Commit 3147aab1ad35ca6fe49072cda0cc38ce72b47154

Authored by Karnovsky A
1 parent 163914fd

Fix search with stock-check

frontend/controllers/CatalogController.php
... ... @@ -61,10 +61,12 @@ class CatalogController extends \yii\web\Controller
61 61  
62 62 $categoriesQuery = Category::find()
63 63 ->innerJoin(ProductCategory::tableName(), ProductCategory::tableName() .'.category_id = '. Category::tableName() .'.category_id')
64   - ->innerJoin(Product::tableName(), Product::tableName() .'.product_id = '. ProductCategory::tableName() .'.product_id');
  64 + ->innerJoin(Product::tableName(), Product::tableName() .'.product_id = '. ProductCategory::tableName() .'.product_id')
  65 + ->innerJoin(ProductVariant::tableName(), ProductVariant::tableName() .'.product_id = '. ProductCategory::tableName() .'.product_id');
65 66 foreach ($params['keywords'] as $keyword) {
66 67 $categoriesQuery->andWhere(['ilike', 'product.name', $keyword]);
67 68 }
  69 + $categoriesQuery->andWhere(['!=', ProductVariant::tableName() .'.stock', 0]);
68 70 $categories = $categoriesQuery->all();
69 71  
70 72 return $this->render(
... ... @@ -157,6 +159,10 @@ class CatalogController extends \yii\web\Controller
157 159 /** @var Product $product */
158 160 $product = Yii::$app->request->get('product');
159 161  
  162 + if(!$product->enabledVariant) {
  163 + throw new HttpException(404, 'Товар не найден');
  164 + }
  165 +
160 166 $groups = [];
161 167 foreach($product->category->getTaxGroups()->all() as $_group) {
162 168 $groups[$_group->tax_group_id] = $_group;
... ...
frontend/models/ProductFrontendSearch.php
... ... @@ -87,6 +87,8 @@ class ProductFrontendSearch extends Product {
87 87  
88 88 $this->_setParams($query, $params);
89 89  
  90 + $query->andWhere(['!=', ProductVariant::tableName() .'.stock', 0]);
  91 +
90 92 return $dataProvider;
91 93 }
92 94  
... ...