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 | 133 | return $this->redirect(['view', 'id' => $model->product_id]); |
| 134 | 134 | } |
| 135 | 135 | } else { |
| 136 | - $groups = $model->category-> getTaxGroupsByLevel(0); | |
| 136 | + $groups = $model->getTaxGroupsByLevel(0); | |
| 137 | 137 | |
| 138 | 138 | return $this->render('update', [ |
| 139 | 139 | 'model' => $model, | ... | ... |
common/modules/product/controllers/VariantController.php
| ... | ... | @@ -96,7 +96,7 @@ class VariantController extends Controller |
| 96 | 96 | return $this->redirect(['index', 'product_id' => $product_id]); |
| 97 | 97 | } |
| 98 | 98 | } else { |
| 99 | - $groups = $model->category->getTaxGroupsByLevel(1); | |
| 99 | + $groups = $model->getTaxGroupsByLevel(1); | |
| 100 | 100 | |
| 101 | 101 | return $this->render('create', [ |
| 102 | 102 | 'model' => $model, |
| ... | ... | @@ -193,7 +193,7 @@ class VariantController extends Controller |
| 193 | 193 | |
| 194 | 194 | |
| 195 | 195 | } else { |
| 196 | - $groups = $model->category-> getTaxGroupsByLevel(1); | |
| 196 | + $groups = $model->getTaxGroupsByLevel(1); | |
| 197 | 197 | |
| 198 | 198 | return $this->render('update', [ |
| 199 | 199 | 'model' => $model, | ... | ... |
common/modules/product/models/Product.php
| ... | ... | @@ -12,6 +12,7 @@ use common\modules\rubrication\models\TaxOption; |
| 12 | 12 | use Yii; |
| 13 | 13 | use common\modules\relation\relationBehavior; |
| 14 | 14 | use yii\db\ActiveRecord; |
| 15 | +use yii\helpers\ArrayHelper; | |
| 15 | 16 | |
| 16 | 17 | /** |
| 17 | 18 | * This is the model class for table "{{%product}}". |
| ... | ... | @@ -413,4 +414,10 @@ class Product extends \yii\db\ActiveRecord |
| 413 | 414 | public function getAverageRating() { |
| 414 | 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 | 4 | |
| 5 | 5 | use common\modules\product\behaviors\FilterBehavior; |
| 6 | 6 | use common\modules\relation\relationBehavior; |
| 7 | +use common\modules\rubrication\models\TaxGroup; | |
| 7 | 8 | use common\modules\rubrication\models\TaxOption; |
| 8 | 9 | use Yii; |
| 10 | +use yii\db\ActiveQuery; | |
| 9 | 11 | use yii\helpers\ArrayHelper; |
| 10 | 12 | |
| 11 | 13 | /** |
| ... | ... | @@ -258,6 +260,16 @@ class ProductVariant extends \yii\db\ActiveRecord |
| 258 | 260 | public function getCategory() { |
| 259 | 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 | 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 | 127 | [ |
| 128 | 128 | 'prompt' => Yii::t('product', 'Unit'), |
| 129 | 129 | ])->label(Yii::t('product', 'Unit')) ?> |
| 130 | - | |
| 130 | + | |
| 131 | 131 | <?php if(isset($groups)) :?> |
| 132 | 132 | <?php foreach($groups->all() as $group) :?> |
| 133 | 133 | <?= $form->field($model, 'options')->checkboxList( | ... | ... |