Commit 0dfd8fe287781babfec43868b3db6db8c2a1ddf9
1 parent
e8e6b858
Tax options fix
Showing
5 changed files
with
23 additions
and
4 deletions
Show diff stats
common/modules/product/controllers/ManageController.php
@@ -133,7 +133,7 @@ class ManageController extends Controller | @@ -133,7 +133,7 @@ class ManageController extends Controller | ||
133 | return $this->redirect(['view', 'id' => $model->product_id]); | 133 | return $this->redirect(['view', 'id' => $model->product_id]); |
134 | } | 134 | } |
135 | } else { | 135 | } else { |
136 | - $groups = $model->category-> getTaxGroupsByLevel(0); | 136 | + $groups = $model->getTaxGroupsByLevel(0); |
137 | 137 | ||
138 | return $this->render('update', [ | 138 | return $this->render('update', [ |
139 | 'model' => $model, | 139 | 'model' => $model, |
common/modules/product/controllers/VariantController.php
@@ -96,7 +96,7 @@ class VariantController extends Controller | @@ -96,7 +96,7 @@ class VariantController extends Controller | ||
96 | return $this->redirect(['index', 'product_id' => $product_id]); | 96 | return $this->redirect(['index', 'product_id' => $product_id]); |
97 | } | 97 | } |
98 | } else { | 98 | } else { |
99 | - $groups = $model->category->getTaxGroupsByLevel(1); | 99 | + $groups = $model->getTaxGroupsByLevel(1); |
100 | 100 | ||
101 | return $this->render('create', [ | 101 | return $this->render('create', [ |
102 | 'model' => $model, | 102 | 'model' => $model, |
@@ -193,7 +193,7 @@ class VariantController extends Controller | @@ -193,7 +193,7 @@ class VariantController extends Controller | ||
193 | 193 | ||
194 | 194 | ||
195 | } else { | 195 | } else { |
196 | - $groups = $model->category-> getTaxGroupsByLevel(1); | 196 | + $groups = $model->getTaxGroupsByLevel(1); |
197 | 197 | ||
198 | return $this->render('update', [ | 198 | return $this->render('update', [ |
199 | 'model' => $model, | 199 | 'model' => $model, |
common/modules/product/models/Product.php
@@ -12,6 +12,7 @@ use common\modules\rubrication\models\TaxOption; | @@ -12,6 +12,7 @@ use common\modules\rubrication\models\TaxOption; | ||
12 | use Yii; | 12 | use Yii; |
13 | use common\modules\relation\relationBehavior; | 13 | use common\modules\relation\relationBehavior; |
14 | use yii\db\ActiveRecord; | 14 | use yii\db\ActiveRecord; |
15 | +use yii\helpers\ArrayHelper; | ||
15 | 16 | ||
16 | /** | 17 | /** |
17 | * This is the model class for table "{{%product}}". | 18 | * This is the model class for table "{{%product}}". |
@@ -413,4 +414,10 @@ class Product extends \yii\db\ActiveRecord | @@ -413,4 +414,10 @@ class Product extends \yii\db\ActiveRecord | ||
413 | public function getAverageRating() { | 414 | public function getAverageRating() { |
414 | return $this->hasOne(ProductToRating::className(), ['product_id' => 'product_id']); | 415 | return $this->hasOne(ProductToRating::className(), ['product_id' => 'product_id']); |
415 | } | 416 | } |
417 | + | ||
418 | + public function getTaxGroupsByLevel($level) | ||
419 | + { | ||
420 | + $categories = ArrayHelper::getColumn($this->categories, 'category_id'); | ||
421 | + return TaxGroup::find()->distinct()->innerJoin('relation', 'entity1_id = tax_group_id')->where(['relation.entity2_id' => $categories])->where(['level' => $level]); | ||
422 | + } | ||
416 | } | 423 | } |
common/modules/product/models/ProductVariant.php
@@ -4,8 +4,10 @@ namespace common\modules\product\models; | @@ -4,8 +4,10 @@ namespace common\modules\product\models; | ||
4 | 4 | ||
5 | use common\modules\product\behaviors\FilterBehavior; | 5 | use common\modules\product\behaviors\FilterBehavior; |
6 | use common\modules\relation\relationBehavior; | 6 | use common\modules\relation\relationBehavior; |
7 | +use common\modules\rubrication\models\TaxGroup; | ||
7 | use common\modules\rubrication\models\TaxOption; | 8 | use common\modules\rubrication\models\TaxOption; |
8 | use Yii; | 9 | use Yii; |
10 | +use yii\db\ActiveQuery; | ||
9 | use yii\helpers\ArrayHelper; | 11 | use yii\helpers\ArrayHelper; |
10 | 12 | ||
11 | /** | 13 | /** |
@@ -258,6 +260,16 @@ class ProductVariant extends \yii\db\ActiveRecord | @@ -258,6 +260,16 @@ class ProductVariant extends \yii\db\ActiveRecord | ||
258 | public function getCategory() { | 260 | public function getCategory() { |
259 | return $this->hasOne(Category::className(), ['category_id' => 'category_id'])->viaTable('product_category', ['product_id' => 'product_id']); | 261 | return $this->hasOne(Category::className(), ['category_id' => 'category_id'])->viaTable('product_category', ['product_id' => 'product_id']); |
260 | } | 262 | } |
263 | + | ||
264 | + public function getCategories() { | ||
265 | + return $this->hasMany(Category::className(), ['category_id' => 'category_id'])->viaTable('product_category', ['product_id' => 'product_id']); | ||
266 | + } | ||
267 | + | ||
268 | + public function getTaxGroupsByLevel($level) | ||
269 | + { | ||
270 | + $categories = ArrayHelper::getColumn($this->categories, 'category_id'); | ||
271 | + return TaxGroup::find()->distinct()->innerJoin('relation', 'entity1_id = tax_group_id')->where(['relation.entity2_id' => $categories])->where(['level' => $level]); | ||
272 | + } | ||
261 | 273 | ||
262 | // public function afterSave($insert, $changedAttributes) | 274 | // public function afterSave($insert, $changedAttributes) |
263 | // { | 275 | // { |
common/modules/product/views/variant/_form.php
@@ -127,7 +127,7 @@ $this->registerJs($js, View::POS_END); | @@ -127,7 +127,7 @@ $this->registerJs($js, View::POS_END); | ||
127 | [ | 127 | [ |
128 | 'prompt' => Yii::t('product', 'Unit'), | 128 | 'prompt' => Yii::t('product', 'Unit'), |
129 | ])->label(Yii::t('product', 'Unit')) ?> | 129 | ])->label(Yii::t('product', 'Unit')) ?> |
130 | - | 130 | + |
131 | <?php if(isset($groups)) :?> | 131 | <?php if(isset($groups)) :?> |
132 | <?php foreach($groups->all() as $group) :?> | 132 | <?php foreach($groups->all() as $group) :?> |
133 | <?= $form->field($model, 'options')->checkboxList( | 133 | <?= $form->field($model, 'options')->checkboxList( |