Commit 04eb9f674a0e4f7f58de2f62b68c52c065b6137a
1 parent
776dd7a1
-Search with sale products
Showing
2 changed files
with
18 additions
and
20 deletions
Show diff stats
frontend/controllers/SearchController.php
| ... | ... | @@ -54,7 +54,7 @@ class SearchController extends \yii\web\Controller |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | $productModel = new ProductFrontendSearch(); |
| 57 | - $productProvider = $productModel->search(null, $params, false); | |
| 57 | + $productProvider = $productModel->search(null, $params, false, false); | |
| 58 | 58 | |
| 59 | 59 | |
| 60 | 60 | return $this->render( | ... | ... |
frontend/models/ProductFrontendSearch.php
| ... | ... | @@ -2,19 +2,15 @@ |
| 2 | 2 | |
| 3 | 3 | namespace frontend\models; |
| 4 | 4 | |
| 5 | - use common\modules\product\helpers\FilterHelper; | |
| 6 | 5 | use common\modules\product\helpers\ProductHelper; |
| 7 | 6 | use common\modules\product\models\Category; |
| 8 | - use Yii; | |
| 9 | 7 | use yii\base\Model; |
| 10 | - use yii\data\ActiveDataProvider; | |
| 11 | 8 | use yii\data\ArrayDataProvider; |
| 12 | 9 | use yii\db\ActiveQuery; |
| 13 | 10 | |
| 14 | 11 | use common\modules\product\models\Product; |
| 15 | 12 | use common\modules\product\models\ProductVariant; |
| 16 | 13 | use yii\db\Query; |
| 17 | - use yii\helpers\ArrayHelper; | |
| 18 | 14 | |
| 19 | 15 | class ProductFrontendSearch extends Product |
| 20 | 16 | { |
| ... | ... | @@ -54,12 +50,12 @@ |
| 54 | 50 | * |
| 55 | 51 | * @return ArrayDataProvider |
| 56 | 52 | */ |
| 57 | - public function search($category = null, $params = [], $in_stock = true) | |
| 53 | + public function search($category = null, $params = [], $in_stock = true, $without_sale = true) | |
| 58 | 54 | { |
| 59 | 55 | |
| 60 | 56 | $dataProvider = new ArrayDataProvider( |
| 61 | 57 | [ |
| 62 | - 'allModels' => $this->getSearchQuery($category, $params, $in_stock) | |
| 58 | + 'allModels' => $this->getSearchQuery($category, $params, $in_stock, $without_sale) | |
| 63 | 59 | ->with( |
| 64 | 60 | [ |
| 65 | 61 | 'images', |
| ... | ... | @@ -96,7 +92,7 @@ |
| 96 | 92 | return $dataProvider; |
| 97 | 93 | } |
| 98 | 94 | |
| 99 | - public function getSearchQuery($category = null, $params = [], $in_stock = true) | |
| 95 | + public function getSearchQuery($category = null, $params = [], $in_stock = true, $without_sale = true) | |
| 100 | 96 | { |
| 101 | 97 | |
| 102 | 98 | if (!empty($category)) { |
| ... | ... | @@ -137,19 +133,21 @@ |
| 137 | 133 | /** |
| 138 | 134 | * Removing products that currently in events |
| 139 | 135 | */ |
| 140 | - $query->andWhere( | |
| 141 | - [ | |
| 142 | - 'not', | |
| 136 | + if ($without_sale) { | |
| 137 | + $query->andWhere( | |
| 143 | 138 | [ |
| 144 | - 'product.product_id' => ( new Query() )->select('events_to_products.product_id') | |
| 145 | - ->from('events_to_products') | |
| 146 | - ->innerJoin( | |
| 147 | - 'event', | |
| 148 | - 'event.event_id=events_to_products.event_id' | |
| 149 | - )->where(['event.sale' => true]), | |
| 150 | - ], | |
| 151 | - ] | |
| 152 | - ); | |
| 139 | + 'not', | |
| 140 | + [ | |
| 141 | + 'product.product_id' => ( new Query() )->select('events_to_products.product_id') | |
| 142 | + ->from('events_to_products') | |
| 143 | + ->innerJoin( | |
| 144 | + 'event', | |
| 145 | + 'event.event_id=events_to_products.event_id' | |
| 146 | + )->where(['event.sale' => true]), | |
| 147 | + ], | |
| 148 | + ] | |
| 149 | + ); | |
| 150 | + } | |
| 153 | 151 | |
| 154 | 152 | return $query; |
| 155 | 153 | } | ... | ... |