Skip to content

Commit 9ae07b1

Browse files
committed
Model entity name renamed to singular for components
1 parent 67524f7 commit 9ae07b1

15 files changed

+79
-60
lines changed

admin/component/posts.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ function results() {
4747

4848
$results = $posts->getAll($this->options);
4949

50-
foreach ($results['posts'] as $id => &$post) {
50+
foreach ($results['post'] as $id => &$post) {
5151
if (isset($post['images'])) {
5252
$post['images'] = json_decode($post['images'], 1);
5353

admin/component/products.php

+3-4
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,17 @@ function __construct($class = __CLASS__) {
4949
}
5050

5151
function results() {
52-
5352
$products = new \Vvveb\Sql\ProductSQL();
5453

5554
$results = $products->getAll($this->options);
5655

57-
$results['products'] = $results['products'] ?? [];
56+
$results['product'] = $results['product'] ?? [];
5857

59-
if ($results['products']) {
58+
if ($results['product']) {
6059
$tax = Tax::getInstance($this->options);
6160
$currency = Currency::getInstance($this->options);
6261

63-
foreach ($results['products'] as $id => &$product) {
62+
foreach ($results['product'] as $id => &$product) {
6463
if (isset($product['images'])) {
6564
$product['images'] = json_decode($product['images'], true);
6665

app/component/checkout.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ function cacheKey() {
4141

4242
function results() {
4343
$cart = ShoppingCart::getInstance($this->options);
44-
$results['products'] = $cart->getAll();
44+
$results['product'] = $cart->getAll();
4545
$results['total_items'] = $cart->getNoProducts();
4646
$results['total'] = '500$';
4747

app/component/comments.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class Comments extends ComponentBase {
3434

3535
protected $route = 'content/post/index';
3636

37-
protected $model = 'comment';
37+
protected $modelName = 'comment';
3838

3939
public static $defaultOptions = [
4040
'post_id' => 'url',
@@ -50,7 +50,7 @@ class Comments extends ComponentBase {
5050

5151
//called when fetching data, when cache expires
5252
function results() {
53-
$this->modelInstance = model($this->model); //new CommentSQL();
53+
$this->modelInstance = model($this->modelName); //new CommentSQL();
5454
$results = $this->modelInstance->getAll($this->options);
5555
$results[$this->type] = $results[$this->type] ?? [];
5656

app/component/compare.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,11 @@ function results() {
9898

9999
$results = $products->getAll($this->options) + $this->options;
100100

101-
if ($results && isset($results['products'])) {
101+
if ($results && isset($results['product'])) {
102102
$tax = Tax::getInstance($this->options);
103103
$currency = Currency::getInstance($this->options);
104104

105-
foreach ($results['products'] as $id => &$product) {
105+
foreach ($results['product'] as $id => &$product) {
106106
$language = [];
107107

108108
if ($product['language_id'] != $this->options['default_language_id']) {

app/component/language.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ function results() {
6565

6666
$publicPath = \Vvveb\publicUrlPath();
6767
$request = Request::getInstance();
68-
$view = View::getInstance();
68+
$view = View::getInstance();
6969

7070
if ($results) {
71-
$results['current'] = $code = $request->request['language'] ?? Session::getInstance()->get('language') ?? 'en_US';
71+
$results['current'] = $code = $request->request['language'] ?? Session::getInstance()->get('language') ?? 'en_US';
7272
$language = $results['language'][$code] ?? [];
7373

7474
if (! $language) {

app/component/menu.php

+28-26
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,14 @@ function results() {
4848
}
4949

5050
$menuSql = new menuSQL();
51-
$results = $menuSql->getMenus($options);
51+
$results = $menuSql->get($options);
5252

5353
//count the number of child menus (subcategories) for each category
54-
if (isset($results['menus'])) {
54+
if (isset($results['menu'])) {
5555
$productIds = [];
5656
$postIds = [];
5757

58-
foreach ($results['menus'] as $taxonomy_item_id => &$category) {
58+
foreach ($results['menu'] as $taxonomy_item_id => &$category) {
5959
$parent_id = $category['parent_id'] ?? false;
6060
$type = $category['type'] ?? 'link';
6161

@@ -64,7 +64,7 @@ function results() {
6464
}
6565

6666
if ($parent_id > 0) {
67-
$parent = &$results['menus'][$parent_id];
67+
$parent = &$results['menu'][$parent_id];
6868

6969
if (isset($parent['children'])) {
7070
$parent['children']++;
@@ -78,11 +78,13 @@ function results() {
7878
}
7979

8080
if ($type == 'product') {
81-
$productIds[$taxonomy_item_id] = $category['item_id'];
81+
$productIds[$taxonomy_item_id] = $category['item_id'];
82+
$taxonomyProducts[$category['item_id']][] = $taxonomy_item_id;
8283
}
8384

84-
if ($type == 'post' || $type == 'page') {
85-
$postIds[$taxonomy_item_id] = $category['item_id'];
85+
if (($type == 'post' || $type == 'page') && $category['item_id']) {
86+
$postIds[$category['item_id']] = $category['item_id'];
87+
$taxonomyPosts[$category['item_id']][] = $taxonomy_item_id;
8688
}
8789
}
8890

@@ -98,14 +100,14 @@ function results() {
98100
$products = $productSql->getAll($productOptions);
99101

100102
if (isset($products['products']) && $products['products']) {
101-
$productTaxonomy = array_flip($productIds);
102-
103103
foreach ($products['products'] as $product) {
104-
$taxonomy_item_id = $productTaxonomy[$product['product_id']];
105-
$category = &$results['menus'][$taxonomy_item_id];
106-
$route = "product/{$category['type']}/index";
107-
$category['url'] = url($route, ['slug'=> $product['slug']]);
108-
$category['name'] = $product['name'];
104+
foreach ($taxonomyPosts[$product['product_id']] as $taxonomy_item_id) {
105+
$taxonomy_item_id = $productTaxonomy[$product['product_id']];
106+
$category = &$results['menu'][$taxonomy_item_id];
107+
$route = "product/{$category['type']}/index";
108+
$category['url'] = url($route, ['slug'=> $product['slug'], 'product_id'=> $product['product_id']]);
109+
$category['name'] = $product['name'];
110+
}
109111
}
110112
}
111113
}
@@ -121,15 +123,15 @@ function results() {
121123
$postSql = new postSql();
122124
$posts = $postSql->getAll($postOptions);
123125

124-
if (isset($posts['posts']) && $posts['posts']) {
125-
$postTaxonomy = array_flip($postIds);
126-
127-
foreach ($posts['posts'] as $post) {
128-
$taxonomy_item_id = $postTaxonomy[$post['post_id']];
129-
$category = &$results['menus'][$taxonomy_item_id];
130-
$route = "content/{$category['type']}/index";
131-
$category['url'] = url($route, ['slug'=> $post['slug']]);
132-
$category['name'] = $post['name'];
126+
if (isset($posts['post']) && $posts['post']) {
127+
foreach ($posts['post'] as $post) {
128+
foreach ($taxonomyPosts[$post['post_id']] as $taxonomy_item_id) {
129+
$category = &$results['menu'][$taxonomy_item_id];
130+
$route = "content/{$category['type']}/index";
131+
$url = url($route, ['slug'=> $post['slug'], 'post_id'=> $post['post_id']]);
132+
$category['url'] = $url;
133+
$category['name'] = $post['name'];
134+
}
133135
}
134136
}
135137
}
@@ -144,9 +146,9 @@ function results() {
144146
function request(&$results, $index = 0) {
145147
$currentUrl = getCurrentUrl();
146148

147-
if (isset($results['menus'])) {
148-
foreach ($results['menus'] as $taxonomy_item_id => &$category) {
149-
$category['active'] = ($category['url'] === $currentUrl);
149+
if (isset($results['menu'])) {
150+
foreach ($results['menu'] as $taxonomy_item_id => &$category) {
151+
$category['active'] = isset($category['url']) && ($category['url'] === $currentUrl);
150152
}
151153
}
152154

app/component/order.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ function results() {
5858
if ($results && $results['order']) {
5959
$currency = Currency::getInstance();
6060

61-
if (isset($results['products'])) {
62-
foreach ($results['products'] as $id => &$product) {
61+
if (isset($results['product'])) {
62+
foreach ($results['product'] as $id => &$product) {
6363
$product['url'] = htmlentities(\Vvveb\url('product/product/index', $product + $url));
6464

6565
if (isset($product['images'])) {

app/component/posts.php

+10-6
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,16 @@ class Posts extends ComponentBase {
4141
'site_id' => null,
4242
'start' => null,
4343
'limit' => ['url', 8],
44-
'order_by' => 'sort_order',
45-
'direction' => ['desc', 'asc'],
44+
'order_by' => 'post_id',
45+
'direction' => 'desc',
4646
'status' => 'publish',
4747
'excerpt_limit' => 200,
4848
'comment_count' => 1,
4949
'comment_status' => 1,
5050
'taxonomy_item_id' => NULL,
5151
'taxonomy_item_slug' => NULL,
5252
'search' => NULL,
53+
'search_boolean' => true,
5354
'like' => NULL,
5455
'admin_id' => NULL,
5556
//archive
@@ -104,7 +105,7 @@ function results() {
104105
}
105106

106107
if (isset($this->options['order_by']) &&
107-
! in_array($this->options['order_by'], ['created_at', 'updated_at'])) {
108+
! in_array($this->options['order_by'], ['post_id', 'admin_id', 'sort_order', 'parent', 'type', 'created_at', 'updated_at'])) {
108109
unset($this->options['order_by']);
109110
}
110111

@@ -113,13 +114,16 @@ function results() {
113114
unset($this->options['direction']);
114115
}
115116

117+
if ($this->options['search'] && $this->options['search_boolean']) {
118+
$this->options['search'] .= '*';
119+
}
120+
116121
$results = $posts->getAll($this->options);
117122
//$languages = availableLanguages();
118-
119123
$type = $this->options['type'] ?: 'post';
120124

121-
if ($results && isset($results['posts'])) {
122-
foreach ($results['posts'] as $id => &$post) {
125+
if ($results && isset($results['post'])) {
126+
foreach ($results['post'] as $id => &$post) {
123127
if (isset($post['images'])) {
124128
$post['images'] = json_decode($post['images'], 1);
125129

app/component/product/manufacturers.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ class Manufacturers extends ComponentBase {
3131
'start' => 0,
3232
//'language_id' => 1,
3333
'count' => ['url', 4],
34-
'id_manufacturer' => NULL,
34+
'manufacturer_id' => NULL,
3535
'order' => ['url', 'price asc'],
36-
'id_category' => NULL,
36+
'category_id' => NULL,
3737
'limit' => 7,
3838
'page' => 1,
3939
'type' => 'tags',
@@ -46,8 +46,9 @@ class Manufacturers extends ComponentBase {
4646
function results() {
4747
$category = new \Vvveb\Sql\ManufacturerSQL();
4848
$results = $category->getAll($this->options);
49-
49+
5050
$filter = [];
51+
5152
if ($this->options['filter']) {
5253
$filter = $this->options['filter']['manufacturer_id'] ?? [];
5354
}

app/component/product/vendors.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ class Vendors extends ComponentBase {
3131
'start' => 0,
3232
//'language_id' => 1,
3333
'count' => ['url', 4],
34-
'id_vendor' => NULL,
34+
'vendor_id' => NULL,
3535
'order' => ['url', 'price asc'],
36-
'id_category' => NULL,
36+
'category_id' => NULL,
3737
'limit' => 7,
3838
'page' => 1,
3939
'type' => 'tags',
@@ -48,6 +48,7 @@ function results() {
4848
$results = $category->getAll($this->options);
4949

5050
$filter = [];
51+
5152
if ($this->options['filter']) {
5253
$filter = $this->options['filter']['vendor_id'] ?? [];
5354
}

app/component/products.php

+17-5
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
namespace Vvveb\Component;
2424

25+
use function Vvveb\getCurrency;
2526
use Vvveb\System\Cart\Currency;
2627
use Vvveb\System\Cart\Tax;
2728
use Vvveb\System\Component\ComponentBase;
@@ -42,18 +43,19 @@ class Products extends ComponentBase {
4243
'parent' => null,
4344
'manufacturer_id' => NULL,
4445
'vendor_id' => NULL,
45-
'order_by' => NULL,
46-
'direction' => ['url', 'asc', 'desc'],
4746
'taxonomy_item_id' => NULL,
4847
'product_image' => true,
4948
'product_id' => [],
5049
'search' => null,
50+
'search_boolean' => true,
5151
'like' => null,
5252
'slug' => null,
5353
'related' => null,
5454
'variant' => null,
5555
'image_size' => 'medium',
5656
'filter' => null,
57+
'order_by' => NULL,
58+
'direction' => ['url', 'asc', 'desc'],
5759
];
5860

5961
public $options = [];
@@ -108,13 +110,18 @@ function results() {
108110
$this->options['vendor_id'] = [$this->options['vendor_id']];
109111
}
110112

111-
$results = $products->getAll($this->options) + $this->options;
113+
if ($this->options['search'] && $this->options['search_boolean']) {
114+
$this->options['search'] .= '*';
115+
}
116+
117+
$results = $products->getAll($this->options) + $this->options;
118+
$currentCurrency = getCurrency();
112119

113-
if ($results && isset($results['products'])) {
120+
if ($results && isset($results['product'])) {
114121
$tax = Tax::getInstance($this->options);
115122
$currency = Currency::getInstance($this->options);
116123

117-
foreach ($results['products'] as $id => &$product) {
124+
foreach ($results['product'] as $id => &$product) {
118125
$language = [];
119126

120127
if ($product['language_id'] != $this->options['default_language_id']) {
@@ -150,9 +157,14 @@ function results() {
150157
$product['price_tax'] = $tax->addTaxes($product['price'], $product['tax_type_id']);
151158
$product['price_tax_formatted'] = $currency->format($product['price_tax']);
152159
$product['price_formatted'] = $currency->format($product['price']);
160+
$product['price_currency'] = $currentCurrency;
153161
}
154162
}
155163

164+
$results['limit'] = $this->options['limit'];
165+
$results['start'] = $this->options['start'];
166+
$results['search'] = $this->options['search'];
167+
156168
list($results) = Event :: trigger(__CLASS__,__FUNCTION__, $results);
157169

158170
return $results;

app/component/questions.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class Questions extends Comments {
2727

2828
protected $route = 'product/product/index';
2929

30-
protected $model = 'product_question';
30+
protected $modelName = 'product_question';
3131

3232
public static $defaultOptions = [
3333
'product_id' => 'url',

app/component/reviews.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class Reviews extends Comments {
3030

3131
protected $route = 'product/product/index';
3232

33-
protected $model = 'product_review';
33+
protected $modelName = 'product_review';
3434

3535
public static $defaultOptions = [
3636
'product_id' => 'url',

app/component/wishlist.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,11 @@ function results() {
9898

9999
$results = $products->getAll($this->options) + $this->options;
100100

101-
if ($results && isset($results['products'])) {
101+
if ($results && isset($results['product'])) {
102102
$tax = Tax::getInstance($this->options);
103103
$currency = Currency::getInstance($this->options);
104104

105-
foreach ($results['products'] as $id => &$product) {
105+
foreach ($results['product'] as $id => &$product) {
106106
$language = [];
107107

108108
if ($product['language_id'] != $this->options['default_language_id']) {

0 commit comments

Comments
 (0)