'Category ID', 'brand_id' => 'Brand ID', 'product_name' => 'Product name', 'variant_count' => 'Variant count', ]; return array_merge($labels, $new_labels); } /** * @inheritdoc */ public function scenarios() { // bypass scenarios() implementation in the parent class return Model::scenarios(); } /** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Product::find(); $query->select([ 'product.*', 'COUNT(product_variant.product_variant_id) as count', ]); $query->joinWith([ 'categories', 'lang', ]) ->joinWith([ 'brand' => function($query) { /** * @var ActiveQuery $query */ $query->joinWith('lang'); }, ]) ->joinWith('variants'); $query->groupBy([ 'product.product_id', 'brand_lang.name', 'product_lang.name', ]); $dataProvider = new ActiveDataProvider([ 'query' => $query, ]); $dataProvider->setSort([ 'attributes' => [ 'product_id', 'product_name' => [ 'asc' => [ 'product_lang.name' => SORT_ASC ], 'desc' => [ 'product_lang.name' => SORT_DESC ], ], 'brand_id' => [ 'asc' => [ 'brand_lang.name' => SORT_ASC ], 'desc' => [ 'brand_lang.name' => SORT_DESC ], 'default' => SORT_DESC, ], 'variant_count' => [ 'asc' => [ 'count' => SORT_ASC ], 'desc' => [ 'count' => SORT_DESC ], ], ], ]); $this->load($params); if(isset( $this->is_top )) { $query->andWhere([ 'is_top' => (bool) $this->is_top, ]); } if(isset( $this->is_new )) { $query->andWhere([ 'is_new' => (bool) $this->is_new, ]); } if(isset( $this->akciya )) { $query->andWhere([ 'akciya' => (bool) $this->akciya, ]); } $query->andFilterWhere([ 'product.brand_id' => $this->brand_id, 'product.product_id' => $this->product_id, 'product_category.category_id' => $this->category_id, ]); $query->andFilterWhere([ 'like', 'product_lang.name', $this->product_name, ]); return $dataProvider; } }