Commit e2651dcda75b98e50a19dac274e5ae0eb7a03349

Authored by Karnovsky A
1 parent bac5886c

Special-product-filter

common/components/artboximage/ArtboxImageHelper.php
... ... @@ -28,7 +28,8 @@ class ArtboxImageHelper extends Object {
28 28 }
29 29  
30 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 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 69 public function rules()
70 70 {
71 71 return [
  72 + [['categories'], 'required'],
72 73 [['brand_id'], 'integer'],
73 74 [['name'], 'string', 'max' => 150],
74 75 [['alias'], 'string', 'max' => 250],
... ...
common/modules/product/views/manage/_form.php
... ... @@ -108,6 +108,14 @@ use kartik\select2\Select2;
108 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 32 ]
33 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 37 <?= $form->field($model, 'is_filter')->checkbox() ?>
38 38  
... ...
frontend/controllers/CatalogController.php
... ... @@ -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 104 if ( !empty($filter['options']) ) {
90 105 $params['options'] = $filter['options'];
91 106 /*$optionQuery = TaxOption::find();
... ...
frontend/models/ProductFrontendSearch.php
... ... @@ -161,6 +161,11 @@ class ProductFrontendSearch extends Product {
161 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 169 if (!empty($params['brands'])) {
165 170 $query->andFilterWhere([Product::tableName() .'.brand_id' => $params['brands']]);
166 171 }
... ... @@ -174,6 +179,9 @@ class ProductFrontendSearch extends Product {
174 179 );
175 180 }
176 181 }
  182 +
  183 +
  184 +
177 185 if ($setPriceLimits && !empty($params['prices'])) {
178 186 if ($params['prices']['min'] > 0) {
179 187 $query->andWhere(['>=', ProductVariant::tableName() .'.price', $params['prices']['min']]);
... ...
frontend/views/catalog/products.php
... ... @@ -67,9 +67,38 @@ $this-&gt;registerJsFile (Yii::getAlias(&#39;@web/js/ion.rangeSlider.js&#39;));
67 67  
68 68 <div class="loyout">
69 69 <div class="leftbar">
  70 + <?php /*
70 71 <img src="<?= Yii::$app->request->baseUrl ?>/img/new_coll.png" width="112" height="22"/><br/>
71 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 102 <form action="#" name="filter_catalog_page_form" class="filter-catalog-form">
74 103 <?php if (!empty($filter)) :?>
75 104 <div class="filter_accept_bloc">
... ...
frontend/widgets/Rubrics.php
... ... @@ -23,7 +23,7 @@ class Rubrics extends Widget {
23 23 if (empty($this->active)) {
24 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 27 $this->active = CategorySearch::findByAlias($this->active);
28 28 }
29 29 if (!empty($this->active)) {
... ...
frontend/widgets/views/rubrics.php
... ... @@ -6,7 +6,7 @@ use yii\widgets\Menu;
6 6 <?php endif?>
7 7 <ul>
8 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 10 <?php endforeach;?>
11 11 </ul>
12 12 <?php if(!empty($wrapper)) :?>
... ...