$this->getSearchQuery($category, $params, $in_stock) ->all(), 'pagination' => [ 'pageSize' => 10, ], 'sort' => [ 'attributes' => [ 'name_asc' => [ 'asc' => [ 'name' => SORT_ASC ], 'desc' => [ 'name' => SORT_ASC ], 'default' => SORT_ASC, 'label' => 'имени от А до Я', ], 'name_desc' => [ 'asc' => [ 'name' => SORT_DESC ], 'desc' => [ 'name' => SORT_DESC ], 'default' => SORT_DESC, 'label' => 'имени от Я до А', ], 'price' => [ 'asc' => [ 'price' => SORT_ASC ], 'desc' => [ 'price' => SORT_DESC ], 'default' => SORT_DESC, 'label' => 'по цене', ], ], ], ] ); return $dataProvider; } public function getSearchQuery($category = null, $params = [], $in_stock = true) { if (!empty( $category )) { /** @var ActiveQuery $query */ /**@var Category $category * */ $query = $category->getProducts(); } else { $query = Product::find(); } $query->select([ 'product.*' ]); $query->joinWith( [ 'lang', 'brand.lang', 'options', ] ) ->innerJoinWith( [ 'enabledVariants' => function ($query) { /** * @var ActiveQuery $query */ $query->joinWith('lang') ->with('images'); }, ] ); $query->groupBy( [ 'product.id', 'product_variant.price', ] ); FilterHelper::setQueryParams($query, $params); if ($in_stock) { $query->andWhere( [ '>=', ProductVariant::tableName() . '.stock', 1, ] ); } return $query; } /** * @param Category|null $category * * @return array */ public function priceLimits($category = null) { if (!empty( $category )) { /** @var ActiveQuery $query */ $query = $category->getProducts(); } else { $query = Product::find(); } $query->joinWith('variant'); return [ 'min' => $query->min(ProductVariant::tableName() . '.price'), 'max' => $query->max(ProductVariant::tableName() . '.price'), ]; } }