Commit e8d4c8fa4b8008bfce810a048eb920961566f407

Authored by Administrator
1 parent af4b9988

add variantSku

Showing 1 changed file with 42 additions and 29 deletions   Show diff stats
helpers/FilterHelper.php
@@ -190,7 +190,10 @@ @@ -190,7 +190,10 @@
190 190
191 } 191 }
192 } 192 }
193 - self::filterOptions($params, $productVariantOptions, $query); 193 + if(!empty($params)){
  194 + self::filterOptions($params, $productVariantOptions, $query);
  195 + }
  196 +
194 } 197 }
195 198
196 199
@@ -210,9 +213,10 @@ @@ -210,9 +213,10 @@
210 $variant_query = ( new Query() )->distinct() 213 $variant_query = ( new Query() )->distinct()
211 ->select('product_variant.product_id as products') 214 ->select('product_variant.product_id as products')
212 ->from('product_variant'); 215 ->from('product_variant');
213 - 216 + $variantSearch = false;
214 foreach ($params as $key=>$param){ 217 foreach ($params as $key=>$param){
215 if(in_array($key, $productVariantOptions)){ 218 if(in_array($key, $productVariantOptions)){
  219 + $variantSearch = true;
216 unset($params[$key]); 220 unset($params[$key]);
217 $product_variant_id = ( new Query() )->distinct()->select('product_variant_option.product_variant_id as id') 221 $product_variant_id = ( new Query() )->distinct()->select('product_variant_option.product_variant_id as id')
218 ->from('product_variant_option') 222 ->from('product_variant_option')
@@ -239,38 +243,47 @@ @@ -239,38 +243,47 @@
239 243
240 } 244 }
241 245
  246 + if($variantSearch){
  247 + if($in_stock) {
  248 + $variant_query->andWhere(['!=', 'product_variant.stock', 0]);
  249 + }
  250 +
  251 +
  252 + $query->andWhere([ 'product.id' => $variant_query ]);
242 253
243 - if($in_stock) {  
244 - $variant_query->andWhere(['!=', 'product_variant.stock', 0]);  
245 } 254 }
246 - $product_query = ( new Query() )->distinct()  
247 - ->select('product_option.product_id as products')  
248 - ->from('product_option')  
249 - ->innerJoin(  
250 - 'tax_option',  
251 - 'tax_option.id = product_option.option_id'  
252 - )  
253 - ->innerJoin(  
254 - 'tax_option_lang',  
255 - 'tax_option_lang.tax_option_id = tax_option.id'  
256 - )  
257 - ->innerJoin(  
258 - 'tax_group',  
259 - 'tax_group.id = tax_option.tax_group_id'  
260 - )  
261 - ->innerJoin(  
262 - 'tax_group_lang',  
263 - 'tax_group_lang.tax_group_id = tax_group.id'  
264 - );  
265 - foreach ($params as $key=>$param){  
266 - $product_query  
267 - ->where([ 'tax_group_lang.alias' => $key ])  
268 - ->andWhere([ 'tax_option_lang.alias' => $param ]);  
269 255
  256 +
  257 +
  258 + if(!empty($params)) {
  259 + $product_query = ( new Query() )->distinct()
  260 + ->select('product_option.product_id as products')
  261 + ->from('product_option')
  262 + ->innerJoin(
  263 + 'tax_option',
  264 + 'tax_option.id = product_option.option_id'
  265 + )
  266 + ->innerJoin(
  267 + 'tax_option_lang',
  268 + 'tax_option_lang.tax_option_id = tax_option.id'
  269 + )
  270 + ->innerJoin(
  271 + 'tax_group',
  272 + 'tax_group.id = tax_option.tax_group_id'
  273 + )
  274 + ->innerJoin(
  275 + 'tax_group_lang',
  276 + 'tax_group_lang.tax_group_id = tax_group.id'
  277 + );
  278 + foreach ($params as $key=>$param){
  279 + $product_query
  280 + ->where([ 'tax_group_lang.alias' => $key ])
  281 + ->andWhere([ 'tax_option_lang.alias' => $param ]);
  282 +
  283 + }
  284 + $query->andWhere([ 'product.id' => $product_query ]);
270 } 285 }
271 286
272 - $query->andWhere([ 'product.id' => $product_query ]);  
273 - $query->andWhere([ 'product.id' => $variant_query ]);  
274 287
275 } 288 }
276 289