Commit a95ce595e20ad9a14287192dbc59cc92bfe87303

Authored by Administrator
1 parent 74a103b3

big commti

.htaccess
... ... @@ -144,12 +144,7 @@ AddDefaultCharset utf-8
144 144 RewriteRule (.*) http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
145 145  
146 146 RewriteCond %{THE_REQUEST} \s/+(.+?)/+[?\s]
147   - RewriteRule /$ /%1 [R,L]
148   -
149   -
150   -
151   - RewriteCond %{THE_REQUEST} \s/+(.+?)/+[?\s]
152   - RewriteRule /$ /%1 [R,L]
  147 + RewriteRule /$ /%1 [R=301,L]
153 148  
154 149  
155 150 RewriteCond %{HTTP_HOST} ^([^www].*)$
... ...
common/models/FilterCache.php 0 → 100644
  1 +<?php
  2 +
  3 +namespace common\models;
  4 +
  5 +use Yii;
  6 +use yii\helpers\ArrayHelper;
  7 +
  8 +/**
  9 + * This is the model class for table "filter_cache".
  10 + *
  11 + * @property integer $id
  12 + * @property integer $options_key
  13 + * @property integer $category_id
  14 + * @property integer $depth
  15 + * @property integer $count
  16 + */
  17 +class FilterCache extends \yii\db\ActiveRecord
  18 +{
  19 + /**
  20 + * @inheritdoc
  21 + */
  22 + public static function tableName()
  23 + {
  24 + return 'filter_cache';
  25 + }
  26 +
  27 + /**
  28 + * @inheritdoc
  29 + */
  30 + public function rules()
  31 + {
  32 + return [
  33 + [[ 'category_id', 'depth', 'count'], 'integer'],
  34 + [['options_key'], 'string']
  35 + ];
  36 + }
  37 +
  38 + /**
  39 + * @inheritdoc
  40 + */
  41 + public function attributeLabels()
  42 + {
  43 + return [
  44 + 'id' => 'ID',
  45 + 'options_key' => 'Options Key',
  46 + 'category_id' => 'Category ID',
  47 + 'depth' => 'Depth',
  48 + 'count' => 'Count',
  49 + ];
  50 + }
  51 +
  52 + /**
  53 + * @param array $optionsIdArray
  54 + * @return string
  55 + */
  56 + static function createCacheKey($optionsIdArray){
  57 + if(!empty($optionsIdArray)){
  58 + sort($optionsIdArray);
  59 + $string = implode('',$optionsIdArray);
  60 + $key = md5($string);
  61 + return $key;
  62 + } else {
  63 + return 0;
  64 + }
  65 + }
  66 +
  67 +
  68 + /**
  69 + * @param $groups
  70 + * @param $params
  71 + * @return array
  72 + */
  73 +
  74 + static function convertAliasToId($groups,$params){
  75 + $optionsAlias = ArrayHelper::index($groups, 'option_alias');
  76 + $convertedParams = [];
  77 + foreach($params as $key => $options){
  78 + foreach($options as $option){
  79 + if(isset($optionsAlias[$option]) && !in_array($optionsAlias[$option]['tax_option_id'],$convertedParams)){
  80 + $convertedParams[] = $optionsAlias[$option]['tax_option_id'];
  81 + }
  82 + }
  83 + }
  84 + return $convertedParams;
  85 +
  86 + }
  87 +
  88 +}
... ...
common/modules/product/helpers/FilterHelper.php
... ... @@ -3,10 +3,16 @@
3 3 namespace common\modules\product\helpers;
4 4  
5 5  
  6 +use common\modules\product\models\Brand;
  7 +use common\modules\product\models\Category;
  8 +use common\modules\product\models\Product;
  9 +use common\modules\product\models\ProductVariant;
6 10 use common\modules\rubrication\models\TaxGroup;
7 11 use yii\base\Object;
8 12 use Yii;
  13 +use yii\db\Query;
9 14 use yii\db\QueryInterface;
  15 +use yii\db\ActiveQuery;
10 16 use yii\helpers\ArrayHelper;
11 17  
12 18 class FilterHelper extends Object {
... ... @@ -24,7 +30,7 @@ class FilterHelper extends Object {
24 30  
25 31 }
26 32  
27   - /*
  33 + /**
28 34 * Return custom filter-option link
29 35 * @var array $filter
30 36 * @var array $options
... ... @@ -84,4 +90,157 @@ class FilterHelper extends Object {
84 90  
85 91  
86 92  
  93 + /**
  94 + * @param ActiveQuery $query
  95 + * @param array $params
  96 + */
  97 + public static function setNewQueryParams($query, $params)
  98 + {
  99 + $last_query = null;
  100 + foreach ($params as $key => $param) {
  101 + switch ($key) {
  102 + case 'special':
  103 + self::filterSpecial($param, $query);
  104 + break;
  105 + case 'brands':
  106 + self::filterBrands($param, $query);
  107 + break;
  108 + case 'keywords':
  109 + self::filterKeywords($param, $query);
  110 + break;
  111 + case 'prices':
  112 + self::filterPrices($param, $query);
  113 + break;
  114 + default:
  115 + $last_query = self::filterOptions($param, $last_query);
  116 + break;
  117 + }
  118 + }
  119 + if(!empty($last_query)) {
  120 + $query->andWhere(['product.product_id' => $last_query]);
  121 + }
  122 + }
  123 +
  124 + private static function filterOptions(array $params, Query $last_query = null)
  125 + {
  126 + $variant_query = ( new Query() )->distinct()
  127 + ->select('product_variant.product_id as products')
  128 + ->from('product_variant_option')
  129 + ->innerJoin(
  130 + 'product_variant',
  131 + 'product_variant_option.product_variant_id = product_variant.product_variant_id'
  132 + )
  133 + ->innerJoin('tax_option', 'tax_option.tax_option_id = product_variant_option.option_id')
  134 + ->where([ 'tax_option.alias' => $params ]);
  135 + $product_query = ( new Query() )->distinct()
  136 + ->select('product_option.product_id as products')
  137 + ->from('product_option')
  138 + ->innerJoin('tax_option', 'product_option.option_id = tax_option.tax_option_id')
  139 + ->where(
  140 + [ 'tax_option.alias' => $params ]
  141 + )->union($variant_query);
  142 + $query = (new Query())->select('products')->from(['result_table' => $product_query]);
  143 + if (!empty( $last_query )) {
  144 + $query->andWhere([ 'product.product_id' => $last_query ]);
  145 + }
  146 + return $query;
  147 + }
  148 +
  149 + private static function filterSpecial(array $params, ActiveQuery $query)
  150 + {
  151 + $conditions = [];
  152 + /**
  153 + * @var string $key
  154 + */
  155 + foreach ($params as $key => $param) {
  156 + $conditions[] = [
  157 + '=',
  158 + Product::tableName() . '.' . $key,
  159 + $param,
  160 + ];
  161 + }
  162 + /* If 2 or more special conditions get all that satisfy at least one of them. */
  163 + if (count($conditions) > 1) {
  164 + array_unshift($conditions, 'or');
  165 + } else {
  166 + $conditions = $conditions[ 0 ];
  167 + }
  168 + $query->andFilterWhere($conditions);
  169 + }
  170 +
  171 + private static function filterBrands(array $param, ActiveQuery $query)
  172 + {
  173 + $query->andFilterWhere([ Product::tableName() . '.brand_id' => $param ]);
  174 + }
  175 +
  176 + private static function filterKeywords(array $params, ActiveQuery $query)
  177 + {
  178 + $conditions = [];
  179 + if (!empty( $params )) {
  180 + if (!is_array($params)) {
  181 + $params = [ $params ];
  182 + }
  183 + /**
  184 + * @var string $param Inputed keyword
  185 + */
  186 + foreach ($params as $param) {
  187 + $conditions[] = [
  188 + 'or',
  189 + [
  190 + 'ilike',
  191 + Product::tableName() . '.name',
  192 + $param,
  193 + ],
  194 + [
  195 + 'ilike',
  196 + Brand::tableName() . '.name',
  197 + $param,
  198 + ],
  199 + [
  200 + 'ilike',
  201 + Category::tableName() . '.name',
  202 + $param,
  203 + ],
  204 + [
  205 + 'ilike',
  206 + ProductVariant::tableName() . '.sku',
  207 + $param,
  208 + ],
  209 + ];
  210 + }
  211 + }
  212 + if (count($conditions) > 1) {
  213 + array_unshift($conditions, 'or');
  214 + } else {
  215 + $conditions = $conditions[ 0 ];
  216 + }
  217 + $query->andFilterWhere($conditions);
  218 + }
  219 +
  220 + private static function filterPrices(array $params, ActiveQuery $query)
  221 + {
  222 + $conditions = [];
  223 + if (!empty( $params[ 'min' ] ) && $params[ 'min' ] > 0) {
  224 + $conditions[] = [
  225 + '>=',
  226 + ProductVariant::tableName() . '.price',
  227 + $params[ 'min' ],
  228 + ];
  229 + }
  230 + if (!empty( $params[ 'max' ] ) && $params[ 'max' ] > 0) {
  231 + $conditions[] = [
  232 + '<=',
  233 + ProductVariant::tableName() . '.price',
  234 + $params[ 'max' ],
  235 + ];
  236 + }
  237 + if (count($conditions) > 1) {
  238 + array_unshift($conditions, 'and');
  239 + } else {
  240 + $conditions = $conditions[ 0 ];
  241 + }
  242 + $query->andFilterWhere($conditions);
  243 + }
  244 +
  245 +
87 246 }
88 247 \ No newline at end of file
... ...
common/modules/product/helpers/ProductHelper.php
... ... @@ -31,7 +31,7 @@
31 31 return Brand::find(); // ->with('brandName')
32 32 }
33 33  
34   - /*
  34 + /**
35 35 * Return custom filter-option link
36 36 * @var array $filter
37 37 * @var array $options
... ... @@ -269,7 +269,49 @@
269 269 }
270 270  
271 271 }
272   -
  272 +
  273 + /**
  274 + * @param ActiveQuery $query
  275 + * @param $params
  276 + * @param bool $setPriceLimits
  277 + */
  278 + public static function setCacheQueryParams(&$query, $params)
  279 + {
  280 +
  281 +
  282 + foreach($params as $key => $param) {
  283 +
  284 +
  285 + $query->andWhere(
  286 + Product::tableName() . '.product_id IN (
  287 + SELECT DISTINCT products
  288 + FROM (
  289 + SELECT product_id AS products FROM product WHERE product_id IN(
  290 + SELECT product_id FROM product_option
  291 + INNER JOIN tax_option ON tax_option.tax_option_id = product_option.option_id
  292 + INNER JOIN tax_group ON tax_group.tax_group_id = tax_option.tax_group_id
  293 + WHERE tax_group.alias = \''. $key .'\' AND tax_option.alias IN (\'' . implode('\',\'', $param) . '\'))
  294 + OR product_id IN (
  295 + (SELECT product_id AS products
  296 + FROM product_variant_option
  297 + INNER JOIN product_variant ON product_variant_option.product_variant_id = product_variant.product_variant_id
  298 + INNER JOIN tax_option ON tax_option.tax_option_id = product_variant_option.option_id
  299 + INNER JOIN tax_group ON tax_group.tax_group_id = tax_option.tax_group_id
  300 + WHERE tax_group.alias = \''. $key .'\' AND tax_option.alias IN (\'' . implode('\',\'', $param) . '\'))
  301 + )
  302 + ) AS table_name
  303 + )'
  304 + );
  305 + }
  306 +
  307 +
  308 + }
  309 +
  310 +
  311 +
  312 +
  313 +
  314 +
273 315 public static function productCountQuery($category = NULL, $params, $excludeKeys = [ ])
274 316 {
275 317 $p = [ ];
... ...
common/modules/product/models/Category.php
... ... @@ -5,7 +5,8 @@ namespace common\modules\product\models;
5 5  
6 6 use common\components\artboxtree\ArtboxTreeBehavior;
7 7 use common\components\artboxtree\ArtboxTreeHelper;
8   -
  8 +use common\modules\rubrication\models\TaxOption;
  9 +use yii\db\ActiveQuery;
9 10 use common\modules\rubrication\models\TaxGroup;
10 11 use Yii;
11 12  
... ... @@ -35,6 +36,7 @@ use common\behaviors\Slug;
35 36 * @property ProductUnit $productUnit
36 37 * @property CategoryName[] $categoryNames
37 38 * @property ProductCategory[] $productCategories
  39 + * @property TaxGroup $TaxGroup
38 40 */
39 41 class Category extends \yii\db\ActiveRecord
40 42 {
... ... @@ -195,56 +197,99 @@ class Category extends \yii\db\ActiveRecord
195 197 ProductCategory::deleteAll(['category_id' => $this->category_id]);
196 198 return true;
197 199 }
  200 +
  201 + /**
  202 + * @param array $product_id
  203 + * @param array $product_variant_id
  204 + * @return ActiveQuery
  205 + */
  206 +
  207 + public function getFilterQuery( $product_id = [], $product_variant_id = []){
  208 + $query1 = (new Query())
  209 + ->distinct()
  210 + ->select([
  211 + 'option_id'
  212 + ])
  213 + ->from('tax_option')
  214 + ->innerJoin('product_variant_option', 'tax_option.tax_option_id = product_variant_option.option_id')
  215 + ->innerJoin('tax_group', 'tax_group.tax_group_id = tax_option.tax_group_id')
  216 + ->innerJoin('product_variant', 'product_variant.product_variant_id = product_variant_option.product_variant_id')
  217 + ->innerJoin('product', 'product.product_id = product_variant.product_id')
  218 + ->innerJoin('product_category', 'product_category.product_id = product.product_id')
  219 + ->innerJoin('tax_group_to_category', 'tax_group.tax_group_id = tax_group_to_category.tax_group_id')
  220 + ->where(['product_category.category_id' => $this->category_id,
  221 + 'tax_group.is_filter' => TRUE,
  222 + 'tax_group_to_category.category_id'=>$this->category_id,
  223 +
  224 + ])
  225 + ->filterWhere([
  226 + 'product_variant_option.product_variant_id' => $product_variant_id
  227 + ])
  228 + ->andWhere(['!=', 'product_variant.status', 1]);
  229 +
  230 + $query2 = (new Query())
  231 + ->distinct()
  232 + ->select([
  233 + 'option_id'
  234 + ])
  235 + ->from('tax_option')
  236 + ->innerJoin('product_option', 'tax_option.tax_option_id = product_option.option_id')
  237 + ->innerJoin('tax_group', 'tax_group.tax_group_id = tax_option.tax_group_id')
  238 + ->innerJoin('product', 'product.product_id = product_option.product_id')
  239 + ->innerJoin('product_category', 'product_category.product_id = product.product_id')
  240 + ->innerJoin('product_variant', 'product_variant.product_id = product.product_id')
  241 + ->innerJoin('tax_group_to_category', 'tax_group.tax_group_id = tax_group_to_category.tax_group_id')
  242 + ->where(['product_category.category_id' => $this->category_id,
  243 + 'tax_group.is_filter' => TRUE,
  244 + 'tax_group_to_category.category_id'=>$this->category_id,
  245 + ])
  246 + ->filterWhere([
  247 + 'product_option.product_id' => $product_id
  248 + ])
  249 + ->andWhere(['!=', 'product_variant.status', 1]);
  250 + $query3 = (new Query())
  251 + ->select([
  252 + 'tax_option.*',
  253 + 'tax_group.*',
  254 + 'tax_option.alias as option_alias',
  255 + 'tax_group.alias as group_alias',
  256 + 'tax_option.name as value',
  257 + 'tax_option.sort AS tax_option_sort',
  258 + 'tax_group.sort AS tax_group_sort',
  259 + ])
  260 + ->from(['tax_option' ])
  261 + ->where(['tax_option.tax_option_id'=>$query1->union($query2)])
  262 +
  263 + ->innerJoin('tax_group','tax_group.tax_group_id = tax_option.tax_group_id')
  264 + ->orderBy('tax_option.sort, tax_group.sort');
  265 + return $query3;
  266 + }
  267 +
  268 + /**
  269 + * @return mixed
  270 + * @throws \Exception
  271 + */
  272 +
  273 +
198 274 public function getActiveFilters() {
199 275 return Category::getDb()->cache(function(){
200   - $query1 = (new Query())
201   - ->distinct()
202   - ->select([
203   - 'option_id'
204   - ])
205   - ->from('tax_option')
206   - ->innerJoin('product_variant_option', 'tax_option.tax_option_id = product_variant_option.option_id')
207   - ->innerJoin('tax_group', 'tax_group.tax_group_id = tax_option.tax_group_id')
208   - ->innerJoin('product_variant', 'product_variant.product_variant_id = product_variant_option.product_variant_id')
209   - ->innerJoin('product', 'product.product_id = product_variant.product_id')
210   - ->innerJoin('product_category', 'product_category.product_id = product.product_id')
211   - ->innerJoin('tax_group_to_category', 'tax_group.tax_group_id = tax_group_to_category.tax_group_id')
212   - ->where(['product_category.category_id' => $this->category_id, 'tax_group.is_filter' => TRUE,'tax_group_to_category.category_id'=>$this->category_id])
213   - ->andWhere(['!=', 'product_variant.status', 1]);
214   -
215   - $query2 = (new Query())
216   - ->distinct()
217   - ->select([
218   - 'option_id'
219   - ])
220   - ->from('tax_option')
221   - ->innerJoin('product_option', 'tax_option.tax_option_id = product_option.option_id')
222   - ->innerJoin('tax_group', 'tax_group.tax_group_id = tax_option.tax_group_id')
223   - ->innerJoin('product', 'product.product_id = product_option.product_id')
224   - ->innerJoin('product_category', 'product_category.product_id = product.product_id')
225   - ->innerJoin('product_variant', 'product_variant.product_id = product.product_id')
226   - ->innerJoin('tax_group_to_category', 'tax_group.tax_group_id = tax_group_to_category.tax_group_id')
227   - ->where(['product_category.category_id' => $this->category_id, 'tax_group.is_filter' => TRUE,'tax_group_to_category.category_id'=>$this->category_id])
228   - ->andWhere(['!=', 'product_variant.status', 1]);
229   - $query3 = (new Query())
230   - ->select([
231   - 'tax_option.*',
232   - 'tax_group.*',
233   - 'tax_option.alias as option_alias',
234   - 'tax_group.alias as group_alias',
235   - 'tax_option.name as value',
236   - 'tax_option.sort AS tax_option_sort',
237   - 'tax_group.sort AS tax_group_sort',
238   - ])
239   - ->from(['tax_option' ])
240   - ->where(['tax_option.tax_option_id'=>$query1->union($query2)])
241   - ->innerJoin('tax_group','tax_group.tax_group_id = tax_option.tax_group_id')
242   - ->orderBy('tax_option.sort, tax_group.sort');
243   - return $query3->all();
  276 + return $this->getFilterQuery()->all();
244 277 }, 3600);
245 278  
246 279 }
247 280  
  281 + /**
  282 + * @param array $product_id
  283 + * @param array $product_variant_id
  284 + * @return mixed
  285 + */
  286 + public function getSelectFilters($product_id = [], $product_variant_id = []) {
  287 +
  288 + return $this->getFilterQuery($product_id, $product_variant_id)->select('tax_option_id')->column();
  289 +
  290 + }
  291 +
  292 +
248 293 public function getTaxGroupsForMenu()
249 294 {
250 295  
... ... @@ -282,4 +327,5 @@ class Category extends \yii\db\ActiveRecord
282 327 return $this->hasMany(TaxGroup::className(), ['tax_group_id' => 'tax_group_id'])
283 328 ->viaTable('tax_group_to_category', ['category_id' => 'category_id']);
284 329 }
  330 +
285 331 }
... ...
common/modules/product/models/Product.php
... ... @@ -504,4 +504,5 @@ class Product extends \yii\db\ActiveRecord
504 504 ->viaTable('product_option',[ 'product_id'=> 'product_id'])
505 505 ->joinWith('taxGroup');
506 506 }
  507 +
507 508 }
... ...
common/modules/product/models/ProductVariant.php
... ... @@ -215,6 +215,10 @@ class ProductVariant extends \yii\db\ActiveRecord
215 215 return $this->hasMany(TaxOption::className(), ['tax_option_id' => 'option_id'])->viaTable('product_variant_option', ['product_variant_id' => 'product_variant_id']);
216 216 }
217 217  
  218 + public function setOptions($value){
  219 + $this->_options = $value;
  220 + }
  221 +
218 222 public function getProperties() {
219 223 $groups = $options = [];
220 224 foreach ($this->options as $option) {
... ...
common/widgets/views/order.php
... ... @@ -3,7 +3,7 @@
3 3 <html lang="uk">
4 4 <head>
5 5 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
6   - <title>Rukzachok.com.ua</title>
  6 + <title>linija-svitla.ua</title>
7 7 <style type="text/css">
8 8 body {
9 9 font-family: helvetica neue, arial, sans-serif;
... ... @@ -57,8 +57,6 @@
57 57 </td>
58 58 <td style="text-align: left; vertical-align: top; font-size: 85%; padding: 20px 20px 15px 15px;">
59 59 <strong>Спасибо за Ваш заказ!</strong>
60   - <br>
61   - <a href="http://www.rukzachok.com.ua"
62 60 </td>
63 61 </tr>
64 62 <tr>
... ...
console/controllers/FilterController.php 0 → 100644
  1 +<?php
  2 +
  3 +namespace console\controllers;
  4 +
  5 +use \common\models\FilterCache;
  6 +use common\modules\product\helpers\FilterHelper;
  7 +use common\modules\product\helpers\ProductHelper;
  8 +use common\modules\product\models\Category;
  9 +use common\modules\product\models\Product;
  10 +use common\modules\product\models\ProductVariant;
  11 +use common\modules\rubrication\models\TaxGroup;
  12 +use common\modules\rubrication\models\TaxOption;
  13 +use Yii;
  14 +use yii\console\Controller;
  15 +use yii\db\ActiveQuery;
  16 +
  17 +class FilterController extends Controller
  18 +{
  19 +
  20 + public $count = 1;
  21 + public $begin_time;
  22 + const DEPTH = 5;
  23 +
  24 +
  25 +
  26 +
  27 + public function actionIndex()
  28 + {
  29 + $categories = Category::find()->all();
  30 +
  31 + foreach($categories as $category){
  32 + /**
  33 + *@var TaxGroup $taxGroup
  34 + *@var Category $category
  35 + *@var TaxOption $option
  36 + */
  37 +
  38 + $taxOptions = $category->filterQuery->all();
  39 + $brands = $category->brands;
  40 + foreach($brands as $brand){
  41 + $taxOptions[] = [
  42 + 'group_alias' => 'brands',
  43 + 'option_alias' => $brand->brand_id,
  44 + 'tax_option_id' => $brand->brand_id,
  45 + ];
  46 + }
  47 + $count = count($taxOptions);
  48 + $key = 0;
  49 +// $sumArray = FilterCache::find()->select('options_key')->column();
  50 +// print_r($sumArray);
  51 +// die();
  52 + $sumArray=[];
  53 + $optionsIdArray = [];
  54 + $params = [];
  55 +
  56 + $this->begin_time = time() - 1272000000 + floatval(microtime());
  57 + $this->RecursiveOptionFinder($category,$count, $taxOptions,$key,$sumArray,$optionsIdArray,$params);
  58 +
  59 + $end_time = time() - 1272000000 + floatval(microtime()) - $this->begin_time;
  60 + print_r($end_time);
  61 + die();
  62 +
  63 + }
  64 + }
  65 +
  66 +
  67 + /**
  68 + * @param Category $category
  69 + * @param $count
  70 + * @param TaxOption array $taxOptions
  71 + * @param $key
  72 + * @param $sumArray
  73 + * @param $optionsIdArray
  74 + * @param array $params
  75 + */
  76 +
  77 + public function RecursiveOptionFinder($category, $count, $taxOptions, $key, &$sumArray, $optionsIdArray,$params){
  78 +
  79 + for($o = $key; $o <= $count; $o++){
  80 + if(isset($taxOptions[$o]) && (count($optionsIdArray) < self::DEPTH)){
  81 + $_optionsIdArray = $optionsIdArray;
  82 + $_optionsIdArray[] = $taxOptions[$o]['tax_option_id'];
  83 + $sum = FilterCache::createCacheKey($_optionsIdArray);
  84 + if( !in_array( $sum, $sumArray)){
  85 +
  86 + $sumArray[] = $sum;
  87 + $key = $o+1;
  88 + $this->selectParams($params,$taxOptions[$o]['group_alias'], $taxOptions[$o]['option_alias']);
  89 + $this->RecursiveOptionFinder($category,$count, $taxOptions, $key, $sumArray,$optionsIdArray,$params);
  90 + $optionsIdArray[] = $taxOptions[$o]['tax_option_id'];
  91 + $this->saveFilterCache($category,$params, $sum,$optionsIdArray);
  92 + $o++;
  93 + } else {
  94 + $optionsIdArray[] = $taxOptions[$o]['tax_option_id'];
  95 + $key = $o+1;
  96 + $this->selectParams($params,$taxOptions[$o]['group_alias'], $taxOptions[$o]['option_alias']);
  97 + $this->RecursiveOptionFinder($category,$count, $taxOptions, $key, $sumArray,$optionsIdArray,$params);
  98 + $o++;
  99 + }
  100 + }
  101 + }
  102 + }
  103 +
  104 + public function selectParams(&$params,$alias,$optionAlias){
  105 +
  106 + if(isset($params[$alias])){
  107 + $params[$alias][] = $optionAlias;
  108 + } else {
  109 +
  110 + $params = array_merge($params, [$alias=>[$optionAlias]]);
  111 + }
  112 + return $params;
  113 + }
  114 +
  115 + /**
  116 + *
  117 + * @param Category $category
  118 + * @param array $params
  119 + * @param $options_key
  120 + * @param array $optionsIdArray
  121 + */
  122 +
  123 + public function saveFilterCache($category,$params, $options_key,$optionsIdArray){
  124 + $count = $this->findItem($category,$params);
  125 +
  126 + $model = new FilterCache();
  127 + $model->category_id = $category->category_id;
  128 + $model->count = $count;
  129 + $model->depth = count($optionsIdArray);
  130 + $model->options_key = $options_key;
  131 + $model->save();
  132 + }
  133 +
  134 +
  135 + /**
  136 + * @param Category $category
  137 + * @param array $params
  138 + * @return int
  139 + */
  140 + public function findItem($category,$params){
  141 + return $this->getSearchQuery($category,$params)->count();
  142 + //$count2 = $this->getSearchQuery2($category,$params)->count();
  143 +// $this->count ++;
  144 +// if($this->count == 100){
  145 +// $end_time = time() - 1272000000 + floatval(microtime()) - $this->begin_time;
  146 +// print_r($end_time);
  147 +// die();
  148 +// }
  149 + }
  150 +
  151 + public function getSearchQuery($category = null, $params = []) {
  152 +
  153 +
  154 + /** @var ActiveQuery $query */
  155 + /**@var Category $category **/
  156 + $query = $category->getProducts();
  157 +
  158 +
  159 + $query->select(['product.*']);
  160 + $query->joinWith(['enabledVariants','brand','options', 'category']);
  161 +
  162 + $query->groupBy(['product.product_id', 'product_variant.price']);
  163 +
  164 + ProductHelper::_setQueryParams($query, $params);
  165 +
  166 + $query->andWhere(['!=', ProductVariant::tableName() .'.status', 1]);
  167 +
  168 +
  169 +
  170 + return $query;
  171 +
  172 + }
  173 +
  174 +// public function getSearchQuery2($category = null, $params = []) {
  175 +//
  176 +//
  177 +// /** @var ActiveQuery $query */
  178 +// /**@var Category $category **/
  179 +// $query = $category->getProducts();
  180 +//
  181 +//
  182 +// $query->select(['product.*']);
  183 +// $query->joinWith(['enabledVariants','brand','options', 'category']);
  184 +//
  185 +// $query->groupBy(['product.product_id', 'product_variant.price']);
  186 +//
  187 +// FilterHelper::setNewQueryParams($query, $params);
  188 +//
  189 +// $query->andWhere(['!=', ProductVariant::tableName() .'.status', 1]);
  190 +//
  191 +//
  192 +//
  193 +// return $query;
  194 +//
  195 +// }
  196 +
  197 +}
  198 +
... ...
console/migrations/m160321_232402_orders1.php deleted
1   -<?php
2   -
3   -use yii\db\Migration;
4   -
5   -class m160321_232402_orders extends Migration
6   -{
7   - public function up()
8   - {
9   - $tableOptions = null;
10   - if ($this->db->driverName === 'mysql') {
11   - // http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci
12   - $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
13   - }
14   -
15   - $this->createTable('{{%orders}}', [
16   - 'order_id' => $this->primaryKey(),
17   - 'customer_id' => $this->integer(),
18   - 'name' => $this->string()->notNull(),
19   - 'email' => $this->string()->notNull(),
20   - 'phone' => $this->string(32)->notNull(),
21   - 'delivery' => $this->integer(),
22   - 'payment' => $this->integer(),
23   - 'code' => $this->string(),
24   - 'status' => $this->smallInteger(),
25   - 'created_at' => $this->integer()->notNull(),
26   - 'updated_at' => $this->integer()->notNull(),
27   - ], $tableOptions);
28   -
29   - $this->createTable('{{%order_items}}', [
30   - 'order_items_id' => $this->primaryKey(),
31   - 'order_id' => $this->integer(),
32   - 'item_id' => $this->integer(),
33   - 'item_count' => $this->integer(),
34   - 'price' => $this->float(),
35   - ], $tableOptions);
36   -
37   - $this->addForeignKey('orders_items_fk', '{{%order_items}}', 'order_id', '{{%orders}}', 'order_id', 'CASCADE', 'CASCADE');
38   - $this->addForeignKey('orders_items_items_fk', '{{%order_items}}', 'item_id', '{{%product}}', 'product_id', 'RESTRICT', 'RESTRICT');
39   - }
40   -
41   - public function down()
42   - {
43   - $this->dropForeignKey('orders_items_fk', '{{%order_items}}');
44   - $this->dropForeignKey('orders_items_items_fk', '{{%order_items}}');
45   - $this->dropTable('{{%orders}}');
46   - $this->dropTable('{{%order_items}}');
47   - }
48   -
49   -}
console/migrations/m161104_094427_filter_cache.php 0 → 100644
  1 +<?php
  2 +
  3 +use yii\db\Migration;
  4 +
  5 +class m161104_094427_filter_cache extends Migration
  6 +{
  7 + public function up()
  8 + {
  9 + $this->createTable('filter_cache', [
  10 + 'id' => $this->primaryKey(),
  11 + 'options_key' => $this->integer(20),
  12 + 'category_id' => $this->integer(),
  13 + 'depth' => $this->integer(),
  14 + 'count' => $this->integer(),
  15 + ]);
  16 + }
  17 +
  18 + public function down()
  19 + {
  20 + $this->dropTable('filter_cache');
  21 + }
  22 +}
... ...
frontend/config/main.php
... ... @@ -10,10 +10,6 @@ return [
10 10 'id' => 'app-frontend',
11 11 'name'=>'Лінія Світла',
12 12 'basePath' => dirname(__DIR__),
13   - 'bootstrap' => [
14   -
15   - 'frontend\components\SeoComponent',
16   - ],
17 13 'controllerNamespace' => 'frontend\controllers',
18 14 'modules' => [
19 15  
... ...
frontend/controllers/AjaxController.php
... ... @@ -3,6 +3,11 @@
3 3 namespace frontend\controllers;
4 4  
5 5 use common\models\Feedback;
  6 +use common\modules\product\helpers\ProductHelper;
  7 +use common\modules\product\models\Brand;
  8 +use common\modules\product\models\Category;
  9 +use common\modules\product\models\ProductVariant;
  10 +use yii\db\ActiveQuery;
6 11 use yii\web\Controller;
7 12 use \common\modules\product\widgets\specialProducts;
8 13 class AjaxController extends Controller
... ... @@ -46,4 +51,62 @@ class AjaxController extends Controller
46 51 public function actionProm(){
47 52 return specialProducts::widget(['type' => 'promo']);
48 53 }
  54 +
  55 +
  56 + public function actionTest(){
  57 + $filter = \Yii::$app->request->get('info');
  58 +
  59 +
  60 + if(!empty( $filter[ 'brands' ] )) {
  61 + $brands = Brand::find()
  62 + ->select('brand_id')
  63 + ->where([
  64 + 'in',
  65 + 'alias',
  66 + $filter[ 'brands' ],
  67 + ])
  68 + ->all();
  69 + $filter[ 'brands' ] = [ ];
  70 + foreach($brands as $brand) {
  71 + $filter[ 'brands' ][] = $brand->brand_id;
  72 + }
  73 + }
  74 +
  75 + if(!empty($filter)){
  76 + $category = Category::findOne(176);
  77 + return $this->findItem($category,$filter);
  78 + } else {
  79 + return 'test';
  80 + }
  81 +
  82 + }
  83 +
  84 + public function getSearchQuery($category = null, $params = []) {
  85 +
  86 +
  87 + /** @var ActiveQuery $query */
  88 + /**@var Category $category **/
  89 + $query = $category->getProducts();
  90 +
  91 +
  92 + $query->select(['product.*']);
  93 + $query->joinWith(['enabledVariants','brand','options', 'category']);
  94 +
  95 + $query->groupBy(['product.product_id', 'product_variant.price']);
  96 +
  97 + ProductHelper::_setQueryParams($query, $params);
  98 +
  99 + $query->andWhere(['!=', ProductVariant::tableName() .'.status', 1]);
  100 +
  101 +
  102 +
  103 + return $query;
  104 +
  105 + }
  106 +
  107 +
  108 +
  109 + public function findItem($category,$params){
  110 + return $this->getSearchQuery($category,$params)->count();
  111 + }
49 112 }
50 113 \ No newline at end of file
... ...
frontend/controllers/CatalogController.php
... ... @@ -2,33 +2,22 @@
2 2  
3 3 namespace frontend\controllers;
4 4  
5   -use common\modules\product\Filter;
  5 +
6 6 use common\modules\product\helpers\ProductHelper;
7   -use common\modules\rubrication\models\TaxOptionSearch;
8 7 use frontend\models\ProductFrontendSearch;
9 8 use Yii;
10 9 use common\modules\product\models\Brand;
11 10 use common\modules\product\models\BrandSearch;
12 11 use common\modules\product\models\Category;
13   -use common\modules\product\models\CategorySearch;
14 12 use common\modules\product\models\Product;
15   -use common\modules\product\models\ProductCategory;
16   -use common\modules\product\models\ProductOption;
17   -use common\modules\product\models\ProductSearch;
18   -use common\modules\product\models\ProductVariant;
19 13 use common\modules\rubrication\models\TaxGroup;
20   -use common\modules\rubrication\models\TaxOption;
21   -use common\modules\rubrication\models\TaxValueString;
22 14 use yii\data\ActiveDataProvider;
23   -use yii\data\Pagination;
24   -use yii\data\Sort;
25   -use yii\db\ActiveQuery;
26 15 use yii\helpers\ArrayHelper;
27   -use yii\helpers\VarDumper;
28   -use yii\web\HttpException;
29 16  
30 17 class CatalogController extends \yii\web\Controller
31 18 {
  19 +
  20 +
32 21 public function actionSearch() {
33 22 // @todo
34 23 }
... ... @@ -36,6 +25,7 @@ class CatalogController extends \yii\web\Controller
36 25 public function actionCategory()
37 26 {
38 27  
  28 +
39 29 /** @var Category $category */
40 30 $category = Yii::$app->request->get('category');
41 31 $filter = Yii::$app->request->get('filters', [ ]);
... ... @@ -53,21 +43,7 @@ class CatalogController extends \yii\web\Controller
53 43 ->where([ 'is_filter' => 'TRUE' ])
54 44 ->all(), 'alias');
55 45  
56   - if(!empty( $filter[ 'brands' ] )) {
57   - unset( $filter_check[ 'brands' ] );
58   - $brands = Brand::find()
59   - ->select('brand_id')
60   - ->where([
61   - 'in',
62   - 'alias',
63   - $filter[ 'brands' ],
64   - ])
65   - ->all();
66   - $params[ 'brands' ] = [ ];
67   - foreach($brands as $brand) {
68   - $params[ 'brands' ][] = $brand->brand_id;
69   - }
70   - }
  46 +
71 47  
72 48 if(!empty( $filter[ 'special' ] )) {
73 49 unset( $filter_check[ 'special' ] );
... ... @@ -90,6 +66,24 @@ class CatalogController extends \yii\web\Controller
90 66 $params[ 'prices' ] = $filter[ 'prices' ];
91 67 }
92 68  
  69 + $activeFiltersParams = $filter_check;
  70 +
  71 + if(!empty( $filter[ 'brands' ] )) {
  72 + unset( $filter_check[ 'brands' ] );
  73 + $brands = Brand::find()
  74 + ->select('brand_id')
  75 + ->where([
  76 + 'in',
  77 + 'alias',
  78 + $filter[ 'brands' ],
  79 + ])
  80 + ->all();
  81 + $params[ 'brands' ] = [ ];
  82 + foreach($brands as $brand) {
  83 + $params[ 'brands' ][] = $brand->brand_id;
  84 + }
  85 + }
  86 +
93 87 foreach($optionsList as $optionList) {
94 88  
95 89 if(isset( $filter[ $optionList ] )) {
... ... @@ -109,26 +103,70 @@ class CatalogController extends \yii\web\Controller
109 103 }
110 104  
111 105 $productModel = new ProductFrontendSearch();
  106 +
112 107 $productProvider = $productModel->search($category, $params);
113 108  
  109 +
114 110 $brandModel = new BrandSearch();
115 111 $brands = $brandModel->getBrands($category, $params)
116 112 ->all();
117 113  
  114 +
118 115 $groups = $category->getActiveFilters();
  116 +
  117 + foreach($brands as $brand){
  118 + array_unshift($groups , [
  119 + 'group_alias' => 'brands',
  120 + 'option_alias' => $brand->alias,
  121 + 'tax_option_id' => $brand->brand_id,
  122 + 'value' => $brand->name,
  123 + 'alias' => 'brands',
  124 + 'name' => 'Бренды'
  125 + ]);
  126 + }
  127 +
  128 +
  129 +
  130 + foreach ($groups as $key=> $group) {
  131 + $param = $activeFiltersParams;
  132 + if(isset($param[$group['alias']])){
  133 + if(!in_array($group['option_alias'],$param[$group['alias']])){
  134 + $param[$group['alias']][] = $group['option_alias'];
  135 + } else {
  136 + continue;
  137 + }
  138 + }else {
  139 + $param = array_merge($param, [$group['alias']=>[$group['option_alias']]]);
  140 + }
  141 +
  142 + $groups[$key] = array_merge($groups[$key],['cacheKey' => json_encode($param)] );
  143 +
  144 + }
  145 +
  146 +
  147 +
119 148 $groups = ArrayHelper::index($groups, null, 'name');
120   - $priceLimits = $productModel->priceLimits($category, $params);
  149 +
  150 +
  151 +
  152 +
  153 + $cacheKey = ['ActiveProperties','id' => $category, 'params' => $params];
  154 +
  155 + if(!$priceLimits = Yii::$app->cache->get($cacheKey)){
  156 +
  157 + $priceLimits = $productModel->priceLimits($category, $params);
  158 +
  159 + Yii::$app->cache->set($cacheKey,$priceLimits,3600*24);
  160 + }
121 161  
122 162  
123 163 return $this->render('products', [
124 164 'category' => $category,
125   - 'brandModel' => $brandModel,
126   - 'brands' => $brands,
127 165 'filter' => $filter,
128 166 'params' => $params,
129 167 'productModel' => $productModel,
130 168 'productProvider' => $productProvider,
131   - 'groups' => $groups,
  169 + 'groups' => $groups,
132 170 'priceLimits' => $priceLimits,
133 171 ]);
134 172  
... ...
frontend/controllers/SiteController.php
... ... @@ -3,6 +3,7 @@
3 3 namespace frontend\controllers;
4 4  
5 5  
  6 +use common\modules\product\models\Category;
6 7 use Yii;
7 8 use common\models\LoginForm;
8 9 use frontend\models\PasswordResetRequestForm;
... ... @@ -223,23 +224,11 @@ class SiteController extends Controller
223 224 {
224 225  
225 226  
226   - $category_alias = Yii::$app->request->get('category');
227   - $is_count = Yii::$app->request->get('count', false);
228 227  
229   - if ( !($category = CategorySearch::findByAlias($category_alias)))
230   - {
231   - throw new HttpException(404, 'Данной страницы не существует!');
232   - }
233   -
234   - $products = $category->getProducts()->with(['filters','filters.group'])->joinWith('variant')->where(['product_variant.status'=>0])->all();
235   -
236   - if ($is_count) {
237   - print (count($products));
238   - exit;
239   - }
  228 + $is_count = Yii::$app->request->get('count', false);
240 229  
  230 + $categories = Category::find()->all();
241 231  
242   -//var_dump($products);die();
243 232 set_time_limit (0);
244 233 header ("Content-Type: text/xml");
245 234 print '<?xml version="1.0" encoding="UTF-8" ?>';
... ... @@ -250,17 +239,31 @@ class SiteController extends Controller
250 239 print "<rate></rate>";
251 240 print "<categories>";
252 241  
253   - print "<category>";
254   - print "<id>" . $category->category_id . "</id>";
255   - print "<parentId></parentId>";
256   - print "<name>" . $category->name . "</name>";
257   - print "</category>";
258   -
  242 + foreach($categories as $category){
  243 + print "<category>";
  244 + print "<id>" .$category->category_id . "</id>";
  245 + print "<name>" . $category->name. "</name>";
  246 + print "</category>";
  247 + }
259 248 print "</categories>";
  249 +
  250 +
  251 +
  252 +
260 253 print "<items>";
261   - /** @var Product $product */
262   - foreach ($products as $product)
263   - {
  254 +
  255 + foreach($categories as $category){
  256 + $products = $category->getProducts()->with(['filters','filters.group'])->joinWith('variant')->where(['product_variant.status'=>0])->all();
  257 +
  258 + if ($is_count) {
  259 + print (count($products));
  260 + continue;
  261 + }
  262 +
  263 + /** @var Product $product */
  264 +
  265 + foreach ($products as $product)
  266 + {
264 267  
265 268  
266 269 print "<item>";
... ... @@ -338,9 +341,19 @@ class SiteController extends Controller
338 341 print "</item>";
339 342  
340 343  
  344 + }
  345 +
341 346 }
342 347  
343 348  
  349 +
  350 +
  351 +
  352 +//var_dump($products);die();
  353 +
  354 +
  355 +
  356 +
344 357 print "</items>";
345 358  
346 359 print "</price>";
... ...
frontend/models/ProductFrontendSearch.php
... ... @@ -2,6 +2,7 @@
2 2  
3 3 namespace frontend\models;
4 4  
  5 +use common\modules\product\helpers\FilterHelper;
5 6 use common\modules\product\helpers\ProductHelper;
6 7 use common\modules\product\models\Category;
7 8 use Yii;
... ... @@ -80,9 +81,7 @@ class ProductFrontendSearch extends Product {
80 81 ]
81 82 ]);
82 83  
83   - if (!$this->validate()) {
84   - return $dataProvider;
85   - }
  84 +
86 85  
87 86  
88 87  
... ... @@ -105,7 +104,7 @@ class ProductFrontendSearch extends Product {
105 104  
106 105 $query->groupBy(['product.product_id', 'product_variant.price']);
107 106  
108   - ProductHelper::_setQueryParams($query, $params);
  107 + FilterHelper::setNewQueryParams($query, $params);
109 108 if($in_stock){
110 109 $query->andWhere(['!=', ProductVariant::tableName() .'.status', 1]);
111 110 }
... ...
frontend/views/catalog/_product_item.php
... ... @@ -10,10 +10,10 @@ use yii\helpers\Url;
10 10 <div class="item_container" >
11 11 <input class="prodInfo" type="hidden" value="[]">
12 12 <div class="title">
13   - <?= Html::a( $model->name, Url::to(['catalog/product', 'product' => $model->alias]), ['class'=>'btn-product-details'] )?>
  13 + <?= Html::a( $model->name, Url::to(['catalog/product', 'product' => $model->alias]), ['class'=>'btn-product-details','data-pjax'=>0] )?>
14 14 </div>
15 15 <div class="img">
16   - <a class="btn-product-details"
  16 + <a data-pjax=0 class="btn-product-details"
17 17  
18 18  
19 19 href="<?= Url::to([
... ...
frontend/views/catalog/products.php
... ... @@ -4,13 +4,19 @@
4 4 * @var View $this
5 5 */
6 6 use frontend\widgets\FilterWidget;
7   -use frontend\widgets\Seo;
8   -use yii\helpers\Url;
  7 + use frontend\widgets\Seo;
  8 + use yii\helpers\Url;
9 9 use yii\web\View;
10 10 use yii\widgets\ListView;
  11 + use yii\widgets\Pjax;
  12 + $this->registerCssFile (Yii::getAlias('@web/css/ion.rangeSlider.css'));
  13 + $this->registerCssFile (Yii::getAlias('@web/css/ion.rangeSlider.skinHTML5.css'));
  14 + $this->registerJsFile(Yii::getAlias('@web/js/ion.rangeSlider.js'),[
  15 + 'position' => View::POS_END,
  16 + 'depends' => ['yii\web\JqueryAsset']
  17 + ]);
11 18  
12   -
13   - $this->params['seo']['title'] = !empty($category->meta_title) ? $category->meta_title : $category->name;
  19 +$this->params['seo']['title'] = !empty($category->meta_title) ? $category->meta_title : $category->name;
14 20  
15 21 $this->params['seo']['fields']['meta-title'] = $category->meta_title;
16 22 $this->params['seo']['h1'] = !empty($category->h1) ? $category->h1 : $category->name;
... ... @@ -29,16 +35,20 @@ use yii\helpers\Url;
29 35 'position' => View::POS_END,
30 36 'depends' => ['yii\web\JqueryAsset']
31 37 ]);
  38 + $this->registerJsFile(Yii::getAlias('@web/js/filter.js'),[
  39 + 'position' => View::POS_END,
  40 + 'depends' => ['yii\web\JqueryAsset']
  41 + ]);
32 42 ?>
33   -
  43 +<?php Pjax::begin(['timeout' => 5000,'id'=> 'list-container'])?>
34 44 <div class="container">
35 45 <div class="block-25" style="position: relative;">
36 46 <?= FilterWidget::widget([
37 47 'category'=>$category,
38 48 'groups'=> $groups,
39 49 'filter'=> $filter,
40   - 'brands' => $brands,
41   - 'priceLimits' => $priceLimits
  50 + 'priceLimits' => $priceLimits,
  51 + //'filterBrands' => $filterBrands
42 52 ])?>
43 53  
44 54 <div class="clearfix"></div>
... ... @@ -92,45 +102,6 @@ use yii\helpers\Url;
92 102  
93 103  
94 104  
95   - <?php $js = "$('.toolbar-list').click(function(event) {
96   - //alert(1);
97   - $('.toolbar-list').addClass('selected');
98   - $('.toolbar-grid').removeClass('selected');
99   - $('#centrit .prodBox').addClass('list');
100   - JsHttpRequest.query(
101   - 'hr_gate.php?test=500&r='+Math.random(),
102   - {
103   - 'sp': 'prod_list_style'
104   - ,'style': 1
105   - },
106   - function(result, errors) { },
107   - true //disable caching
108   - );
109   - });
110   - $('.toolbar-grid').click(function(event) {
111   - $('.toolbar-grid').addClass('selected');
112   - $('.toolbar-list').removeClass('selected');
113   - $('#centrit .prodBox').removeClass('list');
114   - JsHttpRequest.query(
115   - 'hr_gate.php?test=500&r='+Math.random(),
116   - {
117   - 'sp': 'prod_list_style'
118   - ,'style': 2
119   - },
120   - function(result, errors) { },
121   - true //disable caching
122   - );
123   -
124   - });
125   -
126   -
127   -
128   -
129   - ";
130   - $this->registerJs($js,View::POS_READY);
131   - ?>
132   -
133   -
134 105  
135 106  
136 107 <div class="catalog_product_list view_table">
... ... @@ -157,6 +128,6 @@ use yii\helpers\Url;
157 128  
158 129 </div>
159 130 </div>
160   -
  131 +<?php Pjax::end()?>
161 132  
162 133  
... ...
frontend/views/event/index.php
... ... @@ -32,7 +32,7 @@ $this-&gt;params[&#39;seo&#39;][&#39;h1&#39;] = $this-&gt;title;
32 32  
33 33 <div class="both"></div>
34 34  
35   -
36   - </div>
37   -
  35 +
  36 + </div>
  37 +
38 38 </div>
39 39 \ No newline at end of file
... ...
frontend/views/event/show.php
... ... @@ -71,6 +71,7 @@ $this-&gt;params[&#39;seo&#39;][&#39;h1&#39;] = $this-&gt;title;
71 71  
72 72 <div class="catalog_product_list view_table">
73 73 <?= ListView::widget([
  74 + 'emptyText' => '',
74 75 'dataProvider' => $productProvider,
75 76 'itemView' => function ($model, $key, $index, $widget) {
76 77 return $this->render('../catalog/_product_item',[
... ...
frontend/web/css/css_header.css
... ... @@ -26965,4 +26965,8 @@ ul.product-special li.promo div {
26965 26965  
26966 26966 .irs-slider.state_hover, .irs-slider{
26967 26967 background: #9fa4a8;
  26968 +}
  26969 +
  26970 +.disabled-link{
  26971 + color: grey !important;
26968 26972 }
26969 26973 \ No newline at end of file
... ...
frontend/web/js/filter.js 0 → 100644
  1 +/**
  2 + * Created by vitaliy on 07.11.16.
  3 + */
  4 +
  5 +function loadService(){
  6 +
  7 + $('.properties_block').each(function(){
  8 + var block = $(this);
  9 + $(this).find('input[type=checkbox]').each(function(){
  10 + if(this.checked){
  11 + block.removeClass('closed').addClass('opened');
  12 + block.find('ul').css({"display":"block"})
  13 + return true;
  14 + }
  15 +
  16 + });
  17 +
  18 + });
  19 +
  20 + $('#finput').keyup(function() {
  21 +
  22 + var empty = false;
  23 + $('#finput').each(function() {
  24 + if ($(this).val() == '') {
  25 + empty = true;
  26 + }
  27 + });
  28 +
  29 + if (empty) {
  30 + $('.sok').attr('disabled', 'disabled').css('display','none');
  31 + } else {
  32 + $('.sok').removeAttr('disabled').css('display','inline-block');
  33 + }
  34 +
  35 + });
  36 +
  37 +
  38 +
  39 +
  40 +
  41 +
  42 + $('.price_tooltip_close').on('click',function(){
  43 + $(this).parent().hide();
  44 + });
  45 +
  46 + $('.pok').click(function(event) {
  47 + url = $('#purl').val();
  48 + price_min = $('#min_price').val();
  49 + price_max = $('#max_price').val();
  50 +
  51 + document.location.href = url + "&pmin=" + price_min + "&pmax=" + price_max;
  52 + });
  53 +
  54 + $('.sok').click(function(event) {
  55 + if ($('#finput').val() != "Артикул" && $('#finput').val() != "") {
  56 +
  57 +
  58 + document.location.href = "/search/main?word="+$('#finput').val();
  59 +
  60 +
  61 + }
  62 + });
  63 +}
  64 +
  65 +function priceRequest(link){
  66 + var tag = $(link).parents('li');
  67 + var filter = tag.data('filter');
  68 + $.ajax({
  69 + url: "/ajax/test",
  70 + type: 'GET',
  71 + data: {info:filter},
  72 + success: function(result){
  73 + if(result=='0'){
  74 + $(link).addClass('disabled-link');
  75 + tag.find('input').prop( "disabled", true );
  76 + $(link).find("span").html(result);
  77 + } else {
  78 + $(link).removeClass('disabled-link');
  79 + tag.find('input').prop( "disabled", false );
  80 + $(link).find("span").html(result);
  81 + }
  82 +
  83 +
  84 + }});
  85 +}
  86 +
  87 +
  88 +function loadPrices(){
  89 + $('.filter-link').each(function(){
  90 + if(!$(this).parents('li').data('checked')){
  91 + priceRequest(this);
  92 + }
  93 +
  94 +
  95 + });
  96 +}
  97 +
  98 +
  99 +function priceSlider(){
  100 +
  101 +
  102 + if($('#price_interval').length){
  103 +
  104 + var block = $('#price_block');
  105 + var link = block.data('url');
  106 + var min = block.data('min');
  107 + var max = block.data('max');
  108 + var from = block.data('from');
  109 + var to = block.data('to');
  110 +
  111 +
  112 + $('#price_interval').ionRangeSlider({
  113 + type: 'double',
  114 + min: min,
  115 + max: max,
  116 + from: from,
  117 + to: to,
  118 + grid: false,
  119 + onFinish: function(e) {
  120 + var url = link;
  121 + var from = e.from;
  122 + var to = e.to;
  123 + $.pjax({url: url.replace('{from}', from).replace('{to}', to), container: "#list-container",timeout:5000, scrollTo: false})
  124 + }
  125 + });
  126 + }
  127 +}
  128 +
  129 +$( document ).ready(function() {
  130 + loadService();
  131 + loadPrices();
  132 + priceSlider();
  133 +
  134 + $('body').on('click', '.disabled-link', function(e){
  135 + e.preventDefault();
  136 + });
  137 +
  138 + $('body').on('change', '.features-option', function(){
  139 + var url = $(this).parents('li').find('a').attr('href');
  140 + $.pjax({url: url, container: '#list-container',timeout:5000,scrollTo:false })
  141 + });
  142 +
  143 + $("#list-container").on("pjax:end", function() {
  144 + loadPrices();
  145 + loadService();
  146 + priceSlider();
  147 +
  148 + });
  149 +
  150 +
  151 +
  152 +
  153 +
  154 +
  155 +});
... ...
frontend/widgets/FilterList.php 0 → 100644
  1 +<?php
  2 +/**
  3 + * @link http://www.yiiframework.com/
  4 + * @copyright Copyright (c) 2008 Yii Software LLC
  5 + * @license http://www.yiiframework.com/license/
  6 + */
  7 +
  8 +namespace frontend\widgets;
  9 +
  10 +use Yii;
  11 +use yii\base\Widget;
  12 +use yii\helpers\ArrayHelper;
  13 +use yii\helpers\Url;
  14 +use yii\helpers\Html;
  15 +
  16 +/**
  17 + * Menu displays a multi-level menu using nested HTML lists.
  18 + *
  19 + * The main property of Menu is [[items]], which specifies the possible items in the menu.
  20 + * A menu item can contain sub-items which specify the sub-menu under that menu item.
  21 + *
  22 + * Menu checks the current route and request parameters to toggle certain menu items
  23 + * with active state.
  24 + *
  25 + * Note that Menu only renders the HTML tags about the menu. It does do any styling.
  26 + * You are responsible to provide CSS styles to make it look like a real menu.
  27 + *
  28 + * The following example shows how to use Menu:
  29 + *
  30 + * ```php
  31 + * echo FilterList::widget([
  32 + * 'items' => [
  33 + * // Important: you need to specify url as 'controller/action',
  34 + * // not just as 'controller' even if default action is used.
  35 + * ['label' => 'Home', 'url' => ['site/index']],
  36 + * // 'Products' menu item will be selected as long as the route is 'product/index'
  37 + * ['label' => 'Products', 'url' => ['product/index'], 'items' => [
  38 + * ['label' => 'New Arrivals', 'url' => ['product/index', 'tag' => 'new']],
  39 + * ['label' => 'Most Popular', 'url' => ['product/index', 'tag' => 'popular']],
  40 + * ]],
  41 + * ['label' => 'Login', 'url' => ['site/login'], 'visible' => Yii::$app->user->isGuest],
  42 + * ],
  43 + * ]);
  44 + * ```
  45 + *
  46 + * @author Qiang Xue <qiang.xue@gmail.com>
  47 + * @since 2.0
  48 + */
  49 +class FilterList extends Widget
  50 +{
  51 + /**
  52 + * @var array list of menu items. Each menu item should be an array of the following structure:
  53 + *
  54 + * - label: string, optional, specifies the menu item label. When [[encodeLabels]] is true, the label
  55 + * will be HTML-encoded. If the label is not specified, an empty string will be used.
  56 + * - encode: boolean, optional, whether this item`s label should be HTML-encoded. This param will override
  57 + * global [[encodeLabels]] param.
  58 + * - url: string or array, optional, specifies the URL of the menu item. It will be processed by [[Url::to]].
  59 + * When this is set, the actual menu item content will be generated using [[linkTemplate]];
  60 + * otherwise, [[labelTemplate]] will be used.
  61 + * - visible: boolean, optional, whether this menu item is visible. Defaults to true.
  62 + * - items: array, optional, specifies the sub-menu items. Its format is the same as the parent items.
  63 + * - active: boolean, optional, whether this menu item is in active state (currently selected).
  64 + * If a menu item is active, its CSS class will be appended with [[activeCssClass]].
  65 + * If this option is not set, the menu item will be set active automatically when the current request
  66 + * is triggered by `url`. For more details, please refer to [[isItemActive()]].
  67 + * - template: string, optional, the template used to render the content of this menu item.
  68 + * The token `{url}` will be replaced by the URL associated with this menu item,
  69 + * and the token `{label}` will be replaced by the label of the menu item.
  70 + * If this option is not set, [[linkTemplate]] or [[labelTemplate]] will be used instead.
  71 + * - submenuTemplate: string, optional, the template used to render the list of sub-menus.
  72 + * The token `{items}` will be replaced with the rendered sub-menu items.
  73 + * If this option is not set, [[submenuTemplate]] will be used instead.
  74 + * - options: array, optional, the HTML attributes for the menu container tag.
  75 + */
  76 + public $items = [];
  77 + /**
  78 + * @var array list of HTML attributes shared by all menu [[items]]. If any individual menu item
  79 + * specifies its `options`, it will be merged with this property before being used to generate the HTML
  80 + * attributes for the menu item tag. The following special options are recognized:
  81 + *
  82 + * - tag: string, defaults to "li", the tag name of the item container tags.
  83 + * Set to false to disable container tag.
  84 + * See also [[\yii\helpers\Html::tag()]].
  85 + *
  86 + * @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
  87 + */
  88 + public $itemOptions = [];
  89 + /**
  90 + * @var string the template used to render the body of a menu which is a link.
  91 + * In this template, the token `{url}` will be replaced with the corresponding link URL;
  92 + * while `{label}` will be replaced with the link text.
  93 + * This property will be overridden by the `template` option set in individual menu items via [[items]].
  94 + */
  95 + public $linkTemplate = '<a href="{url}">{label}</a>';
  96 + /**
  97 + * @var string the template used to render the body of a menu which is NOT a link.
  98 + * In this template, the token `{label}` will be replaced with the label of the menu item.
  99 + * This property will be overridden by the `template` option set in individual menu items via [[items]].
  100 + */
  101 + public $labelTemplate = '{label}';
  102 + /**
  103 + * @var string the template used to render a list of sub-menus.
  104 + * In this template, the token `{items}` will be replaced with the rendered sub-menu items.
  105 + */
  106 + public $submenuTemplate = "\n<ul>\n{items}\n</ul>\n";
  107 + /**
  108 + * @var boolean whether the labels for menu items should be HTML-encoded.
  109 + */
  110 + public $encodeLabels = true;
  111 + /**
  112 + * @var string the CSS class to be appended to the active menu item.
  113 + */
  114 + public $activeCssClass = 'active';
  115 + /**
  116 + * @var boolean whether to automatically activate items according to whether their route setting
  117 + * matches the currently requested route.
  118 + * @see isItemActive()
  119 + */
  120 + public $activateItems = true;
  121 + /**
  122 + * @var boolean whether to activate parent menu items when one of the corresponding child menu items is active.
  123 + * The activated parent menu items will also have its CSS classes appended with [[activeCssClass]].
  124 + */
  125 + public $activateParents = false;
  126 + /**
  127 + * @var boolean whether to hide empty menu items. An empty menu item is one whose `url` option is not
  128 + * set and which has no visible child menu items.
  129 + */
  130 + public $hideEmptyItems = true;
  131 + /**
  132 + * @var array the HTML attributes for the menu's container tag. The following special options are recognized:
  133 + *
  134 + * - tag: string, defaults to "ul", the tag name of the item container tags. Set to false to disable container tag.
  135 + * See also [[\yii\helpers\Html::tag()]].
  136 + *
  137 + * @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
  138 + */
  139 + public $options = [];
  140 + /**
  141 + * @var string the CSS class that will be assigned to the first item in the main menu or each submenu.
  142 + * Defaults to null, meaning no such CSS class will be assigned.
  143 + */
  144 + public $firstItemCssClass;
  145 + /**
  146 + * @var string the CSS class that will be assigned to the last item in the main menu or each submenu.
  147 + * Defaults to null, meaning no such CSS class will be assigned.
  148 + */
  149 + public $lastItemCssClass;
  150 + /**
  151 + * @var string the route used to determine if a menu item is active or not.
  152 + * If not set, it will use the route of the current request.
  153 + * @see params
  154 + * @see isItemActive()
  155 + */
  156 + public $route;
  157 + /**
  158 + * @var array the parameters used to determine if a menu item is active or not.
  159 + * If not set, it will use `$_GET`.
  160 + * @see route
  161 + * @see isItemActive()
  162 + */
  163 + public $params;
  164 +
  165 +
  166 + /**
  167 + * Renders the menu.
  168 + */
  169 + public function run()
  170 + {
  171 + if ($this->route === null && Yii::$app->controller !== null) {
  172 + $this->route = Yii::$app->controller->getRoute();
  173 + }
  174 + if ($this->params === null) {
  175 + $this->params = Yii::$app->request->getQueryParams();
  176 + }
  177 + $items = $this->normalizeItems($this->items, $hasActiveChild);
  178 + if (!empty($items)) {
  179 + $options = $this->options;
  180 + $tag = ArrayHelper::remove($options, 'tag', 'ul');
  181 +
  182 + echo Html::tag($tag, $this->renderItems($items), $options);
  183 + }
  184 + }
  185 +
  186 + /**
  187 + * Recursively renders the menu items (without the container tag).
  188 + * @param array $items the menu items to be rendered recursively
  189 + * @return string the rendering result
  190 + */
  191 + protected function renderItems($items)
  192 + {
  193 + $n = count($items);
  194 + $lines = [];
  195 + foreach ($items as $i => $item) {
  196 +
  197 + $options = array_merge($this->itemOptions, ArrayHelper::getValue($item, 'option
  198 +s', []));
  199 + $tag = ArrayHelper::remove($options, 'tag
  200 + print_r($tag);', 'li');
  201 + $class = [];
  202 + if ($item['active']) {
  203 + $class[] = $this->activeCssClass;
  204 + }
  205 + if ($i === 0 && $this->firstItemCssClass !== null) {
  206 + $class[] = $this->firstItemCssClass;
  207 + }
  208 + if ($i === $n - 1 && $this->lastItemCssClass !== null) {
  209 + $class[] = $this->lastItemCssClass;
  210 + }
  211 + if (!empty($class)) {
  212 + if (empty($options['class'])) {
  213 + $options['class'] = implode(' ', $class);
  214 + } else {
  215 + $options['class'] .= ' ' . implode(' ', $class);
  216 + }
  217 + }
  218 +
  219 + $menu = $this->renderItem($item);
  220 + if (!empty($item['items'])) {
  221 + $submenuTemplate = ArrayHelper::getValue($item, 'submenuTemplate', $this->submenuTemplate);
  222 + $menu .= strtr($submenuTemplate, [
  223 + '{items}' => $this->renderItems($item['items']),
  224 + ]);
  225 + }
  226 + $lines[] = Html::tag($tag, $menu, $options);
  227 + }
  228 +
  229 + return implode("\n", $lines);
  230 + }
  231 +
  232 + /**
  233 + * Renders the content of a menu item.
  234 + * Note that the container and the sub-menus are not rendered here.
  235 + * @param array $item the menu item to be rendered. Please refer to [[items]] to see what data might be in the item.
  236 + * @return string the rendering result
  237 + */
  238 + protected function renderItem($item)
  239 + {
  240 + if (isset($item['url'])) {
  241 + $template = ArrayHelper::getValue($item, 'template', $this->linkTemplate);
  242 +
  243 + return strtr($template, [
  244 + '{url}' => Html::encode(Url::to($item['url'])),
  245 + '{label}' => $item['label'],
  246 + ]);
  247 + } else {
  248 + $template = ArrayHelper::getValue($item, 'template', $this->labelTemplate);
  249 +
  250 + return strtr($template, [
  251 + '{label}' => $item['label'],
  252 + ]);
  253 + }
  254 + }
  255 +
  256 + /**
  257 + * Normalizes the [[items]] property to remove invisible items and activate certain items.
  258 + * @param array $items the items to be normalized.
  259 + * @param boolean $active whether there is an active child menu item.
  260 + * @return array the normalized menu items
  261 + */
  262 + protected function normalizeItems($items, &$active)
  263 + {
  264 + foreach ($items as $i => $item) {
  265 + if (isset($item['visible']) && !$item['visible']) {
  266 + unset($items[$i]);
  267 + continue;
  268 + }
  269 + if (!isset($item['label'])) {
  270 + $item['label'] = '';
  271 + }
  272 + $encodeLabel = isset($item['encode']) ? $item['encode'] : $this->encodeLabels;
  273 + $items[$i]['label'] = $encodeLabel ? Html::encode($item['label']) : $item['label'];
  274 + $hasActiveChild = false;
  275 + if (isset($item['items'])) {
  276 + $items[$i]['items'] = $this->normalizeItems($item['items'], $hasActiveChild);
  277 + if (empty($items[$i]['items']) && $this->hideEmptyItems) {
  278 + unset($items[$i]['items']);
  279 + if (!isset($item['url'])) {
  280 + unset($items[$i]);
  281 + continue;
  282 + }
  283 + }
  284 + }
  285 + if (!isset($item['active'])) {
  286 + if ($this->activateParents && $hasActiveChild || $this->activateItems && $this->isItemActive($item)) {
  287 + $active = $items[$i]['active'] = true;
  288 + } else {
  289 + $items[$i]['active'] = false;
  290 + }
  291 + } elseif ($item['active']) {
  292 + $active = true;
  293 + }
  294 + }
  295 +
  296 + return array_values($items);
  297 + }
  298 +
  299 + /**
  300 + * Checks whether a menu item is active.
  301 + * This is done by checking if [[route]] and [[params]] match that specified in the `url` option of the menu item.
  302 + * When the `url` option of a menu item is specified in terms of an array, its first element is treated
  303 + * as the route for the item and the rest of the elements are the associated parameters.
  304 + * Only when its route and parameters match [[route]] and [[params]], respectively, will a menu item
  305 + * be considered active.
  306 + * @param array $item the menu item to be checked
  307 + * @return boolean whether the menu item is active
  308 + */
  309 + protected function isItemActive($item)
  310 + {
  311 + if (isset($item['url']) && is_array($item['url']) && isset($item['url'][0])) {
  312 + $route = Yii::getAlias($item['url'][0]);
  313 + if ($route[0] !== '/' && Yii::$app->controller) {
  314 + $route = Yii::$app->controller->module->getUniqueId() . '/' . $route;
  315 + }
  316 + if (ltrim($route, '/') !== $this->route) {
  317 + return false;
  318 + }
  319 + unset($item['url']['#']);
  320 + if (count($item['url']) > 1) {
  321 + $params = $item['url'];
  322 + unset($params[0]);
  323 + foreach ($params as $name => $value) {
  324 + if ($value !== null && (!isset($this->params[$name]) || $this->params[$name] != $value)) {
  325 + return false;
  326 + }
  327 + }
  328 + }
  329 +
  330 + return true;
  331 + }
  332 +
  333 + return false;
  334 + }
  335 +}
... ...
frontend/widgets/FilterWidget.php
... ... @@ -9,8 +9,8 @@ class FilterWidget extends Widget
9 9 public $category;
10 10 public $groups;
11 11 public $filter;
12   - public $brands;
13 12 public $priceLimits;
  13 + public $filterWhitoutPrice;
14 14  
15 15  
16 16 public function init(){
... ... @@ -27,8 +27,7 @@ class FilterWidget extends Widget
27 27 'category'=>$this->category,
28 28 'groups'=>$this->groups,
29 29 'filter'=>$this->filter,
30   - 'brands'=>$this->brands,
31   - 'priceLimits'=>$this->priceLimits
  30 + 'priceLimits'=>$this->priceLimits,
32 31 ]);
33 32  
34 33 }
... ...
frontend/widgets/views/_filter_view.php
... ... @@ -2,6 +2,8 @@
2 2 use common\modules\product\helpers\FilterHelper;
3 3 use yii\helpers\Url;
4 4 use yii\web\View;
  5 +use frontend\widgets\FilterList;
  6 +
5 7  
6 8 ?>
7 9  
... ... @@ -23,36 +25,6 @@ use yii\web\View;
23 25  
24 26  
25 27 <div class="filterCat">
26   - <?php if ($brands) :?>
27   - <div class="properties_block closed">
28   -
29   - <div class="block_title"><i></i>Бренд</div>
30   -
31   - <ul class="chechboxes" style="display: none;">
32   - <?php foreach($brands as $brand) :
33   - $checked = !empty($filter['brands']) && in_array($brand->alias, $filter['brands']);
34   - //
35   - $option_url = Url::to(['catalog/category', 'category' => $category, 'filters' => FilterHelper::getFilterForOption($filter, 'brands', $brand->alias, $checked)]);
36   - ?>
37   - <li>
38   -
39   - <input type="checkbox" onchange="document.location='<?= $option_url?>'" class="brands-option" <?= $checked ? ' checked' : ''?> />
40   - <div>
41   - <label for="filter">
42   - <a href="<?= $option_url?>"><?= $brand->name?></a>
43   - </label>
44   - </div>
45   - <div class="clearfix"></div>
46   -
47   -
48   -
49   -
50   - </li>
51   - <?php endforeach?>
52   - </ul>
53   -
54   - </div>
55   - <?php endif?>
56 28 <?php foreach($groups as $group_name => $group) :?>
57 29 <div class="properties_block closed">
58 30  
... ... @@ -63,15 +35,14 @@ use yii\web\View;
63 35 $checked = (isset($filter[$option['group_alias']]) && in_array($option['option_alias'], $filter[$option['group_alias']]));
64 36 $option_url = Url::to(['catalog/category', 'category' => $category, 'filters' => FilterHelper::getFilterForOption($filter, $option['group_alias'], $option['option_alias'], $checked)]);
65 37 ?>
66   - <li>
  38 + <li data-checked="<?= $checked ? ' true' : 'false'?>" data-filter='<?= isset($option['cacheKey'])?$option['cacheKey']:'' ?>'>
67 39  
68   - <input type="checkbox" onchange="document.location='<?= $option_url?>'" class="features-option" <?= $checked ? ' checked' : ''?> />
  40 + <input type="checkbox" id="<?= $option['tax_option_id']?>" onchange='<?=$option_url ?>' class="features-option" <?= $checked ? ' checked' : ''?> />
69 41 <div>
70   - <label for="filter3278">
71   - <a href="<?= $option_url?>"><?= $option['value']?></a>
  42 + <label for="#<?= $option['tax_option_id']?>">
  43 + <a class="filter-link" href="<?= $option_url?>"><?= $option['value']?> <span></span></a>
72 44 </label>
73 45 </div>
74   - <div class="clearfix"></div>
75 46  
76 47 </li>
77 48 <?php endforeach?>
... ... @@ -82,8 +53,22 @@ use yii\web\View;
82 53 </div>
83 54 <?php endforeach?>
84 55  
85   - <?php if ($priceLimits['min'] < $priceLimits['max']) :?>
86   - <div class="properties_block">
  56 + <?php if ($priceLimits['min'] < $priceLimits['max']) :
  57 +
  58 + $filterWhitoutPrice = $filter;
  59 + $filterWhitoutPrice['prices'] = [
  60 + 'min' => '{from}',
  61 + 'max' => '{to}',
  62 + ];
  63 +
  64 + ?>
  65 + <div id="price_block" class="properties_block"
  66 + data-min="<?=$priceLimits['min']?>"
  67 + data-max="<?=$priceLimits['max']?>"
  68 + data-from="<?=((isset($filter['prices']) && !empty($filter['prices']['min'])) ? $filter['prices']['min'] : $priceLimits['min'])?>"
  69 + data-to="<?=(( isset($filter['prices']) && !empty($filter['prices']['max'])) ? $filter['prices']['max'] : $priceLimits['max'])?>"
  70 + data-url="<?= Url::to(['catalog/category','category' => $category,'filters' => $filterWhitoutPrice])?>"
  71 + >
87 72 <div class="block_title"><i></i>Цена</div>
88 73 <div class="price_filter first_price_li">
89 74 <div class="price_slider">
... ... @@ -99,120 +84,11 @@ use yii\web\View;
99 84  
100 85 </div>
101 86  
102   -
103   -
104   -
105   -
106 87 </div>
107 88  
108 89 </div>
109 90  
110 91 </div>
111 92  
112   -<?php
113   -
114   -$js = "
115   -
116   -
117   -
118   - $('.properties_block').each(function(){
119   - var block = $(this);
120   - $(this).find('input[type=checkbox]').each(function(){
121   - if(this.checked){
122   - block.removeClass('closed').addClass('opened');
123   - block.find('ul').css({\"display\":\"block\"})
124   - return true;
125   - }
126   -
127   - });
128   -
129   - });
130   -
131   - $('#finput').keyup(function() {
132   -
133   - var empty = false;
134   - $('#finput').each(function() {
135   - if ($(this).val() == '') {
136   - empty = true;
137   - }
138   - });
139   -
140   - if (empty) {
141   - $('.sok').attr('disabled', 'disabled').css('display','none');
142   - } else {
143   - $('.sok').removeAttr('disabled').css('display','inline-block');
144   - }
145   -
146   - });
147   -
148   -
149   -
150   -
151   -
152   -
153   - $('.price_tooltip_close').on('click',function(){
154   - $(this).parent().hide();
155   - });
156   -
157   - $('.pok').click(function(event) {
158   - url = $('#purl').val();
159   - price_min = $('#min_price').val();
160   - price_max = $('#max_price').val();
161   -
162   - document.location.href = url + \"&pmin=\" + price_min + \"&pmax=\" + price_max;
163   - });
164   -
165   - $('.sok').click(function(event) {
166   - if ($('#finput').val() != \"Артикул\" && $('#finput').val() != \"\") {
167   -
168   -
169   - document.location.href = \"/search/main?word=\"+$('#finput').val();
170   -
171   -
172   - }
173   - });
174   -
175   - ";
176   - $this->registerJs($js,
177   - View::POS_LOAD
178   - );
179   -
180   -
181   - if ($priceLimits['min'] < $priceLimits['max']){
182   -
183   - $filterWhitoutPrice = $filter;
184   - $filterWhitoutPrice['prices'] = [
185   - 'min' => '{from}',
186   - 'max' => '{to}',
187   - ];
188   -
189   - $js = "
190   -
191   -
192   -
193   - $('#price_interval').ionRangeSlider({
194   - type: 'double',
195   - min: {$priceLimits['min']},
196   - max: {$priceLimits['max']},
197   - from: ".((isset($filter['prices']) && !empty($filter['prices']['min'])) ? $filter['prices']['min'] : $priceLimits['min']) .",
198   - to: ". ((isset($filter['prices']) && !empty($filter['prices']['max'])) ? $filter['prices']['max'] : $priceLimits['max']) .",
199   - grid: false,
200   - onFinish: function(e) {
201   - var url = '" . Url::to([
202   - 'catalog/category',
203   - 'category' => $category,
204   - 'filters' => $filterWhitoutPrice
205   - ])."';
206   - var from = e.from;
207   - var to = e.to;
208   - document.location = url.replace('{from}', from).replace('{to}', to);
209   - }
210   - });
211 93  
212   - ";
213   - $this->registerJs($js,
214   - View::POS_READY
215   - );
216   - }
217   - ?>
218 94  
... ...