From 52aea36a7d9882430aa345a882741cbb1ba45ece Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Mon, 15 Aug 2016 13:16:09 +0300 Subject: [PATCH] big commti --- backend/views/layouts/main-sidebar.php | 5 ----- common/modules/product/models/Product.php | 2 +- common/modules/product/models/ProductVariant.php | 2 +- common/modules/product/models/TaxGroupToCategory.php | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ common/modules/product/views/manage/_form.php | 52 ---------------------------------------------------- console/migrations/m160815_101433_add_name_to_category.php | 16 ++++++++++++++++ console/migrations/m160815_101441_add_name_to_brand.php | 16 ++++++++++++++++ 7 files changed, 102 insertions(+), 59 deletions(-) create mode 100644 common/modules/product/models/TaxGroupToCategory.php create mode 100644 console/migrations/m160815_101433_add_name_to_category.php create mode 100644 console/migrations/m160815_101441_add_name_to_brand.php diff --git a/backend/views/layouts/main-sidebar.php b/backend/views/layouts/main-sidebar.php index a8a5d83..b27b1d8 100755 --- a/backend/views/layouts/main-sidebar.php +++ b/backend/views/layouts/main-sidebar.php @@ -74,11 +74,6 @@ use yii\widgets\Menu; 'label' => 'Характеристики Модификаций', 'url' => Url::toRoute(['/rubrication/tax-group', 'level'=> '1']), 'options' => ['class'=>\Yii::$app->user->can('rubrication') ? '' :'hide'], - ], - [ - 'label' => 'Зависимости', - 'url' => ['/relation/manage'], - 'options' => ['class'=>\Yii::$app->user->can('relation') ? '' :'hide'], ] ] ], diff --git a/common/modules/product/models/Product.php b/common/modules/product/models/Product.php index 6b05538..62f2003 100755 --- a/common/modules/product/models/Product.php +++ b/common/modules/product/models/Product.php @@ -433,6 +433,6 @@ class Product extends \yii\db\ActiveRecord public function getTaxGroupsByLevel($level) { $categories = ArrayHelper::getColumn($this->categories, 'category_id'); - return TaxGroup::find()->distinct()->innerJoin('relation', 'entity1_id = tax_group_id')->andWhere(['relation.entity2_id' => $categories])->andWhere(['level' => $level]); + return TaxGroup::find()->distinct()->innerJoin('tax_group_to_category', 'tax_group_to_category.tax_group_id = tax_group.tax_group_id')->andWhere(['tax_group_to_category.category_id' => $categories])->andWhere(['level' => $level]); } } diff --git a/common/modules/product/models/ProductVariant.php b/common/modules/product/models/ProductVariant.php index 52809f4..aa42bec 100755 --- a/common/modules/product/models/ProductVariant.php +++ b/common/modules/product/models/ProductVariant.php @@ -252,7 +252,7 @@ class ProductVariant extends \yii\db\ActiveRecord public function getTaxGroupsByLevel($level) { $categories = ArrayHelper::getColumn($this->categories, 'category_id'); - return TaxGroup::find()->distinct()->innerJoin('relation', 'entity1_id = tax_group_id')->where(['relation.entity2_id' => $categories])->where(['level' => $level]); + return TaxGroup::find()->distinct()->innerJoin('tax_group_to_category', 'tax_group_to_category.tax_group_id = tax_group.tax_group_id')->where(['tax_group_to_category.category_id' => $categories])->where(['level' => $level]); } // public function afterSave($insert, $changedAttributes) diff --git a/common/modules/product/models/TaxGroupToCategory.php b/common/modules/product/models/TaxGroupToCategory.php new file mode 100644 index 0000000..b822aa8 --- /dev/null +++ b/common/modules/product/models/TaxGroupToCategory.php @@ -0,0 +1,68 @@ + true, 'targetClass' => Category::className(), 'targetAttribute' => ['category_id' => 'category_id']], + [['tax_group_id'], 'exist', 'skipOnError' => true, 'targetClass' => TaxGroup::className(), 'targetAttribute' => ['tax_group_id' => 'tax_group_id']], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'tax_group_to_category_id' => 'Tax Group To Category ID', + 'tax_group_id' => 'Tax Group ID', + 'category_id' => 'Category ID', + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getCategory() + { + return $this->hasOne(Category::className(), ['category_id' => 'category_id']); + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getTaxGroup() + { + return $this->hasOne(TaxGroup::className(), ['tax_group_id' => 'tax_group_id']); + } +} diff --git a/common/modules/product/views/manage/_form.php b/common/modules/product/views/manage/_form.php index 06ed762..6c7f33f 100755 --- a/common/modules/product/views/manage/_form.php +++ b/common/modules/product/views/manage/_form.php @@ -66,58 +66,6 @@ use kartik\select2\Select2; ], ]); ?> - field($model, 'variants')->widget(MultipleInput::className(), [ - 'columns' => [ - [ - 'name' => 'product_variant_id', - 'type' => MultipleInputColumn::TYPE_HIDDEN_INPUT, - ], - [ - 'name' => 'name', - 'type' => MultipleInputColumn::TYPE_TEXT_INPUT, - 'title' => Yii::t('product', 'Name'), - ], - [ - 'name' => 'sku', - 'type' => MultipleInputColumn::TYPE_TEXT_INPUT, - 'title' => Yii::t('product', 'SKU'), - ], - [ - 'name' => 'price', - 'type' => MultipleInputColumn::TYPE_TEXT_INPUT, - 'title' => Yii::t('product', 'Price'), - ], - [ - 'name' => 'price_old', - 'type' => MultipleInputColumn::TYPE_TEXT_INPUT, - 'title' => Yii::t('product', 'Old Price'), - ], - [ - 'name' => 'product_unit_id', - 'type' => MultipleInputColumn::TYPE_DROPDOWN, - 'title' => Yii::t('product', 'Unit'), - 'items' => ArrayHelper::map(\common\modules\product\models\ProductUnit::find()->all(), 'product_unit_id', 'name'), - ], - [ - 'name' => 'stock', - 'type' => MultipleInputColumn::TYPE_TEXT_INPUT, - 'title' => Yii::t('product', 'Stock'), - 'options' => [ - 'placeholder' => '∞' - ], - ], - [ - 'name' => 'image', - 'type' => 'fileInput', - 'title' => Yii::t('product', 'Image'), - 'options' => [ - 'multiple' => false - ], - ], - ], - ]); - */ ?> - all() as $group) :?> field($model, 'options')->checkboxList( diff --git a/console/migrations/m160815_101433_add_name_to_category.php b/console/migrations/m160815_101433_add_name_to_category.php new file mode 100644 index 0000000..fe3db3d --- /dev/null +++ b/console/migrations/m160815_101433_add_name_to_category.php @@ -0,0 +1,16 @@ +addColumn('category', 'name', $this->string(255)); + } + + public function down() + { + $this->dropColumn('category', 'name'); + } +} diff --git a/console/migrations/m160815_101441_add_name_to_brand.php b/console/migrations/m160815_101441_add_name_to_brand.php new file mode 100644 index 0000000..2fea94e --- /dev/null +++ b/console/migrations/m160815_101441_add_name_to_brand.php @@ -0,0 +1,16 @@ +addColumn('brand', 'name', $this->string(255)); + } + + public function down() + { + $this->dropColumn('brand', 'name'); + } +} -- libgit2 0.21.4