Commit 3147aab1ad35ca6fe49072cda0cc38ce72b47154
1 parent
163914fd
Fix search with stock-check
Showing
2 changed files
with
9 additions
and
1 deletions
Show diff stats
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