Commit a22144fac44fab81d54532801cc8641a7fd49db9
1 parent
8a7d402e
20.07.16
Showing
2 changed files
with
26 additions
and
26 deletions
Show diff stats
common/modules/product/helpers/ProductHelper.php
1 | 1 | <?php |
2 | - | |
2 | + | |
3 | 3 | namespace common\modules\product\helpers; |
4 | - | |
4 | + | |
5 | 5 | use common\modules\product\models\Brand; |
6 | 6 | use common\modules\product\models\Category; |
7 | 7 | use common\modules\product\models\Product; |
... | ... | @@ -11,28 +11,28 @@ |
11 | 11 | use yii\base\Object; |
12 | 12 | use Yii; |
13 | 13 | use yii\db\ActiveQuery; |
14 | - | |
14 | + | |
15 | 15 | class ProductHelper extends Object |
16 | 16 | { |
17 | - | |
17 | + | |
18 | 18 | const PRODUCT_TAX_GROUP_ID_TARGET = 20; |
19 | 19 | const PRODUCT_TAX_GROUP_ID_YEAR = 21; |
20 | 20 | const PRODUCT_TAX_GROUP_ID_SEX = 22; |
21 | - | |
21 | + | |
22 | 22 | const PRODUCT_VARIANT_TYPE_COLOR = 1; |
23 | 23 | const PRODUCT_VARIANT_TYPE_SIZE = 2; |
24 | - | |
24 | + | |
25 | 25 | public static function getCategories() |
26 | 26 | { |
27 | 27 | return Category::find() |
28 | 28 | ->getTree(); // with('categoryName')-> |
29 | 29 | } |
30 | - | |
30 | + | |
31 | 31 | public static function getBrands() |
32 | 32 | { |
33 | 33 | return Brand::find(); // ->with('brandName') |
34 | 34 | } |
35 | - | |
35 | + | |
36 | 36 | /* |
37 | 37 | * Return custom filter-option link |
38 | 38 | * @var array $filter |
... | ... | @@ -74,7 +74,7 @@ |
74 | 74 | } |
75 | 75 | return $result; |
76 | 76 | } |
77 | - | |
77 | + | |
78 | 78 | public static function addLastProsucts($product_id) |
79 | 79 | { |
80 | 80 | $last_products = self::getLastProducts(); |
... | ... | @@ -86,7 +86,7 @@ |
86 | 86 | Yii::$app->session->set('last_products', $last_products); |
87 | 87 | } |
88 | 88 | } |
89 | - | |
89 | + | |
90 | 90 | public static function getLastProducts($as_object = false) |
91 | 91 | { |
92 | 92 | $last_products = Yii::$app->session->get('last_products', [ ]); |
... | ... | @@ -103,7 +103,7 @@ |
103 | 103 | } |
104 | 104 | return array_reverse($last_products); |
105 | 105 | } |
106 | - | |
106 | + | |
107 | 107 | public static function getSpecialProducts($type, $count, $sort = NULL) |
108 | 108 | { |
109 | 109 | switch($type) { |
... | ... | @@ -128,7 +128,7 @@ |
128 | 128 | ->limit($count)/*->orderBy($sort)*/ |
129 | 129 | ->all(); |
130 | 130 | } |
131 | - | |
131 | + | |
132 | 132 | public static function getSimilarProducts($product, $count = 10) |
133 | 133 | { |
134 | 134 | if(!is_object($product)) { |
... | ... | @@ -137,7 +137,7 @@ |
137 | 137 | ->with('enabledVariants') |
138 | 138 | ->one(); |
139 | 139 | } |
140 | - | |
140 | + | |
141 | 141 | if(!$product->properties) { |
142 | 142 | return [ ]; |
143 | 143 | } |
... | ... | @@ -182,7 +182,7 @@ |
182 | 182 | } |
183 | 183 | return $products; |
184 | 184 | } |
185 | - | |
185 | + | |
186 | 186 | /** |
187 | 187 | * @param ActiveQuery $query |
188 | 188 | * @param $params |
... | ... | @@ -217,9 +217,9 @@ |
217 | 217 | ]); |
218 | 218 | } |
219 | 219 | } |
220 | - | |
220 | + | |
221 | 221 | foreach($params as $key => $param) { |
222 | - | |
222 | + | |
223 | 223 | switch($key) { |
224 | 224 | case 'special': |
225 | 225 | foreach($param as $key => $value) { |
... | ... | @@ -249,7 +249,7 @@ |
249 | 249 | break; |
250 | 250 | default: |
251 | 251 | $query->andWhere( |
252 | - Product::tableName() . '.product_id IN ( | |
252 | + Product::tableName() . '.product_id IN ( | |
253 | 253 | SELECT DISTINCT products |
254 | 254 | FROM ( |
255 | 255 | SELECT product_id AS products |
... | ... | @@ -263,16 +263,16 @@ |
263 | 263 | INNER JOIN tax_option ON tax_option.tax_option_id = product_variant_option.option_id |
264 | 264 | INNER JOIN tax_group ON tax_group.tax_group_id = tax_option.tax_group_id |
265 | 265 | WHERE tax_group.alias LIKE \''. $key .'\' AND tax_option.alias IN (\'' . implode('\',\'', $param) . '\')) |
266 | - ) | |
267 | - ) AS table_name | |
266 | + ) | |
267 | + ) AS table_name | |
268 | 268 | )' |
269 | 269 | ); |
270 | 270 | } |
271 | - | |
271 | + | |
272 | 272 | } |
273 | - | |
273 | + | |
274 | 274 | } |
275 | - | |
275 | + | |
276 | 276 | public static function productCountQuery($category = NULL, $params, $excludeKeys = [ ]) |
277 | 277 | { |
278 | 278 | $p = [ ]; |
... | ... | @@ -289,14 +289,14 @@ |
289 | 289 | } |
290 | 290 | ProductHelper::_setQueryParams($query, $params); |
291 | 291 | $query->select([ 'COUNT(product.product_id)' ]); |
292 | - | |
292 | + | |
293 | 293 | return $query; |
294 | 294 | } |
295 | - | |
295 | + | |
296 | 296 | public static function addLastCategory($category_id) { |
297 | 297 | \Yii::$app->session->set('last_category_id', $category_id); |
298 | 298 | } |
299 | - | |
299 | + | |
300 | 300 | public static function getLastCategory() { |
301 | 301 | return \Yii::$app->session->get('last_category_id'); |
302 | 302 | } | ... | ... |
common/modules/product/widgets/specialProducts.php