Commit db2894a2ae5e58489411f17288ff733b43a270cc

Authored by Administrator
1 parent ec07777f

big commti

common/modules/product/helpers/ProductHelper.php
@@ -249,21 +249,21 @@ @@ -249,21 +249,21 @@
249 $query->andWhere( 249 $query->andWhere(
250 Product::tableName() . '.product_id IN ( 250 Product::tableName() . '.product_id IN (
251 SELECT DISTINCT products 251 SELECT DISTINCT products
252 - FROM (  
253 - SELECT product_id AS products FROM product WHERE product_id IN(  
254 - SELECT product_id FROM product_option  
255 - INNER JOIN tax_option ON tax_option.tax_option_id = product_option.option_id  
256 - INNER JOIN tax_group ON tax_group.tax_group_id = tax_option.tax_group_id  
257 - WHERE tax_group.alias LIKE \''. $key .'\' AND tax_option.alias IN (\'' . implode('\',\'', $param) . '\'))  
258 - OR product_id IN (  
259 - (SELECT product_id AS products  
260 - FROM product_variant_option  
261 - INNER JOIN product_variant ON product_variant_option.product_variant_id = product_variant.product_variant_id  
262 - INNER JOIN tax_option ON tax_option.tax_option_id = product_variant_option.option_id  
263 - INNER JOIN tax_group ON tax_group.tax_group_id = tax_option.tax_group_id  
264 - WHERE tax_group.alias LIKE \''. $key .'\' AND tax_option.alias IN (\'' . implode('\',\'', $param) . '\'))  
265 - )  
266 - ) AS table_name 252 + FROM (
  253 + SELECT product_id AS products FROM product WHERE product_id IN(
  254 + SELECT product_id FROM product_option
  255 + INNER JOIN tax_option ON tax_option.tax_option_id = product_option.option_id
  256 + INNER JOIN tax_group ON tax_group.tax_group_id = tax_option.tax_group_id
  257 + WHERE tax_group.alias LIKE \''. $key .'\' AND tax_option.alias IN (\'' . implode('\',\'', $param) . '\'))
  258 + OR product_id IN (
  259 + (SELECT product_id AS products
  260 + FROM product_variant_option
  261 + INNER JOIN product_variant ON product_variant_option.product_variant_id = product_variant.product_variant_id
  262 + INNER JOIN tax_option ON tax_option.tax_option_id = product_variant_option.option_id
  263 + INNER JOIN tax_group ON tax_group.tax_group_id = tax_option.tax_group_id
  264 + WHERE tax_group.alias LIKE \''. $key .'\' AND tax_option.alias IN (\'' . implode('\',\'', $param) . '\'))
  265 + )
  266 + ) AS table_name
267 )' 267 )'
268 ); 268 );
269 } 269 }
common/modules/product/models/Category.php
@@ -125,7 +125,6 @@ class Category extends \yii\db\ActiveRecord @@ -125,7 +125,6 @@ class Category extends \yii\db\ActiveRecord
125 public function getProducts() { 125 public function getProducts() {
126 return $this->hasMany(Product::className(), ['product_id' => 'product_id']) 126 return $this->hasMany(Product::className(), ['product_id' => 'product_id'])
127 ->viaTable('product_category', ['category_id' => 'category_id']); 127 ->viaTable('product_category', ['category_id' => 'category_id']);
128 -// return $this->getRelations('product_categories');  
129 } 128 }
130 129
131 130
common/modules/product/models/Product.php
@@ -177,6 +177,14 @@ class Product extends \yii\db\ActiveRecord @@ -177,6 +177,14 @@ class Product extends \yii\db\ActiveRecord
177 /** 177 /**
178 * @return \yii\db\ActiveQuery 178 * @return \yii\db\ActiveQuery
179 */ 179 */
  180 + public function getVariants()
  181 + {
  182 + return $this->hasMany(ProductVariant::className(), ['product_id' => 'product_id']);
  183 + }
  184 +
  185 + /**
  186 + * @return \yii\db\ActiveQuery
  187 + */
180 public function getEnabledVariant() 188 public function getEnabledVariant()
181 { 189 {
182 return $this->hasOne(ProductVariant::className(), ['product_id' => 'product_id']) 190 return $this->hasOne(ProductVariant::className(), ['product_id' => 'product_id'])
@@ -191,13 +199,7 @@ class Product extends \yii\db\ActiveRecord @@ -191,13 +199,7 @@ class Product extends \yii\db\ActiveRecord
191 return $this->enabledVariants[0]->price; 199 return $this->enabledVariants[0]->price;
192 } 200 }
193 201
194 - /**  
195 - * @return \yii\db\ActiveQuery  
196 - */  
197 - public function getVariants()  
198 - {  
199 - return $this->hasMany(ProductVariant::className(), ['product_id' => 'product_id']);  
200 - } 202 +
201 203
202 public function getEnabledVariants() 204 public function getEnabledVariants()
203 { 205 {
@@ -298,7 +300,7 @@ class Product extends \yii\db\ActiveRecord @@ -298,7 +300,7 @@ class Product extends \yii\db\ActiveRecord
298 $groups[] = $group; 300 $groups[] = $group;
299 } 301 }
300 } 302 }
301 - Yii::$app->cache->set($cacheKey,$groups); 303 + Yii::$app->cache->set($cacheKey,$groups,3600*24);
302 } 304 }
303 305
304 return $groups; 306 return $groups;
common/modules/product/models/ProductVariant.php
@@ -227,7 +227,7 @@ class ProductVariant extends \yii\db\ActiveRecord @@ -227,7 +227,7 @@ class ProductVariant extends \yii\db\ActiveRecord
227 } 227 }
228 return $groups; 228 return $groups;
229 } 229 }
230 - 230 +
231 231
232 public function getId(){ 232 public function getId(){
233 return $this->product_variant_id; 233 return $this->product_variant_id;
frontend/controllers/CatalogController.php
@@ -118,7 +118,8 @@ class CatalogController extends \yii\web\Controller @@ -118,7 +118,8 @@ class CatalogController extends \yii\web\Controller
118 118
119 $groups = $category->getActiveFilters(); 119 $groups = $category->getActiveFilters();
120 $groups = ArrayHelper::index($groups, null, 'name'); 120 $groups = ArrayHelper::index($groups, null, 'name');
121 - $priceLimits = $productModel->priceLimits($category, $params); 121 +
  122 + $priceLimits = $productModel->priceLimits($productProvider->query);
122 123
123 /* 124 /*
124 * Greedy search for comments and rating 125 * Greedy search for comments and rating
frontend/controllers/EventController.php
@@ -31,8 +31,16 @@ class EventController extends Controller @@ -31,8 +31,16 @@ class EventController extends Controller
31 31
32 $model = $this->findModel($alias); 32 $model = $this->findModel($alias);
33 $productProvider = new ActiveDataProvider([ 33 $productProvider = new ActiveDataProvider([
34 - 'query' => $model->getProducts(), 34 + 'query' => $model->getProducts()->with([
  35 + 'images',
  36 + 'events',
  37 + 'variant',
  38 + 'variant.image',
  39 + 'comments',
  40 + 'averageRating',
  41 + ]),
35 ]); 42 ]);
  43 +
36 return $this->render('show', [ 44 return $this->render('show', [
37 'productProvider' => $productProvider, 45 'productProvider' => $productProvider,
38 'model' => $model, 46 'model' => $model,
@@ -43,9 +51,18 @@ class EventController extends Controller @@ -43,9 +51,18 @@ class EventController extends Controller
43 { 51 {
44 52
45 $model = Event::find()->where(['percent'=>$percent])->one(); 53 $model = Event::find()->where(['percent'=>$percent])->one();
  54 +
46 $productProvider = new ActiveDataProvider([ 55 $productProvider = new ActiveDataProvider([
47 - 'query' => $model->getProducts(), 56 + 'query' => $model->getProducts()->with([
  57 + 'images',
  58 + 'events',
  59 + 'variant',
  60 + 'variant.image',
  61 + 'comments',
  62 + 'averageRating',
  63 + ]),
48 ]); 64 ]);
  65 +
49 return $this->render('show', [ 66 return $this->render('show', [
50 'productProvider' => $productProvider, 67 'productProvider' => $productProvider,
51 'model' => $model, 68 'model' => $model,
frontend/models/ProductFrontendSearch.php
@@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
3 namespace frontend\models; 3 namespace frontend\models;
4 4
5 use common\modules\product\helpers\ProductHelper; 5 use common\modules\product\helpers\ProductHelper;
  6 +use common\modules\product\models\Category;
6 use common\modules\product\models\ProductCategory; 7 use common\modules\product\models\ProductCategory;
7 use common\modules\product\models\ProductOption; 8 use common\modules\product\models\ProductOption;
8 use common\modules\rubrication\models\TaxGroup; 9 use common\modules\rubrication\models\TaxGroup;
@@ -85,7 +86,7 @@ class ProductFrontendSearch extends Product { @@ -85,7 +86,7 @@ class ProductFrontendSearch extends Product {
85 public function getSearchQuery($category = null, $params = [], $in_stock = true) { 86 public function getSearchQuery($category = null, $params = [], $in_stock = true) {
86 if (!empty($category)) { 87 if (!empty($category)) {
87 /** @var ActiveQuery $query */ 88 /** @var ActiveQuery $query */
88 -// $query = $category->getRelations('product_categories'); 89 + /**@var Category $category **/
89 $query = $category->getProducts(); 90 $query = $category->getProducts();
90 } else { 91 } else {
91 $query = Product::find(); 92 $query = Product::find();
@@ -105,25 +106,7 @@ class ProductFrontendSearch extends Product { @@ -105,25 +106,7 @@ class ProductFrontendSearch extends Product {
105 } 106 }
106 107
107 108
108 - public function priceLimits($category = null, $params = []) {  
109 - if (!empty($category)) {  
110 - /** @var ActiveQuery $query */  
111 -// $query = $category->getRelations('product_categories');  
112 - $query = $category->getProducts();  
113 - } else {  
114 - $query = Product::find();  
115 - }  
116 - $query->joinWith('variant');  
117 -  
118 - // Price filter fix  
119 - unset($params['prices']);  
120 -  
121 - ProductHelper::_setQueryParams($query, $params, false);  
122 -  
123 -// $query->select([  
124 -// 'MIN('. ProductVariant::tableName() .'.price) AS priceMIN',  
125 -// 'MAX('. ProductVariant::tableName() .'.price) AS priceMAX',  
126 -// ]); 109 + public function priceLimits($query) {
127 110
128 return [ 111 return [
129 'min' => $query->min(ProductVariant::tableName() .'.price'), 112 'min' => $query->min(ProductVariant::tableName() .'.price'),