diff --git a/backend/config/bootstrap.php b/backend/config/bootstrap.php index 5005cb3..1924a47 100755 --- a/backend/config/bootstrap.php +++ b/backend/config/bootstrap.php @@ -6,4 +6,4 @@ Yii::setAlias('@uploadFilePricesAway', 'price_product_away.csv'); Yii::setAlias('@uploadFilePricesDuplicate', 'price_duplicate.csv'); Yii::setAlias('@uploadFilePricesNoVariant', 'price_no_variant.csv'); -Yii::setAlias('@productsDir', '@frontend/web/images/products'); \ No newline at end of file +Yii::setAlias('@productsDir', '@storage/products'); \ No newline at end of file diff --git a/common/modules/product/behaviors/FilterBehavior.php b/common/modules/product/behaviors/FilterBehavior.php new file mode 100755 index 0000000..26a3b0a --- /dev/null +++ b/common/modules/product/behaviors/FilterBehavior.php @@ -0,0 +1,24 @@ +owner->hasMany(TaxOption::className(), ['tax_option_id' => 'option_id']) + ->viaTable(ProductOption::tableName(),[ 'product_id'=> $this->owner->tableSchema->primaryKey[0]]) + ->joinWith('taxGroup')->all(); + } + + +} \ No newline at end of file diff --git a/common/modules/product/models/Export.php b/common/modules/product/models/Export.php index ce9dcb0..aa29e87 100755 --- a/common/modules/product/models/Export.php +++ b/common/modules/product/models/Export.php @@ -4,6 +4,7 @@ namespace common\modules\product\models; use common\modules\product\helpers\ProductHelper; use yii\base\Model; +use yii\helpers\ArrayHelper; class Export extends Model { public $errors = []; @@ -15,59 +16,66 @@ class Export extends Model { } setlocale(LC_ALL, 'ru_RU.CP1251'); $handle = fopen($dirName .'/'. $filename, "w"); - $products = Product::find()->joinWith(['variants'])->where(['!=', ProductVariant::tableName() .'.stock', 0])->select('product.product_id')->all(); + ///$products = Product::find()->joinWith(['variants'])->where(['!=', ProductVariant::tableName() .'.stock', 0])->select('product.product_id')->all(); + $products = Product::find() + ->with(['variantsWithFilters','brand','categoriesWithName'])->all(); + $i = 0; - foreach ($products as $product_id) + foreach ($products as $product) { - $product = Product::findOne($product_id); + + $i++; /*if ($i>1e2) { break; }*/ $mods = []; - foreach ($product->enabledVariants as $variant) + $filterString = $this->convertFilterToString($product->getFilters()); + + foreach ($product->variantsWithFilters as $variant) { - $size = $color = ''; - if ($product->product_variant_type_id) { - $productVariantType = ProductVariantType::findOne($product->product_variant_type_id); - if ($productVariantType) { - if ($productVariantType->product_variant_type_id == ProductHelper::PRODUCT_VARIANT_TYPE_COLOR) { - $color = $product->name; - } elseif ($productVariantType->product_variant_type_id == ProductHelper::PRODUCT_VARIANT_TYPE_SIZE) { - $size = $product->name; - } - } - } - $mods[] = $variant->sku . '=' . $size . '=' . $color . '=' . $variant->imageUrl; + + $color = $variant->name; + + $mods[] = $variant->sku . + '=' . $this->convertFilterToString($variant->filters) . + '=' . $color . + '=' . ((!empty($variant->image)) ? $variant->image->image: ''). + '=' . $variant->stock; } $fotos = []; - foreach ($product->images as $image) - { - $fotos[] = $image->imageUrl; +// foreach ($product->images as $image) +// { +// $fotos[] = $image->imageUrl; +// } + +// $filters = $product->properties; + $categories = []; + foreach($product->categoriesWithName as $value){ + $categorName = ArrayHelper::getColumn($value->categoryNames,'value'); + $categories[] = $categorName[0]; + } - $filters = $product->properties; + + $categories = implode(',',$categories); $list = [ - $product->category->name, + $categories, $product->brand->name, $product->name, '', ((! empty($product->description)) ? $product->description : ''), - ((! empty($filters[ProductHelper::PRODUCT_TAX_GROUP_ID_TARGET])) ? implode (',', $filters[ProductHelper::PRODUCT_TAX_GROUP_ID_TARGET]) : ''), - '', - ((! empty($filters[ProductHelper::PRODUCT_TAX_GROUP_ID_SEX])) ? implode (',', $filters[ProductHelper::PRODUCT_TAX_GROUP_ID_SEX]) : ''), - ((! empty($filters[ProductHelper::PRODUCT_TAX_GROUP_ID_YEAR])) ? implode (',', $filters[ProductHelper::PRODUCT_TAX_GROUP_ID_YEAR]) : ''), - $product->price_old, - $product->price, + $filterString, + (!empty($product->variant)) ? $product->variant->price_old : '', + (!empty($product->variant)) ? $product->variant->price : '', intval($product->akciya), '', intval($product->new), intval($product->top), - '', $product->video, implode (',', $fotos), ]; @@ -77,11 +85,30 @@ class Export extends Model { $cell = iconv("UTF-8", "WINDOWS-1251", $cell); } + fputcsv($handle, $to_write, ';'); } + + fclose ($handle); return $dirName .'/'. $filename; } + + + public function convertFilterToString($filters){ + $fittersArray = []; + foreach($filters as $filter){ + $fittersArray[$filter->taxGroup->alias][] = $filter->name; + } + $filterString=[]; + + foreach($fittersArray as $filterName =>$filterRows ){ + $row = implode(',',$filterRows); + $filterString[] = "[{$filterName}:{$row}]"; + + } + return implode('*',$filterString); + } } \ No newline at end of file diff --git a/common/modules/product/models/Import.php b/common/modules/product/models/Import.php index 9e95c1d..c46f011 100755 --- a/common/modules/product/models/Import.php +++ b/common/modules/product/models/Import.php @@ -542,7 +542,7 @@ class Import extends Model { // Create option $option = new TaxOption(); $option->tax_group_id = $taxGroup->tax_group_id; - $option->alias = $filter_options; + $option->name = $filter_options; $option->save(); $value = new TaxValueString(); diff --git a/common/modules/product/models/Product.php b/common/modules/product/models/Product.php index 3ebc468..efa99e3 100755 --- a/common/modules/product/models/Product.php +++ b/common/modules/product/models/Product.php @@ -3,6 +3,7 @@ namespace common\modules\product\models; use common\behaviors\Slug; +use common\modules\product\behaviors\FilterBehavior; use common\modules\rubrication\models\TaxGroup; use common\modules\rubrication\models\TaxOption; use Yii; @@ -53,6 +54,9 @@ class Product extends \yii\db\ActiveRecord ] ], [ + 'class' =>FilterBehavior::className(), + ], + [ 'class' => Slug::className(), 'in_attribute' => 'name', 'out_attribute' => 'alias', @@ -218,6 +222,10 @@ class Product extends \yii\db\ActiveRecord return $this->hasMany(Category::className(), ['category_id' => 'category_id'])->viaTable('product_category', ['product_id' => 'product_id']); // return $this->getRelations('product_categories'); } + public function getCategoriesWithName() { + return $this->hasMany(Category::className(), ['category_id' => 'category_id'])->viaTable('product_category', ['product_id' => 'product_id'])->joinWith('categoryNames'); +// return $this->getRelations('product_categories'); + } public function getCategoriesNames() { $result = []; @@ -227,6 +235,10 @@ class Product extends \yii\db\ActiveRecord return $result; } + public function getVariantsWithFilters(){ + return $this->hasMany(ProductVariant::className(), ['product_id' => 'product_id'])->with('filters'); + } + public function getCategory() { return $this->hasOne(Category::className(), ['category_id' => 'category_id'])->viaTable('product_category', ['product_id' => 'product_id']); } diff --git a/common/modules/product/models/ProductImage.php b/common/modules/product/models/ProductImage.php index 617ee8c..e7ece0f 100755 --- a/common/modules/product/models/ProductImage.php +++ b/common/modules/product/models/ProductImage.php @@ -54,7 +54,6 @@ class ProductImage extends \yii\db\ActiveRecord 'product_id' => Yii::t('product', 'Product ID'), 'product_variant_id' => Yii::t('product', 'Product Variant ID'), 'product' => Yii::t('product', 'Product'), - 'product' => Yii::t('product', 'Product'), 'product_variant' => Yii::t('product', 'Product Variant'), 'image' => Yii::t('product', 'Image'), 'alt' => Yii::t('product', 'Alt'), diff --git a/common/modules/product/models/ProductVariant.php b/common/modules/product/models/ProductVariant.php index 146e6e7..9534e2b 100755 --- a/common/modules/product/models/ProductVariant.php +++ b/common/modules/product/models/ProductVariant.php @@ -2,6 +2,7 @@ namespace common\modules\product\models; +use common\modules\product\behaviors\FilterBehavior; use common\modules\relation\relationBehavior; use common\modules\rubrication\models\TaxOption; use Yii; @@ -52,7 +53,7 @@ class ProductVariant extends \yii\db\ActiveRecord 'relations' => [ 'product_variant_option' => 'entity1' // Product variant options ] - ] + ], ]; } @@ -141,6 +142,14 @@ class ProductVariant extends \yii\db\ActiveRecord return is_null($this->stock) ? '∞' : ($this->stock > 0 ? Yii::t('product', 'Enable') : Yii::t('product', 'Disable')); // intval($this->stock); } + public function getFilters(){ + + return $this->hasMany(TaxOption::className(), ['tax_option_id' => 'option_id']) + ->viaTable('product_variant_option',[ 'product_variant_id'=> 'product_variant_id']) + ->joinWith('taxGroup'); + } + + /** * @return \yii\db\ActiveQuery */ diff --git a/common/modules/rubrication/controllers/TaxOptionController.php b/common/modules/rubrication/controllers/TaxOptionController.php index e136479..e94a90c 100755 --- a/common/modules/rubrication/controllers/TaxOptionController.php +++ b/common/modules/rubrication/controllers/TaxOptionController.php @@ -76,10 +76,12 @@ class TaxOptionController extends Controller $valueModelName = $this->getValueModelName($group); $valueModel = new $valueModelName; - if ($model->load(Yii::$app->request->post()) && $valueModel->load(Yii::$app->request->post())) { + if ($model->load(Yii::$app->request->post())) { + $model->save(); $valueModel->tax_option_id = $model->tax_option_id; + $valueModel->value = $model->name; $valueModel->save(); $model->default_value = $valueModel->tax_value_id; @@ -112,9 +114,10 @@ class TaxOptionController extends Controller $valueModelName = $this->getValueModelName($group); $valueModel = $valueModelName::findOne($model->default_value); - if ($model->load(Yii::$app->request->post()) && $valueModel->load(Yii::$app->request->post())) { + if ($model->load(Yii::$app->request->post())) { $model->save(); $valueModel->tax_option_id = $model->tax_option_id; + $valueModel->value = $model->name; $valueModel->save(); $model->default_value = $valueModel->tax_value_id; diff --git a/common/modules/rubrication/models/TaxOption.php b/common/modules/rubrication/models/TaxOption.php index a5f1404..7a05c44 100755 --- a/common/modules/rubrication/models/TaxOption.php +++ b/common/modules/rubrication/models/TaxOption.php @@ -35,6 +35,8 @@ use yii\db\ActiveRecord; class TaxOption extends \yii\db\ActiveRecord { public $_items_count; + + /** * @inheritdoc */ @@ -47,10 +49,11 @@ class TaxOption extends \yii\db\ActiveRecord ], 'slug' => [ 'class' => 'common\behaviors\Slug', - 'in_attribute' => 'ValueRenderFlash', + 'in_attribute' => 'name', 'out_attribute' => 'alias', 'translit' => true ], + ]; } @@ -68,7 +71,7 @@ class TaxOption extends \yii\db\ActiveRecord public function rules() { return [ - [['tax_group_id'], 'required'], + [['tax_group_id','name'], 'required'], [['tax_group_id', 'parent_id', 'sort', 'default_value'], 'integer'], [['alias'], 'string', 'max' => 50], [['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 return $this->hasMany(TaxEntityRelation::className(), ['tax_option_id' => 'tax_option_id'])->inverseOf('taxOption'); } + /** * @return \yii\db\ActiveQuery */ @@ -151,6 +155,21 @@ class TaxOption extends \yii\db\ActiveRecord return $this->hasMany(TaxOptionToOption::className(), ['tax_option2_id' => 'tax_option_id'])->inverseOf('taxOption2'); } + + public function getTaxValueString(){ + return $this->hasOne(TaxValueString::className(), ['tax_option_id' => 'tax_option_id']); + } + + public function getName(){ + return (!empty($this->taxValueString)) ? $this->taxValueString->value : '' ; + } + + + + public function setName($values){ + $this->name = $values; + } + /** */ public function getValue() diff --git a/common/modules/rubrication/views/tax-option/_form.php b/common/modules/rubrication/views/tax-option/_form.php index f11bad2..d73bcbd 100755 --- a/common/modules/rubrication/views/tax-option/_form.php +++ b/common/modules/rubrication/views/tax-option/_form.php @@ -27,7 +27,9 @@ use common\modules\rubrication\helpers\RubricationHelper; field($model, 'tax_group_id')->hiddenInput()->label('') ?> - module .'.php')?> + + field($model, 'name')->textInput(['maxlength' => true]) ?> +module .'.php')?> field($model, 'alias')->textInput(['maxlength' => true]) ?> -- libgit2 0.21.4