Skip to content

armgit / Vvveb

Public Imported from GitHub
0

Powerful and easy to use cms to build websites, blogs or ecommerce stores.

Model entity name renamed to singular for components

givanz9ae07b159cc9
diff --git a/admin/component/posts.php b/admin/component/posts.php
index b9cd2e9..360365e 100755
--- a/admin/component/posts.php
+++ b/admin/component/posts.php
@@ -47,7 +47,7 @@ class Posts extends ComponentBase {
$results = $posts->getAll($this->options);
- foreach ($results['posts'] as $id => &$post) {
+ foreach ($results['post'] as $id => &$post) {
if (isset($post['images'])) {
$post['images'] = json_decode($post['images'], 1);
diff --git a/admin/component/products.php b/admin/component/products.php
index 3d6a295..2acfefd 100755
--- a/admin/component/products.php
+++ b/admin/component/products.php
@@ -49,18 +49,17 @@ class Products extends ComponentBase {
}
function results() {
-
$products = new \Vvveb\Sql\ProductSQL();
$results = $products->getAll($this->options);
- $results['products'] = $results['products'] ?? [];
+ $results['product'] = $results['product'] ?? [];
- if ($results['products']) {
+ if ($results['product']) {
$tax = Tax::getInstance($this->options);
$currency = Currency::getInstance($this->options);
- foreach ($results['products'] as $id => &$product) {
+ foreach ($results['product'] as $id => &$product) {
if (isset($product['images'])) {
$product['images'] = json_decode($product['images'], true);
diff --git a/app/component/checkout.php b/app/component/checkout.php
index 112844a..190c75b 100755
--- a/app/component/checkout.php
+++ b/app/component/checkout.php
@@ -41,7 +41,7 @@ class Checkout extends ComponentBase {
function results() {
$cart = ShoppingCart::getInstance($this->options);
- $results['products'] = $cart->getAll();
+ $results['product'] = $cart->getAll();
$results['total_items'] = $cart->getNoProducts();
$results['total'] = '500$';
diff --git a/app/component/comments.php b/app/component/comments.php
index 43d0582..5396827 100755
--- a/app/component/comments.php
+++ b/app/component/comments.php
@@ -34,7 +34,7 @@ class Comments extends ComponentBase {
protected $route = 'content/post/index';
- protected $model = 'comment';
+ protected $modelName = 'comment';
public static $defaultOptions = [
'post_id' => 'url',
@@ -50,7 +50,7 @@ class Comments extends ComponentBase {
//called when fetching data, when cache expires
function results() {
- $this->modelInstance = model($this->model); //new CommentSQL();
+ $this->modelInstance = model($this->modelName); //new CommentSQL();
$results = $this->modelInstance->getAll($this->options);
$results[$this->type] = $results[$this->type] ?? [];
diff --git a/app/component/compare.php b/app/component/compare.php
index 98ceafb..5721ada 100644
--- a/app/component/compare.php
+++ b/app/component/compare.php
@@ -98,11 +98,11 @@ class Wishlist extends ComponentBase {
$results = $products->getAll($this->options) + $this->options;
- if ($results && isset($results['products'])) {
+ if ($results && isset($results['product'])) {
$tax = Tax::getInstance($this->options);
$currency = Currency::getInstance($this->options);
- foreach ($results['products'] as $id => &$product) {
+ foreach ($results['product'] as $id => &$product) {
$language = [];
if ($product['language_id'] != $this->options['default_language_id']) {
diff --git a/app/component/language.php b/app/component/language.php
index 8f09d52..ce4e899 100755
--- a/app/component/language.php
+++ b/app/component/language.php
@@ -65,10 +65,10 @@ class Language extends ComponentBase {
$publicPath = \Vvveb\publicUrlPath();
$request = Request::getInstance();
- $view = View::getInstance();
+ $view = View::getInstance();
if ($results) {
- $results['current'] = $code = $request->request['language'] ?? Session::getInstance()->get('language') ?? 'en_US';
+ $results['current'] = $code = $request->request['language'] ?? Session::getInstance()->get('language') ?? 'en_US';
$language = $results['language'][$code] ?? [];
if (! $language) {
diff --git a/app/component/menu.php b/app/component/menu.php
index 384ec64..3306eca 100755
--- a/app/component/menu.php
+++ b/app/component/menu.php
@@ -48,14 +48,14 @@ class Menu extends ComponentBase {
}
$menuSql = new menuSQL();
- $results = $menuSql->getMenus($options);
+ $results = $menuSql->get($options);
//count the number of child menus (subcategories) for each category
- if (isset($results['menus'])) {
+ if (isset($results['menu'])) {
$productIds = [];
$postIds = [];
- foreach ($results['menus'] as $taxonomy_item_id => &$category) {
+ foreach ($results['menu'] as $taxonomy_item_id => &$category) {
$parent_id = $category['parent_id'] ?? false;
$type = $category['type'] ?? 'link';
@@ -64,7 +64,7 @@ class Menu extends ComponentBase {
}
if ($parent_id > 0) {
- $parent = &$results['menus'][$parent_id];
+ $parent = &$results['menu'][$parent_id];
if (isset($parent['children'])) {
$parent['children']++;
@@ -78,11 +78,13 @@ class Menu extends ComponentBase {
}
if ($type == 'product') {
- $productIds[$taxonomy_item_id] = $category['item_id'];
+ $productIds[$taxonomy_item_id] = $category['item_id'];
+ $taxonomyProducts[$category['item_id']][] = $taxonomy_item_id;
}
- if ($type == 'post' || $type == 'page') {
- $postIds[$taxonomy_item_id] = $category['item_id'];
+ if (($type == 'post' || $type == 'page') && $category['item_id']) {
+ $postIds[$category['item_id']] = $category['item_id'];
+ $taxonomyPosts[$category['item_id']][] = $taxonomy_item_id;
}
}
@@ -98,14 +100,14 @@ class Menu extends ComponentBase {
$products = $productSql->getAll($productOptions);
if (isset($products['products']) && $products['products']) {
- $productTaxonomy = array_flip($productIds);
-
foreach ($products['products'] as $product) {
- $taxonomy_item_id = $productTaxonomy[$product['product_id']];
- $category = &$results['menus'][$taxonomy_item_id];
- $route = "product/{$category['type']}/index";
- $category['url'] = url($route, ['slug'=> $product['slug']]);
- $category['name'] = $product['name'];
+ foreach ($taxonomyPosts[$product['product_id']] as $taxonomy_item_id) {
+ $taxonomy_item_id = $productTaxonomy[$product['product_id']];
+ $category = &$results['menu'][$taxonomy_item_id];
+ $route = "product/{$category['type']}/index";
+ $category['url'] = url($route, ['slug'=> $product['slug'], 'product_id'=> $product['product_id']]);
+ $category['name'] = $product['name'];
+ }
}
}
}
@@ -121,15 +123,15 @@ class Menu extends ComponentBase {
$postSql = new postSql();
$posts = $postSql->getAll($postOptions);
- if (isset($posts['posts']) && $posts['posts']) {
- $postTaxonomy = array_flip($postIds);
-
- foreach ($posts['posts'] as $post) {
- $taxonomy_item_id = $postTaxonomy[$post['post_id']];
- $category = &$results['menus'][$taxonomy_item_id];
- $route = "content/{$category['type']}/index";
- $category['url'] = url($route, ['slug'=> $post['slug']]);
- $category['name'] = $post['name'];
+ if (isset($posts['post']) && $posts['post']) {
+ foreach ($posts['post'] as $post) {
+ foreach ($taxonomyPosts[$post['post_id']] as $taxonomy_item_id) {
+ $category = &$results['menu'][$taxonomy_item_id];
+ $route = "content/{$category['type']}/index";
+ $url = url($route, ['slug'=> $post['slug'], 'post_id'=> $post['post_id']]);
+ $category['url'] = $url;
+ $category['name'] = $post['name'];
+ }
}
}
}
@@ -144,9 +146,9 @@ class Menu extends ComponentBase {
function request(&$results, $index = 0) {
$currentUrl = getCurrentUrl();
- if (isset($results['menus'])) {
- foreach ($results['menus'] as $taxonomy_item_id => &$category) {
- $category['active'] = ($category['url'] === $currentUrl);
+ if (isset($results['menu'])) {
+ foreach ($results['menu'] as $taxonomy_item_id => &$category) {
+ $category['active'] = isset($category['url']) && ($category['url'] === $currentUrl);
}
}
diff --git a/app/component/order.php b/app/component/order.php
index f0f8663..96de4e8 100755
--- a/app/component/order.php
+++ b/app/component/order.php
@@ -58,8 +58,8 @@ class Order extends ComponentBase {
if ($results && $results['order']) {
$currency = Currency::getInstance();
- if (isset($results['products'])) {
- foreach ($results['products'] as $id => &$product) {
+ if (isset($results['product'])) {
+ foreach ($results['product'] as $id => &$product) {
$product['url'] = htmlentities(\Vvveb\url('product/product/index', $product + $url));
if (isset($product['images'])) {
diff --git a/app/component/posts.php b/app/component/posts.php
index 611e7b9..fbe0350 100755
--- a/app/component/posts.php
+++ b/app/component/posts.php
@@ -41,8 +41,8 @@ class Posts extends ComponentBase {
'site_id' => null,
'start' => null,
'limit' => ['url', 8],
- 'order_by' => 'sort_order',
- 'direction' => ['desc', 'asc'],
+ 'order_by' => 'post_id',
+ 'direction' => 'desc',
'status' => 'publish',
'excerpt_limit' => 200,
'comment_count' => 1,
@@ -50,6 +50,7 @@ class Posts extends ComponentBase {
'taxonomy_item_id' => NULL,
'taxonomy_item_slug' => NULL,
'search' => NULL,
+ 'search_boolean' => true,
'like' => NULL,
'admin_id' => NULL,
//archive
@@ -104,7 +105,7 @@ class Posts extends ComponentBase {
}
if (isset($this->options['order_by']) &&
- ! in_array($this->options['order_by'], ['created_at', 'updated_at'])) {
+ ! in_array($this->options['order_by'], ['post_id', 'admin_id', 'sort_order', 'parent', 'type', 'created_at', 'updated_at'])) {
unset($this->options['order_by']);
}
@@ -113,13 +114,16 @@ class Posts extends ComponentBase {
unset($this->options['direction']);
}
+ if ($this->options['search'] && $this->options['search_boolean']) {
+ $this->options['search'] .= '*';
+ }
+
$results = $posts->getAll($this->options);
//$languages = availableLanguages();
-
$type = $this->options['type'] ?: 'post';
- if ($results && isset($results['posts'])) {
- foreach ($results['posts'] as $id => &$post) {
+ if ($results && isset($results['post'])) {
+ foreach ($results['post'] as $id => &$post) {
if (isset($post['images'])) {
$post['images'] = json_decode($post['images'], 1);
diff --git a/app/component/product/manufacturers.php b/app/component/product/manufacturers.php
index dbe9d7c..7d970a7 100755
--- a/app/component/product/manufacturers.php
+++ b/app/component/product/manufacturers.php
@@ -31,9 +31,9 @@ class Manufacturers extends ComponentBase {
'start' => 0,
//'language_id' => 1,
'count' => ['url', 4],
- 'id_manufacturer' => NULL,
+ 'manufacturer_id' => NULL,
'order' => ['url', 'price asc'],
- 'id_category' => NULL,
+ 'category_id' => NULL,
'limit' => 7,
'page' => 1,
'type' => 'tags',
@@ -46,8 +46,9 @@ class Manufacturers extends ComponentBase {
function results() {
$category = new \Vvveb\Sql\ManufacturerSQL();
$results = $category->getAll($this->options);
-
+
$filter = [];
+
if ($this->options['filter']) {
$filter = $this->options['filter']['manufacturer_id'] ?? [];
}
diff --git a/app/component/product/vendors.php b/app/component/product/vendors.php
index dfc26f2..0ab5c8a 100644
--- a/app/component/product/vendors.php
+++ b/app/component/product/vendors.php
@@ -31,9 +31,9 @@ class Vendors extends ComponentBase {
'start' => 0,
//'language_id' => 1,
'count' => ['url', 4],
- 'id_vendor' => NULL,
+ 'vendor_id' => NULL,
'order' => ['url', 'price asc'],
- 'id_category' => NULL,
+ 'category_id' => NULL,
'limit' => 7,
'page' => 1,
'type' => 'tags',
@@ -48,6 +48,7 @@ class Vendors extends ComponentBase {
$results = $category->getAll($this->options);
$filter = [];
+
if ($this->options['filter']) {
$filter = $this->options['filter']['vendor_id'] ?? [];
}
diff --git a/app/component/products.php b/app/component/products.php
index 0027d64..bbe34c3 100755
--- a/app/component/products.php
+++ b/app/component/products.php
@@ -22,6 +22,7 @@
namespace Vvveb\Component;
+use function Vvveb\getCurrency;
use Vvveb\System\Cart\Currency;
use Vvveb\System\Cart\Tax;
use Vvveb\System\Component\ComponentBase;
@@ -42,18 +43,19 @@ class Products extends ComponentBase {
'parent' => null,
'manufacturer_id' => NULL,
'vendor_id' => NULL,
- 'order_by' => NULL,
- 'direction' => ['url', 'asc', 'desc'],
'taxonomy_item_id' => NULL,
'product_image' => true,
'product_id' => [],
'search' => null,
+ 'search_boolean' => true,
'like' => null,
'slug' => null,
'related' => null,
'variant' => null,
'image_size' => 'medium',
'filter' => null,
+ 'order_by' => NULL,
+ 'direction' => ['url', 'asc', 'desc'],
];
public $options = [];
@@ -108,13 +110,18 @@ class Products extends ComponentBase {
$this->options['vendor_id'] = [$this->options['vendor_id']];
}
- $results = $products->getAll($this->options) + $this->options;
+ if ($this->options['search'] && $this->options['search_boolean']) {
+ $this->options['search'] .= '*';
+ }
+
+ $results = $products->getAll($this->options) + $this->options;
+ $currentCurrency = getCurrency();
- if ($results && isset($results['products'])) {
+ if ($results && isset($results['product'])) {
$tax = Tax::getInstance($this->options);
$currency = Currency::getInstance($this->options);
- foreach ($results['products'] as $id => &$product) {
+ foreach ($results['product'] as $id => &$product) {
$language = [];
if ($product['language_id'] != $this->options['default_language_id']) {
@@ -150,9 +157,14 @@ class Products extends ComponentBase {
$product['price_tax'] = $tax->addTaxes($product['price'], $product['tax_type_id']);
$product['price_tax_formatted'] = $currency->format($product['price_tax']);
$product['price_formatted'] = $currency->format($product['price']);
+ $product['price_currency'] = $currentCurrency;
}
}
+ $results['limit'] = $this->options['limit'];
+ $results['start'] = $this->options['start'];
+ $results['search'] = $this->options['search'];
+
list($results) = Event :: trigger(__CLASS__,__FUNCTION__, $results);
return $results;
diff --git a/app/component/questions.php b/app/component/questions.php
index fd6037e..31cfaf8 100644
--- a/app/component/questions.php
+++ b/app/component/questions.php
@@ -27,7 +27,7 @@ class Questions extends Comments {
protected $route = 'product/product/index';
- protected $model = 'product_question';
+ protected $modelName = 'product_question';
public static $defaultOptions = [
'product_id' => 'url',
diff --git a/app/component/reviews.php b/app/component/reviews.php
index c41db11..553688f 100755
--- a/app/component/reviews.php
+++ b/app/component/reviews.php
@@ -30,7 +30,7 @@ class Reviews extends Comments {
protected $route = 'product/product/index';
- protected $model = 'product_review';
+ protected $modelName = 'product_review';
public static $defaultOptions = [
'product_id' => 'url',
diff --git a/app/component/wishlist.php b/app/component/wishlist.php
index 98ceafb..5721ada 100644
--- a/app/component/wishlist.php
+++ b/app/component/wishlist.php
@@ -98,11 +98,11 @@ class Wishlist extends ComponentBase {
$results = $products->getAll($this->options) + $this->options;
- if ($results && isset($results['products'])) {
+ if ($results && isset($results['product'])) {
$tax = Tax::getInstance($this->options);
$currency = Currency::getInstance($this->options);
- foreach ($results['products'] as $id => &$product) {
+ foreach ($results['product'] as $id => &$product) {
$language = [];
if ($product['language_id'] != $this->options['default_language_id']) {