Commit c3d12ab0d53e3c5c73e4f38338b97021c60aca60
1 parent
d7b7bdaf
add variantSku
Showing
1 changed file
with
21 additions
and
11 deletions
Show diff stats
models/ProductFrontendSearch.php
... | ... | @@ -4,7 +4,6 @@ |
4 | 4 | |
5 | 5 | use artweb\artbox\ecommerce\helpers\FilterHelper; |
6 | 6 | use artweb\artbox\ecommerce\models\Category; |
7 | - use artweb\artbox\language\models\Language; | |
8 | 7 | use yii\base\Model; |
9 | 8 | use yii\data\ActiveDataProvider; |
10 | 9 | use yii\data\ArrayDataProvider; |
... | ... | @@ -118,16 +117,22 @@ |
118 | 117 | return $dataProvider; |
119 | 118 | } |
120 | 119 | |
121 | - /** | |
122 | - * @param Category $category | |
123 | - * @param array $params | |
124 | - * @param bool $in_stock | |
125 | - * @return mixed | |
126 | - */ | |
127 | - public function getSearchQuery($category, $params = [], $in_stock = true) | |
120 | + public function getSearchQuery($category = null, $params = [], $in_stock = true) | |
128 | 121 | { |
129 | 122 | |
130 | - $query = $category->getProducts(); | |
123 | + if (!empty( $category )) { | |
124 | + /** @var ActiveQuery $query */ | |
125 | + /**@var Category $category * */ | |
126 | + $query = $category->getProducts(); | |
127 | + | |
128 | + } else { | |
129 | + $query = Product::find() | |
130 | + ->joinWith( | |
131 | + [ | |
132 | + 'category.lang', | |
133 | + ] | |
134 | + ); | |
135 | + } | |
131 | 136 | |
132 | 137 | $query->select([ 'product.*' ]); |
133 | 138 | $query->joinWith( |
... | ... | @@ -171,7 +176,6 @@ |
171 | 176 | ] |
172 | 177 | ); |
173 | 178 | |
174 | - | |
175 | 179 | FilterHelper::setQueryParams($query, $params); |
176 | 180 | return $query; |
177 | 181 | } |
... | ... | @@ -184,7 +188,13 @@ |
184 | 188 | |
185 | 189 | public function priceLimits($category = null, $params = []) |
186 | 190 | { |
187 | - $query = $category->getProducts(); | |
191 | + if (!empty( $category )) { | |
192 | + /** @var ActiveQuery $query */ | |
193 | + // $query = $category->getRelations('product_categories'); | |
194 | + $query = $category->getProducts(); | |
195 | + } else { | |
196 | + $query = Product::find(); | |
197 | + } | |
188 | 198 | |
189 | 199 | $query->select(['MAX('.ProductVariant::tableName() . '.price) as max', 'MIN('.ProductVariant::tableName() . '.price) as min']); |
190 | 200 | $query->joinWith('variant'); | ... | ... |