Compare View
Commits (2)
Showing
16 changed files
Show diff stats
backend/views/layouts/main-sidebar.php
... | ... | @@ -45,10 +45,20 @@ use yii\widgets\Menu; |
45 | 45 | 'options' => ['class'=>\Yii::$app->user->can('product') ? '' :'hide'], |
46 | 46 | ], |
47 | 47 | [ |
48 | + 'label' => 'Типы вариантов', | |
49 | + 'url' => ['/product/product-variant-type'], | |
50 | + 'options' => ['class'=>\Yii::$app->user->can('product') ? '' :'hide'], | |
51 | + ], | |
52 | + [ | |
48 | 53 | 'label' => 'Импорт товаров', |
49 | 54 | 'url' => ['/product/manage/import'], |
50 | 55 | 'options' => ['class'=>\Yii::$app->user->can('product') ? '' :'hide'], |
51 | 56 | ], |
57 | + [ | |
58 | + 'label' => 'Экспорт товаров', | |
59 | + 'url' => ['/product/manage/export'], | |
60 | + 'options' => ['class'=>\Yii::$app->user->can('product') ? '' :'hide'], | |
61 | + ], | |
52 | 62 | ] |
53 | 63 | ], |
54 | 64 | [ | ... | ... |
common/modules/product/controllers/ManageController.php
... | ... | @@ -4,6 +4,7 @@ namespace common\modules\product\controllers; |
4 | 4 | |
5 | 5 | use common\modules\product\helpers\ProductHelper; |
6 | 6 | use common\modules\product\models\Category; |
7 | +use common\modules\product\models\Export; | |
7 | 8 | use common\modules\product\models\Import; |
8 | 9 | use common\modules\product\models\ProductImage; |
9 | 10 | use common\modules\product\models\ProductVariant; |
... | ... | @@ -278,6 +279,14 @@ class ManageController extends Controller |
278 | 279 | ]); |
279 | 280 | } |
280 | 281 | |
282 | + public function actionExport() { | |
283 | + $model = new Export(); | |
284 | + if (($file = $model->process(Yii::getAlias('@uploadDir')))) { | |
285 | + return Yii::$app->response->sendFile($file)->send(); | |
286 | + } | |
287 | + throw new NotFoundHttpException('Error'); | |
288 | + } | |
289 | + | |
281 | 290 | /** |
282 | 291 | * Finds the Product model based on its primary key value. |
283 | 292 | * If the model is not found, a 404 HTTP exception will be thrown. | ... | ... |
common/modules/product/helpers/ProductHelper.php
... | ... | @@ -10,12 +10,19 @@ use yii\base\Object; |
10 | 10 | use Yii; |
11 | 11 | |
12 | 12 | class ProductHelper extends Object { |
13 | + const PRODUCT_TAX_GROUP_ID_TARGET = 20; | |
14 | + const PRODUCT_TAX_GROUP_ID_YEAR = 21; | |
15 | + const PRODUCT_TAX_GROUP_ID_SEX = 22; | |
16 | + | |
17 | + const PRODUCT_VARIANT_TYPE_COLOR = 1; | |
18 | + const PRODUCT_VARIANT_TYPE_SIZE = 2; | |
19 | + | |
13 | 20 | public static function getCategories() { |
14 | - return Category::find()->with('categoryName')->getTree(); | |
21 | + return Category::find()->getTree(); // with('categoryName')-> | |
15 | 22 | } |
16 | 23 | |
17 | 24 | public static function getBrands() { |
18 | - return Brand::find()->with('brandName'); | |
25 | + return Brand::find(); // ->with('brandName') | |
19 | 26 | } |
20 | 27 | |
21 | 28 | /* | ... | ... |
common/modules/product/models/BrandQuery.php
... | ... | @@ -20,7 +20,7 @@ class BrandQuery extends \yii\db\ActiveQuery |
20 | 20 | */ |
21 | 21 | public function all($db = null) |
22 | 22 | { |
23 | - $this->with('brandName'); | |
23 | +// $this->with('brandName'); | |
24 | 24 | return parent::all($db); |
25 | 25 | } |
26 | 26 | |
... | ... | @@ -30,7 +30,7 @@ class BrandQuery extends \yii\db\ActiveQuery |
30 | 30 | */ |
31 | 31 | public function one($db = null) |
32 | 32 | { |
33 | - $this->with('brandName'); | |
33 | +// $this->with('brandName'); | |
34 | 34 | return parent::one($db); |
35 | 35 | } |
36 | 36 | ... | ... |
common/modules/product/models/BrandSearch.php
... | ... | @@ -42,7 +42,7 @@ class BrandSearch extends Brand |
42 | 42 | */ |
43 | 43 | public function search($params) |
44 | 44 | { |
45 | - $query = Brand::find()->with('brandName'); | |
45 | + $query = Brand::find(); // ->with('brandName') | |
46 | 46 | |
47 | 47 | // add conditions that should always apply here |
48 | 48 | |
... | ... | @@ -71,15 +71,17 @@ class BrandSearch extends Brand |
71 | 71 | 'brand_name_id' => $this->brand_name_id, |
72 | 72 | ]); |
73 | 73 | |
74 | - $query->joinWith('brandName'); | |
75 | - | |
74 | + | |
76 | 75 | $query->andFilterWhere(['ilike', 'alias', $this->alias]) |
77 | 76 | ->andFilterWhere(['ilike', 'image', $this->image]) |
78 | 77 | ->andFilterWhere(['ilike', 'meta_title', $this->meta_title]) |
79 | 78 | ->andFilterWhere(['ilike', 'meta_desc', $this->meta_desc]) |
80 | 79 | ->andFilterWhere(['ilike', 'meta_robots', $this->meta_robots]) |
81 | - ->andFilterWhere(['ilike', 'seo_text', $this->seo_text]) | |
82 | - ->andFilterWhere(['ilike', 'brand_name.value', $this->brand_name]); | |
80 | + ->andFilterWhere(['ilike', 'seo_text', $this->seo_text]); | |
81 | + if (!empty($this->brand_name)) { | |
82 | + $query->joinWith('brandName'); | |
83 | + $query->andFilterWhere(['ilike', 'brand_name.value', $this->brand_name]); | |
84 | + } | |
83 | 85 | |
84 | 86 | $query->orderBy('brand_id', 'asc'); |
85 | 87 | |
... | ... | @@ -94,8 +96,7 @@ class BrandSearch extends Brand |
94 | 96 | ]) |
95 | 97 | ->innerJoin(Product::tableName(), Product::tableName() .'.brand_id='. Brand::tableName() .'.brand_id') |
96 | 98 | ->innerJoin(ProductCategory::tableName(), ProductCategory::tableName() .'.product_id='. Product::tableName() .'.product_id') |
97 | - | |
98 | - ->with('brandName'); | |
99 | + ->with(['brandName']); | |
99 | 100 | if (!empty($category)) { |
100 | 101 | $query->where([ |
101 | 102 | ProductCategory::tableName() .'.category_id' => $category->category_id | ... | ... |
common/modules/product/models/Category.php
... | ... | @@ -134,11 +134,10 @@ class Category extends \yii\db\ActiveRecord |
134 | 134 | } |
135 | 135 | |
136 | 136 | public function getProducts() { |
137 | - return $this->hasMany(Product::className(), ['product_id' => 'product_id']) | |
138 | - ->viaTable('product_category', ['category_id' => 'category_id']) | |
139 | - ->joinWith(['variants']) | |
140 | - ->andOnCondition(['!=', ProductVariant::tableName() .'.stock', 0]); | |
141 | -// return $this->getRelations('product_categories'); | |
137 | +// return $this->hasMany(Product::className(), ['product_id' => 'product_id']) | |
138 | +// ->viaTable('product_category', ['category_id' => 'category_id']) | |
139 | +// ->andOnCondition(['!=', ProductVariant::tableName() .'.stock', 0]); | |
140 | + return $this->getRelations('product_categories'); | |
142 | 141 | } |
143 | 142 | |
144 | 143 | /** | ... | ... |
1 | +<?php | |
2 | + | |
3 | +namespace common\modules\product\models; | |
4 | + | |
5 | +use common\modules\product\helpers\ProductHelper; | |
6 | +use yii\base\Model; | |
7 | + | |
8 | +class Export extends Model { | |
9 | + public $errors = []; | |
10 | + public $output = []; | |
11 | + | |
12 | + public function process($dirName, $filename = null, $use_not_enables = false) { | |
13 | + if (is_null($filename)) { | |
14 | + $filename = 'products_'. date('d_m_Y_H_i') .'.csv'; | |
15 | + } | |
16 | + setlocale(LC_ALL, 'ru_RU.CP1251'); | |
17 | + $handle = fopen($dirName .'/'. $filename, "w"); | |
18 | + $products = Product::find()->joinWith(['variants'])->where(['!=', ProductVariant::tableName() .'.stock', 0])->select('product.product_id')->all(); | |
19 | + $i = 0; | |
20 | + foreach ($products as $product_id) | |
21 | + { | |
22 | + $product = Product::findOne($product_id); | |
23 | + $i++; | |
24 | + /*if ($i>1e2) { | |
25 | + break; | |
26 | + }*/ | |
27 | + $mods = []; | |
28 | + | |
29 | + foreach ($product->enabledVariants as $variant) | |
30 | + { | |
31 | + $size = $color = ''; | |
32 | + if ($product->product_variant_type_id) { | |
33 | + $productVariantType = ProductVariantType::findOne($product->product_variant_type_id); | |
34 | + if ($productVariantType) { | |
35 | + if ($productVariantType->product_variant_type_id == ProductHelper::PRODUCT_VARIANT_TYPE_COLOR) { | |
36 | + $color = $product->name; | |
37 | + } elseif ($productVariantType->product_variant_type_id == ProductHelper::PRODUCT_VARIANT_TYPE_SIZE) { | |
38 | + $size = $product->name; | |
39 | + } | |
40 | + } | |
41 | + } | |
42 | + $mods[] = $variant->sku . '=' . $size . '=' . $color . '=' . $variant->imageUrl; | |
43 | + } | |
44 | + | |
45 | + $fotos = []; | |
46 | + | |
47 | + foreach ($product->images as $image) | |
48 | + { | |
49 | + $fotos[] = $image->imageUrl; | |
50 | + } | |
51 | + | |
52 | + $filters = $product->properties; | |
53 | + | |
54 | + $list = [ | |
55 | + $product->category->name, | |
56 | + $product->brand->name, | |
57 | + $product->name, | |
58 | + '', | |
59 | + ((! empty($product->description)) ? $product->description : ''), | |
60 | + ((! empty($filters[ProductHelper::PRODUCT_TAX_GROUP_ID_TARGET])) ? implode (',', $filters[ProductHelper::PRODUCT_TAX_GROUP_ID_TARGET]) : ''), | |
61 | + '', | |
62 | + ((! empty($filters[ProductHelper::PRODUCT_TAX_GROUP_ID_SEX])) ? implode (',', $filters[ProductHelper::PRODUCT_TAX_GROUP_ID_SEX]) : ''), | |
63 | + ((! empty($filters[ProductHelper::PRODUCT_TAX_GROUP_ID_YEAR])) ? implode (',', $filters[ProductHelper::PRODUCT_TAX_GROUP_ID_YEAR]) : ''), | |
64 | + $product->price_old, | |
65 | + $product->price, | |
66 | + intval($product->akciya), | |
67 | + '', | |
68 | + intval($product->new), | |
69 | + intval($product->top), | |
70 | + '', | |
71 | + $product->video, | |
72 | + implode (',', $fotos), | |
73 | + ]; | |
74 | + | |
75 | + $to_write = array_merge ($list, $mods); | |
76 | + foreach($to_write as &$cell) { | |
77 | + $cell = iconv("UTF-8", "WINDOWS-1251", $cell); | |
78 | + } | |
79 | + | |
80 | + fputcsv($handle, $to_write, ';'); | |
81 | + } | |
82 | + | |
83 | + fclose ($handle); | |
84 | + | |
85 | + return $dirName .'/'. $filename; | |
86 | + } | |
87 | +} | |
0 | 88 | \ No newline at end of file | ... | ... |
common/modules/product/models/Product.php
... | ... | @@ -3,6 +3,7 @@ |
3 | 3 | namespace common\modules\product\models; |
4 | 4 | |
5 | 5 | use common\behaviors\Slug; |
6 | +use common\modules\rubrication\models\TaxGroup; | |
6 | 7 | use common\modules\rubrication\models\TaxOption; |
7 | 8 | use Yii; |
8 | 9 | use common\modules\relation\relationBehavior; |
... | ... | @@ -163,7 +164,7 @@ class Product extends \yii\db\ActiveRecord |
163 | 164 | } |
164 | 165 | |
165 | 166 | public function getEnabledVariantPrice() { |
166 | - return $this->enabledVariant->price; | |
167 | + return $this->enabledVariants[0]->price; | |
167 | 168 | } |
168 | 169 | |
169 | 170 | /** |
... | ... | @@ -179,6 +180,26 @@ class Product extends \yii\db\ActiveRecord |
179 | 180 | return $this->hasMany(ProductVariant::className(), ['product_id' => 'product_id'])->andOnCondition(['!=', ProductVariant::tableName() .'.stock', 0]); |
180 | 181 | } |
181 | 182 | |
183 | + /* | |
184 | + * Get variants grouped by type | |
185 | + */ | |
186 | + public function getEnabledVariantsGrouped() | |
187 | + { | |
188 | + $variants = []; | |
189 | + foreach ($this->enabledVariants as $variant) { | |
190 | + $variants[$variant->product_variant_type_id][] = $variant; | |
191 | + } | |
192 | + if (empty($variants)) { | |
193 | + return []; | |
194 | + } | |
195 | + $variants_type = []; | |
196 | + foreach(ProductVariantType::find()->where(['product_variant_type_id' => array_keys($variants)])->all() as $variant_type) { | |
197 | + $variant_type->_variants = $variants[$variant_type->product_variant_type_id]; | |
198 | + $variants_type[] = $variant_type; | |
199 | + } | |
200 | + return $variants_type; | |
201 | + } | |
202 | + | |
182 | 203 | public function setVariants($variants) { |
183 | 204 | $this->_variants = $variants; |
184 | 205 | } |
... | ... | @@ -206,7 +227,8 @@ class Product extends \yii\db\ActiveRecord |
206 | 227 | } |
207 | 228 | |
208 | 229 | public function getOptions() { |
209 | - return $this->getRelations('product_option'); | |
230 | + return $this->hasMany(TaxOption::className(), ['tax_option_id' => 'option_id'])->viaTable('product_option', ['product_id' => 'product_id']); | |
231 | +// return $this->getRelations('product_option'); | |
210 | 232 | } |
211 | 233 | |
212 | 234 | public function getStocks() { |
... | ... | @@ -347,4 +369,18 @@ class Product extends \yii\db\ActiveRecord |
347 | 369 | } |
348 | 370 | return $op; |
349 | 371 | } |
372 | + | |
373 | + public function getProperties() { | |
374 | + $groups = $options = []; | |
375 | + foreach ($this->options as $option) { | |
376 | + $options[$option->tax_group_id][] = $option; | |
377 | + } | |
378 | + foreach (TaxGroup::find()->where(['tax_group_id' => array_keys($options)])->all() as $group) { | |
379 | + if (!empty($options[$group->tax_group_id])) { | |
380 | + $group->_options = $options[$group->tax_group_id]; | |
381 | + $groups[] = $group; | |
382 | + } | |
383 | + } | |
384 | + return $groups; | |
385 | + } | |
350 | 386 | } | ... | ... |
common/modules/product/models/ProductVariant.php
... | ... | @@ -169,14 +169,6 @@ class ProductVariant extends \yii\db\ActiveRecord |
169 | 169 | $this->stocks = (array) $stocks; |
170 | 170 | } |
171 | 171 | |
172 | - /*public function getStocks() { | |
173 | - return $this->hasMany(Stock::className(), ['stock_id' => 'stock_id'])->viaTable(ProductStock::tableName(), ['product_variant_id' => 'product_variant_id']); | |
174 | - } | |
175 | - | |
176 | - public function getStocksIds() { | |
177 | - return ArrayHelper::getColumn($this->hasMany(Stock::className(), ['stock_id' => 'stock_id'])->viaTable(ProductStock::tableName(), ['product_variant_id' => 'product_variant_id'])->all(), 'stock_id'); | |
178 | - }*/ | |
179 | - | |
180 | 172 | public function afterSave($insert, $changedAttributes) |
181 | 173 | { |
182 | 174 | if (!empty($this->stocks)) { | ... | ... |
common/modules/product/models/ProductVariantType.php
... | ... | @@ -12,6 +12,8 @@ use Yii; |
12 | 12 | */ |
13 | 13 | class ProductVariantType extends \yii\db\ActiveRecord |
14 | 14 | { |
15 | + public $_variants = []; | |
16 | + | |
15 | 17 | /** |
16 | 18 | * @inheritdoc |
17 | 19 | */ |
... | ... | @@ -40,4 +42,8 @@ class ProductVariantType extends \yii\db\ActiveRecord |
40 | 42 | 'name' => 'Name', |
41 | 43 | ]; |
42 | 44 | } |
45 | + | |
46 | + public function getId() { | |
47 | + return $this->product_variant_type_id; | |
48 | + } | |
43 | 49 | } | ... | ... |
common/modules/product/models/import.php
... | ... | @@ -2,6 +2,7 @@ |
2 | 2 | |
3 | 3 | namespace common\modules\product\models; |
4 | 4 | |
5 | +use common\modules\product\helpers\ProductHelper; | |
5 | 6 | use common\modules\product\models\Category; |
6 | 7 | use common\modules\product\models\CategoryName; |
7 | 8 | use common\modules\product\models\ProductImage; |
... | ... | @@ -64,6 +65,8 @@ class Import extends Model { |
64 | 65 | |
65 | 66 | $j = 0; |
66 | 67 | |
68 | + $is_utf = (preg_match('//u', file_get_contents(Yii::getAlias('@uploadDir') .'/'. Yii::getAlias('@uploadFileProducts'), null, null, null, 1000000))); | |
69 | + | |
67 | 70 | while (($data = fgetcsv ($handle, 10000, ";")) !== FALSE) |
68 | 71 | { |
69 | 72 | $j++; |
... | ... | @@ -73,8 +76,9 @@ class Import extends Model { |
73 | 76 | |
74 | 77 | foreach ($data as &$value) |
75 | 78 | { |
76 | - //$value = mb_convert_encoding ($value, "UTF-8", mb_detect_encoding ($value)); | |
77 | - $value = iconv ('windows-1251', "UTF-8//TRANSLIT//IGNORE", $value); | |
79 | + if (!$is_utf) { | |
80 | + $value = iconv ('windows-1251', "UTF-8//TRANSLIT//IGNORE", $value); | |
81 | + } | |
78 | 82 | $value = trim ($value); |
79 | 83 | } |
80 | 84 | |
... | ... | @@ -277,7 +281,7 @@ class Import extends Model { |
277 | 281 | if (!$filter) { |
278 | 282 | continue; |
279 | 283 | } |
280 | - if ( ($value = TaxValueString::find()->innerJoinWith('taxOption')->andFilterWhere(['ilike', 'value', $filter])->andFilterWhere(['tax_option.tax_group_id' => 20])->one()) === null ) { | |
284 | + if ( ($value = TaxValueString::find()->innerJoinWith('taxOption')->andFilterWhere(['ilike', 'value', $filter])->andFilterWhere(['tax_option.tax_group_id' => ProductHelper::PRODUCT_TAX_GROUP_ID_TARGET])->one()) === null ) { | |
281 | 285 | // Create option |
282 | 286 | $option = new TaxOption(); |
283 | 287 | $option->tax_group_id = 20; |
... | ... | @@ -302,7 +306,7 @@ class Import extends Model { |
302 | 306 | if (!$filter) { |
303 | 307 | continue; |
304 | 308 | } |
305 | - if ( ($value = TaxValueString::find()->innerJoinWith('taxOption')->andFilterWhere(['ilike', 'value', $filter])->andFilterWhere(['tax_option.tax_group_id' => 21])->one()) === null ) { | |
309 | + if ( ($value = TaxValueString::find()->innerJoinWith('taxOption')->andFilterWhere(['ilike', 'value', $filter])->andFilterWhere(['tax_option.tax_group_id' => ProductHelper::PRODUCT_TAX_GROUP_ID_YEAR])->one()) === null ) { | |
306 | 310 | // Create option |
307 | 311 | $option = new TaxOption(); |
308 | 312 | $option->tax_group_id = 21; |
... | ... | @@ -327,7 +331,7 @@ class Import extends Model { |
327 | 331 | if (!$filter) { |
328 | 332 | continue; |
329 | 333 | } |
330 | - if ( ($value = TaxValueString::find()->innerJoinWith('taxOption')->andFilterWhere(['ilike', 'value', $filter])->andFilterWhere(['tax_option.tax_group_id' => 22])->one()) === null ) { | |
334 | + if ( ($value = TaxValueString::find()->innerJoinWith('taxOption')->andFilterWhere(['ilike', 'value', $filter])->andFilterWhere(['tax_option.tax_group_id' => ProductHelper::PRODUCT_TAX_GROUP_ID_SEX])->one()) === null ) { | |
331 | 335 | // Create option |
332 | 336 | $option = new TaxOption(); |
333 | 337 | $option->tax_group_id = 22; | ... | ... |
common/modules/product/widgets/views/product_smart.php
... | ... | @@ -8,9 +8,9 @@ use yii\helpers\Url; |
8 | 8 | <a href="<?= Url::to([ |
9 | 9 | 'catalog/product', |
10 | 10 | 'product' => $product, |
11 | - '#' => 'm' .$product->enabledVariant->product_variant_id]) | |
11 | + '#' => 'm' .$product->enabledVariants[0]->product_variant_id]) | |
12 | 12 | ?>"> |
13 | - <?= \common\components\artboximage\ArtboxImageHelper::getImage($product->enabledVariant->imageUrl, 'list')?> | |
13 | + <?= \common\components\artboximage\ArtboxImageHelper::getImage($product->enabledVariants[0]->imageUrl, 'list')?> | |
14 | 14 | </a> |
15 | 15 | </div> |
16 | 16 | <?php if(!empty($product->is_top) || !empty($product->is_new) || !empty($product->akciya)) :?> |
... | ... | @@ -34,17 +34,17 @@ use yii\helpers\Url; |
34 | 34 | |
35 | 35 | <div class="cost-block"> |
36 | 36 | <p class="cost"> |
37 | - <?php if ($product->enabledVariant->price_old != 0 && $product->enabledVariant->price_old != $product->enabledVariant->price) :?> | |
38 | - <strike><span id="old_cost"><?= $product->enabledVariant->price_old ?></span> грн.</strike> | |
37 | + <?php if ($product->enabledVariants[0]->price_old != 0 && $product->enabledVariants[0]->price_old != $product->enabledVariants[0]->price) :?> | |
38 | + <strike><span id="old_cost"><?= $product->enabledVariants[0]->price_old ?></span> грн.</strike> | |
39 | 39 | <?php endif?> |
40 | - <?= $product->enabledVariant->price?> <span>грн.</span></p> | |
40 | + <?= $product->enabledVariants[0]->price?> <span>грн.</span></p> | |
41 | 41 | </div> |
42 | 42 | </div> |
43 | 43 | |
44 | 44 | <a href="<?= Url::to([ |
45 | 45 | 'catalog/product', |
46 | 46 | 'product' => $product, |
47 | - '#' => 'm' .$product->enabledVariant->product_variant_id]) | |
47 | + '#' => 'm' .$product->enabledVariants[0]->product_variant_id]) | |
48 | 48 | ?>" class="link_buy">Купить</a> |
49 | 49 | |
50 | 50 | <div class="mycarousel"> |
... | ... | @@ -55,7 +55,7 @@ use yii\helpers\Url; |
55 | 55 | 'catalog/product', |
56 | 56 | 'product' => $product, |
57 | 57 | '#' => 'm' . $variant->product_variant_id]) ?>"> |
58 | - <?= \common\components\artboximage\ArtboxImageHelper::getImage($variant->imageUrl, 'product_variant')?> | |
58 | + <?= \common\components\artboximage\ArtboxImageHelper::getImage((!empty($variant->image) && !empty($variant->image->imageUrl) ? $variant->image->imageUrl : '/images/no_photo.png'), 'product_variant')?> | |
59 | 59 | </a> |
60 | 60 | </li> |
61 | 61 | <?php endforeach; ?> | ... | ... |
frontend/controllers/CatalogController.php
... | ... | @@ -163,25 +163,11 @@ class CatalogController extends \yii\web\Controller |
163 | 163 | throw new HttpException(404, 'Товар не найден'); |
164 | 164 | } |
165 | 165 | |
166 | - $groups = []; | |
167 | - foreach($product->category->getTaxGroups()->all() as $_group) { | |
168 | - $groups[$_group->tax_group_id] = $_group; | |
169 | - } | |
170 | - foreach ($product->options as $option) { | |
171 | - $groups[$option->tax_group_id]->_options[] = $option; | |
172 | - } | |
173 | - foreach($groups as $i => $group) { | |
174 | - if (empty($group->_options)) | |
175 | - unset($groups[$i]); | |
176 | - } | |
177 | - $category = $product->category; | |
178 | - | |
179 | 166 | ProductHelper::addLastProsucts($product->product_id); |
180 | 167 | |
181 | 168 | return $this->render('product', [ |
182 | 169 | 'product' => $product, |
183 | - 'category' => $category, | |
184 | - 'properties' => $groups, | |
170 | + 'category' => $product->category, | |
185 | 171 | ]); |
186 | 172 | } |
187 | 173 | ... | ... |
frontend/views/catalog/product.php
... | ... | @@ -13,7 +13,7 @@ $this->title = $product->fullname; |
13 | 13 | //} |
14 | 14 | $this->params['breadcrumbs'][] = ['label' => 'Каталог', 'url' => ['catalog/category']]; |
15 | 15 | $this->params['breadcrumbs'][] = ['label' => $product->category->categoryName->value, 'url' => ['catalog/category', 'category' => $product->category]]; |
16 | -$this->params['breadcrumbs'][] = $product->fullname .' #'. $product->enabledVariant->sku; | |
16 | +$this->params['breadcrumbs'][] = $product->fullname .' #'. $product->enabledVariants[0]->sku; | |
17 | 17 | |
18 | 18 | $this->registerJs (' |
19 | 19 | |
... | ... | @@ -94,9 +94,10 @@ $this->registerJs (" |
94 | 94 | <div class="loyout"> |
95 | 95 | <div class="productLeftBar"> |
96 | 96 | <h1><?= $product->fullname ?></h1> |
97 | - <div class="begin">Цветовые решения</div> | |
97 | + <?php foreach($product->enabledVariantsGrouped as $variantGroup) :?> | |
98 | + <div class="begin"><?= $variantGroup->name2?></div> | |
98 | 99 | <ul class="product_mod"> |
99 | - <?php foreach ($product->enabledVariants as $variant): ?> | |
100 | + <?php foreach ($variantGroup->_variants as $variant): ?> | |
100 | 101 | <li> |
101 | 102 | <a id='m<?= $variant->product_variant_id ?>' href="#<?=$variant->product_variant_id ?>" |
102 | 103 | data-cost="<?= $variant->price ?>" |
... | ... | @@ -111,6 +112,7 @@ $this->registerJs (" |
111 | 112 | <?php endforeach; ?> |
112 | 113 | </ul> |
113 | 114 | <div class="both"></div> |
115 | + <?php endforeach; ?> | |
114 | 116 | |
115 | 117 | <div class="cost_box product_read_"> |
116 | 118 | <div class='params'>код: <span id='art'></span><br/> цвет: <span id='color'></span></div> |
... | ... | @@ -142,7 +144,7 @@ $this->registerJs (" |
142 | 144 | <li><a href="#">Характеристики</a> |
143 | 145 | <div class="info"> |
144 | 146 | <p>Бренд: <?= $product->brand->name ?></p> |
145 | - <?php foreach ($properties as $group): ?> | |
147 | + <?php foreach ($product->properties as $group): ?> | |
146 | 148 | <p><?= $group->name ?> <?php foreach($group->_options as $option) :?> <?= $option->ValueRenderHTML?><?php endforeach?></p> |
147 | 149 | <?php endforeach; ?> |
148 | 150 | </div> |
... | ... | @@ -165,7 +167,7 @@ $this->registerJs (" |
165 | 167 | <div class="content"> |
166 | 168 | <div class="pic"> |
167 | 169 | <center> |
168 | - <a href="#" rel="shadowbox[gal]" id="picoriginal"><?= \common\components\artboximage\ArtboxImageHelper::getImage($product->enabledVariant->imageUrl, 'product_view',['id'=>'pic'])?></a> | |
170 | + <a href="#" rel="shadowbox[gal]" id="picoriginal"><?= \common\components\artboximage\ArtboxImageHelper::getImage($product->enabledVariants[0]->imageUrl, 'product_view',['id'=>'pic'])?></a> | |
169 | 171 | </center> |
170 | 172 | </div> |
171 | 173 | <ul class="product_colors"> | ... | ... |
frontend/views/catalog/product_item.php
... | ... | @@ -5,8 +5,8 @@ use yii\helpers\Url; |
5 | 5 | <li class="item"> |
6 | 6 | <div class="boxitem"> |
7 | 7 | <div class="pixbox"> |
8 | - <a href="<?= Url::to(['catalog/product', 'product' => $product,'#' => 'm' .$product->enabledVariant->product_variant_id]) ?>"> | |
9 | - <?= \common\components\artboximage\ArtboxImageHelper::getImage($product->enabledVariant->imageUrl, 'list')?> | |
8 | + <a href="<?= Url::to(['catalog/product', 'product' => $product,'#' => 'm' .$product->enabledVariants[0]->product_variant_id]) ?>"> | |
9 | + <?= \common\components\artboximage\ArtboxImageHelper::getImage($product->enabledVariants[0]->imageUrl, 'list')?> | |
10 | 10 | </a> |
11 | 11 | </div> |
12 | 12 | <?php if(!empty($product->is_top) || !empty($product->is_new) || !empty($product->akciya)) :?> |
... | ... | @@ -25,7 +25,7 @@ use yii\helpers\Url; |
25 | 25 | <a href="<?= Url::to([ |
26 | 26 | 'catalog/product', |
27 | 27 | 'product' => $product, |
28 | - '#' => 'm' .$product->enabledVariant->product_variant_id]) | |
28 | + '#' => 'm' .$product->enabledVariants[0]->product_variant_id]) | |
29 | 29 | ?>" |
30 | 30 | class="name"><?= $product->fullname ?> |
31 | 31 | </a> |
... | ... | @@ -35,12 +35,12 @@ use yii\helpers\Url; |
35 | 35 | echo '<div class="cost-block">'; |
36 | 36 | echo '<p class="cost">'; |
37 | 37 | // есть скидка |
38 | - if ($product->enabledVariant->price_old != 0 && $product->enabledVariant->price_old != $product->enabledVariant->price) | |
38 | + if ($product->enabledVariants[0]->price_old != 0 && $product->enabledVariants[0]->price_old != $product->enabledVariants[0]->price) | |
39 | 39 | { |
40 | - echo '<strike><span id=\'old_cost\'>'.$product->enabledVariant->price_old.'</span> грн.</strike> '; | |
40 | + echo '<strike><span id=\'old_cost\'>'.$product->enabledVariants[0]->price_old.'</span> грн.</strike> '; | |
41 | 41 | } |
42 | 42 | |
43 | - echo $product->enabledVariant->price.' <span>грн.</span></p>'; | |
43 | + echo $product->enabledVariants[0]->price.' <span>грн.</span></p>'; | |
44 | 44 | |
45 | 45 | echo '</div>'; |
46 | 46 | |
... | ... | @@ -49,7 +49,7 @@ use yii\helpers\Url; |
49 | 49 | <a href="<?= Url::to([ |
50 | 50 | 'catalog/product', |
51 | 51 | 'product' => $product, |
52 | - '#' => 'm' .$product->enabledVariant->product_variant_id]) | |
52 | + '#' => 'm' .$product->enabledVariants[0]->product_variant_id]) | |
53 | 53 | ?>" class="link_buy">Купить</a> |
54 | 54 | |
55 | 55 | <div class="mycarousel"> | ... | ... |
frontend/widgets/Rubrics.php
... | ... | @@ -32,7 +32,7 @@ class Rubrics extends Widget { |
32 | 32 | $items = []; |
33 | 33 | |
34 | 34 | if (empty($this->categories)) { |
35 | - $this->categories = Category::find ()->orderBy('category_id', SORT_ASC)->all(); | |
35 | + $this->categories = Category::find()->orderBy('category_id', SORT_ASC)->all(); | |
36 | 36 | } |
37 | 37 | foreach ($this->categories as $category) { |
38 | 38 | if (!empty($this->includes) && !in_array($category->category_id, $this->includes)) { | ... | ... |