public function init() { $cacheKey = 'priceRangeCategory' . $this->categoryId; if (!($data = Yii::$app->cache->get($cacheKey))) { $data = (new Query())->select('MIN(product.price) as min_price, MAX(product.price) as max_price')->from(['product', 'product_category'])->where('product.id = product_category.object_model_id')->andWhere(['product.active' => 1, 'product_category.category_id' => $this->categoryId])->one(); if ($data) { Yii::$app->cache->set($cacheKey, $data, 86400); } } if ($data && isset($data['min_price']) && isset($data['max_price'])) { $this->minValue = $data['min_price']; $this->maxValue = $data['max_price']; $get = ArrayHelper::merge(Yii::$app->request->get(), Yii::$app->request->post()); if (isset($get[$this->minAttribute]) && is_numeric($get[$this->minAttribute])) { $this->changeFlagDefaultValue = 1; $this->minValueNow = $get[$this->minAttribute]; } else { $this->minValueNow = $this->minValue; } if (isset($get[$this->maxAttribute]) && is_numeric($get[$this->maxAttribute])) { $this->changeFlagDefaultValue = 1; $this->maxValueNow = $get[$this->maxAttribute]; } else { $this->maxValueNow = $this->maxValue; } } return parent::init(); }
public function run() { $this->attributeName = $this->property->name; $this->minAttribute = 'minValue[' . $this->property->id . ']'; $this->maxAttribute = 'maxValue[' . $this->property->id . ']'; $this->changeFlagAttribute = 'changeValue[' . $this->property->id . ']'; $get = ArrayHelper::merge(Yii::$app->request->get(), Yii::$app->request->post()); if ($this->selects) { $this->minValue = (int) array_values($this->selects)[0]['value']; $this->maxValue = (int) array_values($this->selects)[0]['value']; foreach ($this->selects as $select) { $select['value'] = (int) $select['value']; $this->minValue = $select['value'] < $this->minValue ? $select['value'] : $this->minValue; $this->maxValue = $select['value'] > $this->maxValue ? $select['value'] : $this->maxValue; } if (isset($get[$this->minAttribute]) && is_numeric($get[$this->minAttribute])) { $this->changeFlagDefaultValue = 1; $this->minValueNow = $get[$this->minAttribute]; } else { $this->minValueNow = $this->minValue; } if (isset($get[$this->maxAttribute]) && is_numeric($get[$this->maxAttribute])) { $this->changeFlagDefaultValue = 1; $this->maxValueNow = $get[$this->maxAttribute]; } else { $this->maxValueNow = $this->maxValue; } } return parent::run(); }
public function run() { $this->minValue = (int) $this->minValue; $this->maxValue = (int) $this->maxValue; $this->attributeName = $this->property->name; $this->minAttribute = 'minValue[' . $this->property->id . ']'; $this->maxAttribute = 'maxValue[' . $this->property->id . ']'; $this->changeFlagAttribute = 'changeValue[' . $this->property->id . ']'; $get = ArrayHelper::merge(Yii::$app->request->get(), Yii::$app->request->post()); if (isset($get['minValue']) && isset($get['minValue'][$this->property->id]) && is_numeric($get['minValue'][$this->property->id]) && $this->minValue !== (int) $get['minValue'][$this->property->id]) { $this->changeFlagDefaultValue = 1; $this->minValueNow = (int) $get['minValue'][$this->property->id]; } else { $this->minValueNow = $this->minValue; } if (isset($get['maxValue']) && isset($get['maxValue'][$this->property->id]) && is_numeric($get['maxValue'][$this->property->id]) && $this->maxValue !== (int) $get['maxValue'][$this->property->id]) { $this->changeFlagDefaultValue = 1; $this->maxValueNow = (int) $get['maxValue'][$this->property->id]; } else { $this->maxValueNow = $this->maxValue; } return parent::run(); }