diff --git a/common/modules/product/helpers/ProductHelper.php b/common/modules/product/helpers/ProductHelper.php index 88c2b78..8e20a9d 100755 --- a/common/modules/product/helpers/ProductHelper.php +++ b/common/modules/product/helpers/ProductHelper.php @@ -249,21 +249,21 @@ $query->andWhere( Product::tableName() . '.product_id IN ( SELECT DISTINCT products - FROM ( - SELECT product_id AS products FROM product WHERE product_id IN( - SELECT product_id FROM product_option - INNER JOIN tax_option ON tax_option.tax_option_id = product_option.option_id - INNER JOIN tax_group ON tax_group.tax_group_id = tax_option.tax_group_id - WHERE tax_group.alias LIKE \''. $key .'\' AND tax_option.alias IN (\'' . implode('\',\'', $param) . '\')) - OR product_id IN ( - (SELECT product_id AS products - FROM product_variant_option - INNER JOIN product_variant ON product_variant_option.product_variant_id = product_variant.product_variant_id - INNER JOIN tax_option ON tax_option.tax_option_id = product_variant_option.option_id - INNER JOIN tax_group ON tax_group.tax_group_id = tax_option.tax_group_id - WHERE tax_group.alias LIKE \''. $key .'\' AND tax_option.alias IN (\'' . implode('\',\'', $param) . '\')) - ) - ) AS table_name + FROM ( + SELECT product_id AS products FROM product WHERE product_id IN( + SELECT product_id FROM product_option + INNER JOIN tax_option ON tax_option.tax_option_id = product_option.option_id + INNER JOIN tax_group ON tax_group.tax_group_id = tax_option.tax_group_id + WHERE tax_group.alias LIKE \''. $key .'\' AND tax_option.alias IN (\'' . implode('\',\'', $param) . '\')) + OR product_id IN ( + (SELECT product_id AS products + FROM product_variant_option + INNER JOIN product_variant ON product_variant_option.product_variant_id = product_variant.product_variant_id + INNER JOIN tax_option ON tax_option.tax_option_id = product_variant_option.option_id + INNER JOIN tax_group ON tax_group.tax_group_id = tax_option.tax_group_id + WHERE tax_group.alias LIKE \''. $key .'\' AND tax_option.alias IN (\'' . implode('\',\'', $param) . '\')) + ) + ) AS table_name )' ); } diff --git a/common/modules/product/models/Category.php b/common/modules/product/models/Category.php index 0927402..b314863 100755 --- a/common/modules/product/models/Category.php +++ b/common/modules/product/models/Category.php @@ -125,7 +125,6 @@ class Category extends \yii\db\ActiveRecord public function getProducts() { return $this->hasMany(Product::className(), ['product_id' => 'product_id']) ->viaTable('product_category', ['category_id' => 'category_id']); -// return $this->getRelations('product_categories'); } diff --git a/common/modules/product/models/Product.php b/common/modules/product/models/Product.php index b80d437..7690c3c 100755 --- a/common/modules/product/models/Product.php +++ b/common/modules/product/models/Product.php @@ -177,6 +177,14 @@ class Product extends \yii\db\ActiveRecord /** * @return \yii\db\ActiveQuery */ + public function getVariants() + { + return $this->hasMany(ProductVariant::className(), ['product_id' => 'product_id']); + } + + /** + * @return \yii\db\ActiveQuery + */ public function getEnabledVariant() { return $this->hasOne(ProductVariant::className(), ['product_id' => 'product_id']) @@ -191,13 +199,7 @@ class Product extends \yii\db\ActiveRecord return $this->enabledVariants[0]->price; } - /** - * @return \yii\db\ActiveQuery - */ - public function getVariants() - { - return $this->hasMany(ProductVariant::className(), ['product_id' => 'product_id']); - } + public function getEnabledVariants() { @@ -298,7 +300,7 @@ class Product extends \yii\db\ActiveRecord $groups[] = $group; } } - Yii::$app->cache->set($cacheKey,$groups); + Yii::$app->cache->set($cacheKey,$groups,3600*24); } return $groups; diff --git a/common/modules/product/models/ProductVariant.php b/common/modules/product/models/ProductVariant.php index cc7343c..0c09604 100755 --- a/common/modules/product/models/ProductVariant.php +++ b/common/modules/product/models/ProductVariant.php @@ -227,7 +227,7 @@ class ProductVariant extends \yii\db\ActiveRecord } return $groups; } - + public function getId(){ return $this->product_variant_id; diff --git a/frontend/controllers/CatalogController.php b/frontend/controllers/CatalogController.php index f1440e3..1e21f05 100755 --- a/frontend/controllers/CatalogController.php +++ b/frontend/controllers/CatalogController.php @@ -118,7 +118,8 @@ class CatalogController extends \yii\web\Controller $groups = $category->getActiveFilters(); $groups = ArrayHelper::index($groups, null, 'name'); - $priceLimits = $productModel->priceLimits($category, $params); + + $priceLimits = $productModel->priceLimits($productProvider->query); /* * Greedy search for comments and rating diff --git a/frontend/controllers/EventController.php b/frontend/controllers/EventController.php index 2084723..5d9f0ea 100755 --- a/frontend/controllers/EventController.php +++ b/frontend/controllers/EventController.php @@ -31,8 +31,16 @@ class EventController extends Controller $model = $this->findModel($alias); $productProvider = new ActiveDataProvider([ - 'query' => $model->getProducts(), + 'query' => $model->getProducts()->with([ + 'images', + 'events', + 'variant', + 'variant.image', + 'comments', + 'averageRating', + ]), ]); + return $this->render('show', [ 'productProvider' => $productProvider, 'model' => $model, @@ -43,9 +51,18 @@ class EventController extends Controller { $model = Event::find()->where(['percent'=>$percent])->one(); + $productProvider = new ActiveDataProvider([ - 'query' => $model->getProducts(), + 'query' => $model->getProducts()->with([ + 'images', + 'events', + 'variant', + 'variant.image', + 'comments', + 'averageRating', + ]), ]); + return $this->render('show', [ 'productProvider' => $productProvider, 'model' => $model, diff --git a/frontend/models/ProductFrontendSearch.php b/frontend/models/ProductFrontendSearch.php index 6f56087..7793ce7 100755 --- a/frontend/models/ProductFrontendSearch.php +++ b/frontend/models/ProductFrontendSearch.php @@ -3,6 +3,7 @@ namespace frontend\models; use common\modules\product\helpers\ProductHelper; +use common\modules\product\models\Category; use common\modules\product\models\ProductCategory; use common\modules\product\models\ProductOption; use common\modules\rubrication\models\TaxGroup; @@ -85,7 +86,7 @@ class ProductFrontendSearch extends Product { public function getSearchQuery($category = null, $params = [], $in_stock = true) { if (!empty($category)) { /** @var ActiveQuery $query */ -// $query = $category->getRelations('product_categories'); + /**@var Category $category **/ $query = $category->getProducts(); } else { $query = Product::find(); @@ -105,25 +106,7 @@ class ProductFrontendSearch extends Product { } - public function priceLimits($category = null, $params = []) { - if (!empty($category)) { - /** @var ActiveQuery $query */ -// $query = $category->getRelations('product_categories'); - $query = $category->getProducts(); - } else { - $query = Product::find(); - } - $query->joinWith('variant'); - - // Price filter fix - unset($params['prices']); - - ProductHelper::_setQueryParams($query, $params, false); - -// $query->select([ -// 'MIN('. ProductVariant::tableName() .'.price) AS priceMIN', -// 'MAX('. ProductVariant::tableName() .'.price) AS priceMAX', -// ]); + public function priceLimits($query) { return [ 'min' => $query->min(ProductVariant::tableName() .'.price'), -- libgit2 0.21.4