Commit eaaf879fa6458238690ce82de64fb13d68e9c8db

Authored by Karnovsky A
1 parent d74f0496

Similar products - set category filter

Showing 1 changed file with 7 additions and 1 deletions   Show diff stats
common/modules/product/helpers/ProductHelper.php
... ... @@ -108,10 +108,16 @@ class ProductHelper extends Object {
108 108 if (!$product->properties) {
109 109 return [];
110 110 }
  111 + $product_categories = [];
  112 + foreach ($product->categories as $category) {
  113 + $product_categories[] = $category->category_id;
  114 + }
111 115 $query = Product::find()
112 116 ->select('product.product_id')
113 117 ->innerJoinWith('variant')
114   - ->where(['!=', 'product_variant.stock', 0]);
  118 + ->joinWith('category')
  119 + ->where(['!=', 'product_variant.stock', 0])
  120 + ->andWhere(['product_category.category_id' => $product_categories]);
115 121 // $query->andWhere(['>=', 'product_variant.price', $product->enabledVariant->price * 0.7]);
116 122 // $query->andWhere(['<=', 'product_variant.price', $product->enabledVariant->price * 1.3]);
117 123 foreach($product->properties as $group) {
... ...