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