Commit e2651dcda75b98e50a19dac274e5ae0eb7a03349
1 parent
bac5886c
Special-product-filter
Showing
9 changed files
with
67 additions
and
5 deletions
Show diff stats
common/components/artboximage/ArtboxImageHelper.php
| @@ -28,7 +28,8 @@ class ArtboxImageHelper extends Object { | @@ -28,7 +28,8 @@ class ArtboxImageHelper extends Object { | ||
| 28 | } | 28 | } |
| 29 | 29 | ||
| 30 | public static function getImage($file, $preset, $imgOptions = []) { | 30 | public static function getImage($file, $preset, $imgOptions = []) { |
| 31 | - return Html::img(self::getImageSrc($file, $preset), $imgOptions); | 31 | + $preset_alias = is_array($preset) ? array_keys($preset)[0] : null; |
| 32 | + return Html::img(self::getImageSrc($file, $preset, $preset_alias), $imgOptions); | ||
| 32 | } | 33 | } |
| 33 | 34 | ||
| 34 | public static function getImageSrc($file, $preset, $preset_alias = null) { | 35 | public static function getImageSrc($file, $preset, $preset_alias = null) { |
common/modules/product/models/Product.php
| @@ -69,6 +69,7 @@ class Product extends \yii\db\ActiveRecord | @@ -69,6 +69,7 @@ class Product extends \yii\db\ActiveRecord | ||
| 69 | public function rules() | 69 | public function rules() |
| 70 | { | 70 | { |
| 71 | return [ | 71 | return [ |
| 72 | + [['categories'], 'required'], | ||
| 72 | [['brand_id'], 'integer'], | 73 | [['brand_id'], 'integer'], |
| 73 | [['name'], 'string', 'max' => 150], | 74 | [['name'], 'string', 'max' => 150], |
| 74 | [['alias'], 'string', 'max' => 250], | 75 | [['alias'], 'string', 'max' => 250], |
common/modules/product/views/manage/_form.php
| @@ -108,6 +108,14 @@ use kartik\select2\Select2; | @@ -108,6 +108,14 @@ use kartik\select2\Select2; | ||
| 108 | 'placeholder' => '∞' | 108 | 'placeholder' => '∞' |
| 109 | ], | 109 | ], |
| 110 | ], | 110 | ], |
| 111 | + [ | ||
| 112 | + 'name' => 'image', | ||
| 113 | + 'type' => MultipleInputColumn::TYPE_FILE, | ||
| 114 | + 'title' => Yii::t('product', 'Image'), | ||
| 115 | + 'options' => [ | ||
| 116 | + 'multiple' => false | ||
| 117 | + ], | ||
| 118 | + ], | ||
| 111 | ], | 119 | ], |
| 112 | ]); | 120 | ]); |
| 113 | ?> | 121 | ?> |
common/modules/rubrication/views/tax-group/_form.php
| @@ -32,7 +32,7 @@ use common\components\artboxtree\ArtboxTreeHelper; | @@ -32,7 +32,7 @@ use common\components\artboxtree\ArtboxTreeHelper; | ||
| 32 | ] | 32 | ] |
| 33 | )->label('Use in the following categories') ?> | 33 | )->label('Use in the following categories') ?> |
| 34 | 34 | ||
| 35 | - <?= $form->field($model, 'hierarchical')->checkbox() ?> | 35 | + <?php /*= $form->field($model, 'hierarchical')->checkbox()*/ ?> |
| 36 | 36 | ||
| 37 | <?= $form->field($model, 'is_filter')->checkbox() ?> | 37 | <?= $form->field($model, 'is_filter')->checkbox() ?> |
| 38 | 38 |
frontend/controllers/CatalogController.php
| @@ -86,6 +86,21 @@ class CatalogController extends \yii\web\Controller | @@ -86,6 +86,21 @@ class CatalogController extends \yii\web\Controller | ||
| 86 | } | 86 | } |
| 87 | } | 87 | } |
| 88 | 88 | ||
| 89 | + if ( !empty($filter['special']) ) { | ||
| 90 | + if (!is_array($filter['special'])) { | ||
| 91 | + $filter['special'] = [$filter['special']]; | ||
| 92 | + } | ||
| 93 | + if (in_array('new', $filter['special'])) { | ||
| 94 | + $params['special']['is_new'] = true; | ||
| 95 | + } | ||
| 96 | + if (in_array('top', $filter['special'])) { | ||
| 97 | + $params['special']['is_top'] = true; | ||
| 98 | + } | ||
| 99 | + if (in_array('promo', $filter['special'])) { | ||
| 100 | + $params['special']['akciya'] = true; | ||
| 101 | + } | ||
| 102 | + } | ||
| 103 | + | ||
| 89 | if ( !empty($filter['options']) ) { | 104 | if ( !empty($filter['options']) ) { |
| 90 | $params['options'] = $filter['options']; | 105 | $params['options'] = $filter['options']; |
| 91 | /*$optionQuery = TaxOption::find(); | 106 | /*$optionQuery = TaxOption::find(); |
frontend/models/ProductFrontendSearch.php
| @@ -161,6 +161,11 @@ class ProductFrontendSearch extends Product { | @@ -161,6 +161,11 @@ class ProductFrontendSearch extends Product { | ||
| 161 | $query->andFilterWhere(['ilike', Product::tableName() .'.name', $keyword]); | 161 | $query->andFilterWhere(['ilike', Product::tableName() .'.name', $keyword]); |
| 162 | } | 162 | } |
| 163 | } | 163 | } |
| 164 | + if (!empty($params['special'])) { | ||
| 165 | + foreach($params['special'] as $key => $value) { | ||
| 166 | + $query->orFilterWhere([Product::tableName() .'.'. $key => $value]); | ||
| 167 | + } | ||
| 168 | + } | ||
| 164 | if (!empty($params['brands'])) { | 169 | if (!empty($params['brands'])) { |
| 165 | $query->andFilterWhere([Product::tableName() .'.brand_id' => $params['brands']]); | 170 | $query->andFilterWhere([Product::tableName() .'.brand_id' => $params['brands']]); |
| 166 | } | 171 | } |
| @@ -174,6 +179,9 @@ class ProductFrontendSearch extends Product { | @@ -174,6 +179,9 @@ class ProductFrontendSearch extends Product { | ||
| 174 | ); | 179 | ); |
| 175 | } | 180 | } |
| 176 | } | 181 | } |
| 182 | + | ||
| 183 | + | ||
| 184 | + | ||
| 177 | if ($setPriceLimits && !empty($params['prices'])) { | 185 | if ($setPriceLimits && !empty($params['prices'])) { |
| 178 | if ($params['prices']['min'] > 0) { | 186 | if ($params['prices']['min'] > 0) { |
| 179 | $query->andWhere(['>=', ProductVariant::tableName() .'.price', $params['prices']['min']]); | 187 | $query->andWhere(['>=', ProductVariant::tableName() .'.price', $params['prices']['min']]); |
frontend/views/catalog/products.php
| @@ -67,9 +67,38 @@ $this->registerJsFile (Yii::getAlias('@web/js/ion.rangeSlider.js')); | @@ -67,9 +67,38 @@ $this->registerJsFile (Yii::getAlias('@web/js/ion.rangeSlider.js')); | ||
| 67 | 67 | ||
| 68 | <div class="loyout"> | 68 | <div class="loyout"> |
| 69 | <div class="leftbar"> | 69 | <div class="leftbar"> |
| 70 | + <?php /* | ||
| 70 | <img src="<?= Yii::$app->request->baseUrl ?>/img/new_coll.png" width="112" height="22"/><br/> | 71 | <img src="<?= Yii::$app->request->baseUrl ?>/img/new_coll.png" width="112" height="22"/><br/> |
| 71 | <img src="<?= Yii::$app->request->baseUrl ?>/img/pro.png" width="42" height="22"/> | 72 | <img src="<?= Yii::$app->request->baseUrl ?>/img/pro.png" width="42" height="22"/> |
| 72 | - | 73 | + */?> |
| 74 | + <div class="filters"> | ||
| 75 | + <ul> | ||
| 76 | + <li> | ||
| 77 | + <?php | ||
| 78 | + $checked = !empty($filter['special']) && in_array('new', $filter['special']); | ||
| 79 | + $option_url = Url::to(['catalog/category', 'category' => $category, 'filter' => ProductHelper::getFilterForOption($filter, 'special', 'new', $checked)]); | ||
| 80 | + ?> | ||
| 81 | + <input type="checkbox" class="special-option" <?= $checked ? ' checked' : ''?> onchange="document.location='<?= $option_url?>'" /> | ||
| 82 | + <a href="<?= $option_url?>"><?= Yii::t('product', 'New products')?></a> | ||
| 83 | + </li> | ||
| 84 | + <li> | ||
| 85 | + <?php | ||
| 86 | + $checked = !empty($filter['special']) && in_array('top', $filter['special']); | ||
| 87 | + $option_url = Url::to(['catalog/category', 'category' => $category, 'filter' => ProductHelper::getFilterForOption($filter, 'special', 'top', $checked)]); | ||
| 88 | + ?> | ||
| 89 | + <input type="checkbox" class="special-option" <?= $checked ? ' checked' : ''?> onchange="document.location='<?= $option_url?>'" /> | ||
| 90 | + <a href="<?= $option_url?>"><?= Yii::t('product', 'Top products')?></a> | ||
| 91 | + </li> | ||
| 92 | + <li> | ||
| 93 | + <?php | ||
| 94 | + $checked = !empty($filter['special']) && in_array('promo', $filter['special']); | ||
| 95 | + $option_url = Url::to(['catalog/category', 'category' => $category, 'filter' => ProductHelper::getFilterForOption($filter, 'special', 'promo', $checked)]); | ||
| 96 | + ?> | ||
| 97 | + <input type="checkbox" class="special-option" <?= $checked ? ' checked' : ''?> onchange="document.location='<?= $option_url?>'" /> | ||
| 98 | + <a href="<?= $option_url?>"><?= Yii::t('product', 'Promo products')?></a> | ||
| 99 | + </li> | ||
| 100 | + </ul> | ||
| 101 | + </div> | ||
| 73 | <form action="#" name="filter_catalog_page_form" class="filter-catalog-form"> | 102 | <form action="#" name="filter_catalog_page_form" class="filter-catalog-form"> |
| 74 | <?php if (!empty($filter)) :?> | 103 | <?php if (!empty($filter)) :?> |
| 75 | <div class="filter_accept_bloc"> | 104 | <div class="filter_accept_bloc"> |
frontend/widgets/Rubrics.php
| @@ -23,7 +23,7 @@ class Rubrics extends Widget { | @@ -23,7 +23,7 @@ class Rubrics extends Widget { | ||
| 23 | if (empty($this->active)) { | 23 | if (empty($this->active)) { |
| 24 | $this->active = Yii::$app->request->get('category'); | 24 | $this->active = Yii::$app->request->get('category'); |
| 25 | } | 25 | } |
| 26 | - if (!is_object($this->active)) { | 26 | + if (!empty($this->active) && !is_object($this->active)) { |
| 27 | $this->active = CategorySearch::findByAlias($this->active); | 27 | $this->active = CategorySearch::findByAlias($this->active); |
| 28 | } | 28 | } |
| 29 | if (!empty($this->active)) { | 29 | if (!empty($this->active)) { |
frontend/widgets/views/rubrics.php
| @@ -6,7 +6,7 @@ use yii\widgets\Menu; | @@ -6,7 +6,7 @@ use yii\widgets\Menu; | ||
| 6 | <?php endif?> | 6 | <?php endif?> |
| 7 | <ul> | 7 | <ul> |
| 8 | <?php foreach($items as $i => $category) :?> | 8 | <?php foreach($items as $i => $category) :?> |
| 9 | - <li class="item_<?= $category->alias?><?= ($active == $category->category_id ? ' active' : '')?>"><?= \yii\helpers\Html::a($category->name, ['catalog/category', 'category' => $category])?></li> | 9 | + <li class="item_<?= $category->alias?><?= (!empty($active) && $active == $category->category_id ? ' active' : '')?>"><?= \yii\helpers\Html::a($category->name, ['catalog/category', 'category' => $category])?></li> |
| 10 | <?php endforeach;?> | 10 | <?php endforeach;?> |
| 11 | </ul> | 11 | </ul> |
| 12 | <?php if(!empty($wrapper)) :?> | 12 | <?php if(!empty($wrapper)) :?> |