Commit 96f5a82290d90ed126d5a3f15f16d9def9179b64
1 parent
70412c76
29.06.16
Showing
10 changed files
with
132 additions
and
37 deletions
Show diff stats
backend/config/bootstrap.php
| ... | ... | @@ -6,4 +6,4 @@ Yii::setAlias('@uploadFilePricesAway', 'price_product_away.csv'); |
| 6 | 6 | Yii::setAlias('@uploadFilePricesDuplicate', 'price_duplicate.csv'); |
| 7 | 7 | Yii::setAlias('@uploadFilePricesNoVariant', 'price_no_variant.csv'); |
| 8 | 8 | |
| 9 | -Yii::setAlias('@productsDir', '@frontend/web/images/products'); | |
| 10 | 9 | \ No newline at end of file |
| 10 | +Yii::setAlias('@productsDir', '@storage/products'); | |
| 11 | 11 | \ No newline at end of file | ... | ... |
common/modules/product/behaviors/FilterBehavior.php
0 → 100755
| 1 | +<?php | |
| 2 | + | |
| 3 | +namespace common\modules\product\behaviors; | |
| 4 | + | |
| 5 | + | |
| 6 | +use common\modules\product\models\ProductOption; | |
| 7 | +use common\modules\rubrication\models\TaxGroup; | |
| 8 | +use common\modules\rubrication\models\TaxOption; | |
| 9 | +use yii\base\Behavior; | |
| 10 | + | |
| 11 | +use Yii; | |
| 12 | + | |
| 13 | + | |
| 14 | +class FilterBehavior extends Behavior { | |
| 15 | + | |
| 16 | + public function getFilters(){ | |
| 17 | + | |
| 18 | + return $this->owner->hasMany(TaxOption::className(), ['tax_option_id' => 'option_id']) | |
| 19 | + ->viaTable(ProductOption::tableName(),[ 'product_id'=> $this->owner->tableSchema->primaryKey[0]]) | |
| 20 | + ->joinWith('taxGroup')->all(); | |
| 21 | + } | |
| 22 | + | |
| 23 | + | |
| 24 | +} | |
| 0 | 25 | \ No newline at end of file | ... | ... |
common/modules/product/models/Export.php
| ... | ... | @@ -4,6 +4,7 @@ namespace common\modules\product\models; |
| 4 | 4 | |
| 5 | 5 | use common\modules\product\helpers\ProductHelper; |
| 6 | 6 | use yii\base\Model; |
| 7 | +use yii\helpers\ArrayHelper; | |
| 7 | 8 | |
| 8 | 9 | class Export extends Model { |
| 9 | 10 | public $errors = []; |
| ... | ... | @@ -15,59 +16,66 @@ class Export extends Model { |
| 15 | 16 | } |
| 16 | 17 | setlocale(LC_ALL, 'ru_RU.CP1251'); |
| 17 | 18 | $handle = fopen($dirName .'/'. $filename, "w"); |
| 18 | - $products = Product::find()->joinWith(['variants'])->where(['!=', ProductVariant::tableName() .'.stock', 0])->select('product.product_id')->all(); | |
| 19 | + ///$products = Product::find()->joinWith(['variants'])->where(['!=', ProductVariant::tableName() .'.stock', 0])->select('product.product_id')->all(); | |
| 20 | + $products = Product::find() | |
| 21 | + ->with(['variantsWithFilters','brand','categoriesWithName'])->all(); | |
| 22 | + | |
| 19 | 23 | $i = 0; |
| 20 | - foreach ($products as $product_id) | |
| 24 | + foreach ($products as $product) | |
| 21 | 25 | { |
| 22 | - $product = Product::findOne($product_id); | |
| 26 | + | |
| 27 | + | |
| 23 | 28 | $i++; |
| 24 | 29 | /*if ($i>1e2) { |
| 25 | 30 | break; |
| 26 | 31 | }*/ |
| 27 | 32 | $mods = []; |
| 28 | 33 | |
| 29 | - foreach ($product->enabledVariants as $variant) | |
| 34 | + $filterString = $this->convertFilterToString($product->getFilters()); | |
| 35 | + | |
| 36 | + foreach ($product->variantsWithFilters as $variant) | |
| 30 | 37 | { |
| 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; | |
| 38 | + | |
| 39 | + $color = $variant->name; | |
| 40 | + | |
| 41 | + $mods[] = $variant->sku . | |
| 42 | + '=' . $this->convertFilterToString($variant->filters) . | |
| 43 | + '=' . $color . | |
| 44 | + '=' . ((!empty($variant->image)) ? $variant->image->image: ''). | |
| 45 | + '=' . $variant->stock; | |
| 43 | 46 | } |
| 44 | 47 | |
| 45 | 48 | $fotos = []; |
| 46 | 49 | |
| 47 | - foreach ($product->images as $image) | |
| 48 | - { | |
| 49 | - $fotos[] = $image->imageUrl; | |
| 50 | +// foreach ($product->images as $image) | |
| 51 | +// { | |
| 52 | +// $fotos[] = $image->imageUrl; | |
| 53 | +// } | |
| 54 | + | |
| 55 | +// $filters = $product->properties; | |
| 56 | + $categories = []; | |
| 57 | + foreach($product->categoriesWithName as $value){ | |
| 58 | + $categorName = ArrayHelper::getColumn($value->categoryNames,'value'); | |
| 59 | + $categories[] = $categorName[0]; | |
| 60 | + | |
| 50 | 61 | } |
| 51 | 62 | |
| 52 | - $filters = $product->properties; | |
| 63 | + | |
| 64 | + $categories = implode(',',$categories); | |
| 53 | 65 | |
| 54 | 66 | $list = [ |
| 55 | - $product->category->name, | |
| 67 | + $categories, | |
| 56 | 68 | $product->brand->name, |
| 57 | 69 | $product->name, |
| 58 | 70 | '', |
| 59 | 71 | ((! 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, | |
| 72 | + $filterString, | |
| 73 | + (!empty($product->variant)) ? $product->variant->price_old : '', | |
| 74 | + (!empty($product->variant)) ? $product->variant->price : '', | |
| 66 | 75 | intval($product->akciya), |
| 67 | 76 | '', |
| 68 | 77 | intval($product->new), |
| 69 | 78 | intval($product->top), |
| 70 | - '', | |
| 71 | 79 | $product->video, |
| 72 | 80 | implode (',', $fotos), |
| 73 | 81 | ]; |
| ... | ... | @@ -77,11 +85,30 @@ class Export extends Model { |
| 77 | 85 | $cell = iconv("UTF-8", "WINDOWS-1251", $cell); |
| 78 | 86 | } |
| 79 | 87 | |
| 88 | + | |
| 80 | 89 | fputcsv($handle, $to_write, ';'); |
| 81 | 90 | } |
| 82 | 91 | |
| 92 | + | |
| 93 | + | |
| 83 | 94 | fclose ($handle); |
| 84 | 95 | |
| 85 | 96 | return $dirName .'/'. $filename; |
| 86 | 97 | } |
| 98 | + | |
| 99 | + | |
| 100 | + public function convertFilterToString($filters){ | |
| 101 | + $fittersArray = []; | |
| 102 | + foreach($filters as $filter){ | |
| 103 | + $fittersArray[$filter->taxGroup->alias][] = $filter->name; | |
| 104 | + } | |
| 105 | + $filterString=[]; | |
| 106 | + | |
| 107 | + foreach($fittersArray as $filterName =>$filterRows ){ | |
| 108 | + $row = implode(',',$filterRows); | |
| 109 | + $filterString[] = "[{$filterName}:{$row}]"; | |
| 110 | + | |
| 111 | + } | |
| 112 | + return implode('*',$filterString); | |
| 113 | + } | |
| 87 | 114 | } |
| 88 | 115 | \ No newline at end of file | ... | ... |
common/modules/product/models/Import.php
| ... | ... | @@ -542,7 +542,7 @@ class Import extends Model { |
| 542 | 542 | // Create option |
| 543 | 543 | $option = new TaxOption(); |
| 544 | 544 | $option->tax_group_id = $taxGroup->tax_group_id; |
| 545 | - $option->alias = $filter_options; | |
| 545 | + $option->name = $filter_options; | |
| 546 | 546 | $option->save(); |
| 547 | 547 | |
| 548 | 548 | $value = new TaxValueString(); | ... | ... |
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\product\behaviors\FilterBehavior; | |
| 6 | 7 | use common\modules\rubrication\models\TaxGroup; |
| 7 | 8 | use common\modules\rubrication\models\TaxOption; |
| 8 | 9 | use Yii; |
| ... | ... | @@ -53,6 +54,9 @@ class Product extends \yii\db\ActiveRecord |
| 53 | 54 | ] |
| 54 | 55 | ], |
| 55 | 56 | [ |
| 57 | + 'class' =>FilterBehavior::className(), | |
| 58 | + ], | |
| 59 | + [ | |
| 56 | 60 | 'class' => Slug::className(), |
| 57 | 61 | 'in_attribute' => 'name', |
| 58 | 62 | 'out_attribute' => 'alias', |
| ... | ... | @@ -218,6 +222,10 @@ class Product extends \yii\db\ActiveRecord |
| 218 | 222 | return $this->hasMany(Category::className(), ['category_id' => 'category_id'])->viaTable('product_category', ['product_id' => 'product_id']); |
| 219 | 223 | // return $this->getRelations('product_categories'); |
| 220 | 224 | } |
| 225 | + public function getCategoriesWithName() { | |
| 226 | + return $this->hasMany(Category::className(), ['category_id' => 'category_id'])->viaTable('product_category', ['product_id' => 'product_id'])->joinWith('categoryNames'); | |
| 227 | +// return $this->getRelations('product_categories'); | |
| 228 | + } | |
| 221 | 229 | |
| 222 | 230 | public function getCategoriesNames() { |
| 223 | 231 | $result = []; |
| ... | ... | @@ -227,6 +235,10 @@ class Product extends \yii\db\ActiveRecord |
| 227 | 235 | return $result; |
| 228 | 236 | } |
| 229 | 237 | |
| 238 | + public function getVariantsWithFilters(){ | |
| 239 | + return $this->hasMany(ProductVariant::className(), ['product_id' => 'product_id'])->with('filters'); | |
| 240 | + } | |
| 241 | + | |
| 230 | 242 | public function getCategory() { |
| 231 | 243 | return $this->hasOne(Category::className(), ['category_id' => 'category_id'])->viaTable('product_category', ['product_id' => 'product_id']); |
| 232 | 244 | } | ... | ... |
common/modules/product/models/ProductImage.php
| ... | ... | @@ -54,7 +54,6 @@ class ProductImage extends \yii\db\ActiveRecord |
| 54 | 54 | 'product_id' => Yii::t('product', 'Product ID'), |
| 55 | 55 | 'product_variant_id' => Yii::t('product', 'Product Variant ID'), |
| 56 | 56 | 'product' => Yii::t('product', 'Product'), |
| 57 | - 'product' => Yii::t('product', 'Product'), | |
| 58 | 57 | 'product_variant' => Yii::t('product', 'Product Variant'), |
| 59 | 58 | 'image' => Yii::t('product', 'Image'), |
| 60 | 59 | 'alt' => Yii::t('product', 'Alt'), | ... | ... |
common/modules/product/models/ProductVariant.php
| ... | ... | @@ -2,6 +2,7 @@ |
| 2 | 2 | |
| 3 | 3 | namespace common\modules\product\models; |
| 4 | 4 | |
| 5 | +use common\modules\product\behaviors\FilterBehavior; | |
| 5 | 6 | use common\modules\relation\relationBehavior; |
| 6 | 7 | use common\modules\rubrication\models\TaxOption; |
| 7 | 8 | use Yii; |
| ... | ... | @@ -52,7 +53,7 @@ class ProductVariant extends \yii\db\ActiveRecord |
| 52 | 53 | 'relations' => [ |
| 53 | 54 | 'product_variant_option' => 'entity1' // Product variant options |
| 54 | 55 | ] |
| 55 | - ] | |
| 56 | + ], | |
| 56 | 57 | ]; |
| 57 | 58 | } |
| 58 | 59 | |
| ... | ... | @@ -141,6 +142,14 @@ class ProductVariant extends \yii\db\ActiveRecord |
| 141 | 142 | return is_null($this->stock) ? '∞' : ($this->stock > 0 ? Yii::t('product', 'Enable') : Yii::t('product', 'Disable')); // intval($this->stock); |
| 142 | 143 | } |
| 143 | 144 | |
| 145 | + public function getFilters(){ | |
| 146 | + | |
| 147 | + return $this->hasMany(TaxOption::className(), ['tax_option_id' => 'option_id']) | |
| 148 | + ->viaTable('product_variant_option',[ 'product_variant_id'=> 'product_variant_id']) | |
| 149 | + ->joinWith('taxGroup'); | |
| 150 | + } | |
| 151 | + | |
| 152 | + | |
| 144 | 153 | /** |
| 145 | 154 | * @return \yii\db\ActiveQuery |
| 146 | 155 | */ | ... | ... |
common/modules/rubrication/controllers/TaxOptionController.php
| ... | ... | @@ -76,10 +76,12 @@ class TaxOptionController extends Controller |
| 76 | 76 | $valueModelName = $this->getValueModelName($group); |
| 77 | 77 | $valueModel = new $valueModelName; |
| 78 | 78 | |
| 79 | - if ($model->load(Yii::$app->request->post()) && $valueModel->load(Yii::$app->request->post())) { | |
| 79 | + if ($model->load(Yii::$app->request->post())) { | |
| 80 | + | |
| 80 | 81 | $model->save(); |
| 81 | 82 | |
| 82 | 83 | $valueModel->tax_option_id = $model->tax_option_id; |
| 84 | + $valueModel->value = $model->name; | |
| 83 | 85 | $valueModel->save(); |
| 84 | 86 | |
| 85 | 87 | $model->default_value = $valueModel->tax_value_id; |
| ... | ... | @@ -112,9 +114,10 @@ class TaxOptionController extends Controller |
| 112 | 114 | $valueModelName = $this->getValueModelName($group); |
| 113 | 115 | $valueModel = $valueModelName::findOne($model->default_value); |
| 114 | 116 | |
| 115 | - if ($model->load(Yii::$app->request->post()) && $valueModel->load(Yii::$app->request->post())) { | |
| 117 | + if ($model->load(Yii::$app->request->post())) { | |
| 116 | 118 | $model->save(); |
| 117 | 119 | $valueModel->tax_option_id = $model->tax_option_id; |
| 120 | + $valueModel->value = $model->name; | |
| 118 | 121 | $valueModel->save(); |
| 119 | 122 | |
| 120 | 123 | $model->default_value = $valueModel->tax_value_id; | ... | ... |
common/modules/rubrication/models/TaxOption.php
| ... | ... | @@ -35,6 +35,8 @@ use yii\db\ActiveRecord; |
| 35 | 35 | class TaxOption extends \yii\db\ActiveRecord |
| 36 | 36 | { |
| 37 | 37 | public $_items_count; |
| 38 | + | |
| 39 | + | |
| 38 | 40 | /** |
| 39 | 41 | * @inheritdoc |
| 40 | 42 | */ |
| ... | ... | @@ -47,10 +49,11 @@ class TaxOption extends \yii\db\ActiveRecord |
| 47 | 49 | ], |
| 48 | 50 | 'slug' => [ |
| 49 | 51 | 'class' => 'common\behaviors\Slug', |
| 50 | - 'in_attribute' => 'ValueRenderFlash', | |
| 52 | + 'in_attribute' => 'name', | |
| 51 | 53 | 'out_attribute' => 'alias', |
| 52 | 54 | 'translit' => true |
| 53 | 55 | ], |
| 56 | + | |
| 54 | 57 | ]; |
| 55 | 58 | } |
| 56 | 59 | |
| ... | ... | @@ -68,7 +71,7 @@ class TaxOption extends \yii\db\ActiveRecord |
| 68 | 71 | public function rules() |
| 69 | 72 | { |
| 70 | 73 | return [ |
| 71 | - [['tax_group_id'], 'required'], | |
| 74 | + [['tax_group_id','name'], 'required'], | |
| 72 | 75 | [['tax_group_id', 'parent_id', 'sort', 'default_value'], 'integer'], |
| 73 | 76 | [['alias'], 'string', 'max' => 50], |
| 74 | 77 | [['tax_group_id'], 'exist', 'skipOnError' => true, 'targetClass' => TaxGroup::className(), 'targetAttribute' => ['tax_group_id' => 'tax_group_id']], |
| ... | ... | @@ -103,6 +106,7 @@ class TaxOption extends \yii\db\ActiveRecord |
| 103 | 106 | return $this->hasMany(TaxEntityRelation::className(), ['tax_option_id' => 'tax_option_id'])->inverseOf('taxOption'); |
| 104 | 107 | } |
| 105 | 108 | |
| 109 | + | |
| 106 | 110 | /** |
| 107 | 111 | * @return \yii\db\ActiveQuery |
| 108 | 112 | */ |
| ... | ... | @@ -151,6 +155,21 @@ class TaxOption extends \yii\db\ActiveRecord |
| 151 | 155 | return $this->hasMany(TaxOptionToOption::className(), ['tax_option2_id' => 'tax_option_id'])->inverseOf('taxOption2'); |
| 152 | 156 | } |
| 153 | 157 | |
| 158 | + | |
| 159 | + public function getTaxValueString(){ | |
| 160 | + return $this->hasOne(TaxValueString::className(), ['tax_option_id' => 'tax_option_id']); | |
| 161 | + } | |
| 162 | + | |
| 163 | + public function getName(){ | |
| 164 | + return (!empty($this->taxValueString)) ? $this->taxValueString->value : '' ; | |
| 165 | + } | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + public function setName($values){ | |
| 170 | + $this->name = $values; | |
| 171 | + } | |
| 172 | + | |
| 154 | 173 | /** |
| 155 | 174 | */ |
| 156 | 175 | public function getValue() | ... | ... |
common/modules/rubrication/views/tax-option/_form.php
| ... | ... | @@ -27,7 +27,9 @@ use common\modules\rubrication\helpers\RubricationHelper; |
| 27 | 27 | <?= $form->field($model, 'tax_group_id')->hiddenInput()->label('') ?> |
| 28 | 28 | <?php endif?> |
| 29 | 29 | |
| 30 | - <?php require(dirname(__FILE__) .'/value/_fields_'. $group->module .'.php')?> | |
| 30 | + | |
| 31 | + <?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?> | |
| 32 | +<!-- --><?php //require(dirname(__FILE__) .'/value/_fields_'. $group->module .'.php')?> | |
| 31 | 33 | |
| 32 | 34 | <?= $form->field($model, 'alias')->textInput(['maxlength' => true]) ?> |
| 33 | 35 | ... | ... |