Exemple #1
0
 public function init()
 {
     parent::init();
     $this->languages_codeToName = ArrayHelper::map(Language::find()->all(), 'code', 'name');
     $this->languages_idToName = ArrayHelper::map(Language::find()->all(), 'id', 'name');
     $this->currencies_idToName = ArrayHelper::map(Currency::find()->all(), 'id', 'name');
     $this->parent_productCategories_idToSlug = ArrayHelper::map(ProductCategory::find()->where(['parent_id' => null])->all(), 'id', 'slug');
     foreach ($this->parent_productCategories_idToSlug as $id => $slug) {
         $this->productCategories_idToSlug[$slug] = ArrayHelper::map(ProductCategory::find()->where(['parent_id' => $id])->all(), 'id', 'slug');
     }
     is_array($this->productCategories_idToSlug) or $this->productCategories_idToSlug = array();
     $this->productCollections_idToSlug = ArrayHelper::map(ProductCollection::find()->all(), 'id', 'slug');
     I18n::$currency_params = ['exchange_rate' => 1, 'prefix' => '', 'suffix' => 'đ', 'thousand_separator' => '.', 'decimal_point' => ',', 'number_digits_after_decimal_point' => 0];
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = ProductCollection::find();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['id' => SORT_DESC]]]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'is_active' => $this->is_active, 'is_hot' => $this->is_hot, 'position' => $this->position]);
     $query->andFilterWhere(['like', 'slug', $this->slug])->andFilterWhere(['like', 'old_slugs', $this->old_slugs])->andFilterWhere(['like', 'image_path', $this->image_path])->andFilterWhere(['like', 'image', $this->image])->andFilterWhere(['like', 'banner', $this->banner])->andFilterWhere(['like', 'created_by', $this->created_by])->andFilterWhere(['like', 'updated_by', $this->updated_by]);
     return $dataProvider;
 }