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,7 +54,7 @@ class SearchController extends \yii\web\Controller | ||
| 54 | } | 54 | } |
| 55 | 55 | ||
| 56 | $productModel = new ProductFrontendSearch(); | 56 | $productModel = new ProductFrontendSearch(); |
| 57 | - $productProvider = $productModel->search(null, $params, false); | 57 | + $productProvider = $productModel->search(null, $params, false, false); |
| 58 | 58 | ||
| 59 | 59 | ||
| 60 | return $this->render( | 60 | return $this->render( |
frontend/models/ProductFrontendSearch.php
| @@ -2,19 +2,15 @@ | @@ -2,19 +2,15 @@ | ||
| 2 | 2 | ||
| 3 | namespace frontend\models; | 3 | namespace frontend\models; |
| 4 | 4 | ||
| 5 | - use common\modules\product\helpers\FilterHelper; | ||
| 6 | use common\modules\product\helpers\ProductHelper; | 5 | use common\modules\product\helpers\ProductHelper; |
| 7 | use common\modules\product\models\Category; | 6 | use common\modules\product\models\Category; |
| 8 | - use Yii; | ||
| 9 | use yii\base\Model; | 7 | use yii\base\Model; |
| 10 | - use yii\data\ActiveDataProvider; | ||
| 11 | use yii\data\ArrayDataProvider; | 8 | use yii\data\ArrayDataProvider; |
| 12 | use yii\db\ActiveQuery; | 9 | use yii\db\ActiveQuery; |
| 13 | 10 | ||
| 14 | use common\modules\product\models\Product; | 11 | use common\modules\product\models\Product; |
| 15 | use common\modules\product\models\ProductVariant; | 12 | use common\modules\product\models\ProductVariant; |
| 16 | use yii\db\Query; | 13 | use yii\db\Query; |
| 17 | - use yii\helpers\ArrayHelper; | ||
| 18 | 14 | ||
| 19 | class ProductFrontendSearch extends Product | 15 | class ProductFrontendSearch extends Product |
| 20 | { | 16 | { |
| @@ -54,12 +50,12 @@ | @@ -54,12 +50,12 @@ | ||
| 54 | * | 50 | * |
| 55 | * @return ArrayDataProvider | 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 | $dataProvider = new ArrayDataProvider( | 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 | ->with( | 59 | ->with( |
| 64 | [ | 60 | [ |
| 65 | 'images', | 61 | 'images', |
| @@ -96,7 +92,7 @@ | @@ -96,7 +92,7 @@ | ||
| 96 | return $dataProvider; | 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 | if (!empty($category)) { | 98 | if (!empty($category)) { |
| @@ -137,19 +133,21 @@ | @@ -137,19 +133,21 @@ | ||
| 137 | /** | 133 | /** |
| 138 | * Removing products that currently in events | 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 | return $query; | 152 | return $query; |
| 155 | } | 153 | } |