Commit 21ce7afa7afd9888deef5a8e995c9c39efb51321
1 parent
321cea72
-Fix when cannot unset all options from product or variant
-Fix when product have no options its variants don't display during filtering by variant's options
Showing
6 changed files
with
25 additions
and
54 deletions
Show diff stats
common/modules/product/controllers/ManageController.php
| @@ -9,6 +9,7 @@ | @@ -9,6 +9,7 @@ | ||
| 9 | use Yii; | 9 | use Yii; |
| 10 | use common\modules\product\models\Product; | 10 | use common\modules\product\models\Product; |
| 11 | use common\modules\product\models\ProductSearch; | 11 | use common\modules\product\models\ProductSearch; |
| 12 | + use yii\helpers\VarDumper; | ||
| 12 | use yii\web\Controller; | 13 | use yii\web\Controller; |
| 13 | use yii\web\NotFoundHttpException; | 14 | use yii\web\NotFoundHttpException; |
| 14 | use yii\filters\VerbFilter; | 15 | use yii\filters\VerbFilter; |
| @@ -125,7 +126,9 @@ | @@ -125,7 +126,9 @@ | ||
| 125 | public function actionUpdate($id) | 126 | public function actionUpdate($id) |
| 126 | { | 127 | { |
| 127 | $model = $this->findModel($id); | 128 | $model = $this->findModel($id); |
| 129 | + | ||
| 128 | if($model->load(Yii::$app->request->post())) { | 130 | if($model->load(Yii::$app->request->post())) { |
| 131 | + $model->unlinkAll('options',true); | ||
| 129 | $model->imagesUpload = UploadedFile::getInstances($model, 'imagesUpload'); | 132 | $model->imagesUpload = UploadedFile::getInstances($model, 'imagesUpload'); |
| 130 | if($model->save()) { | 133 | if($model->save()) { |
| 131 | if(!empty( $model->imagesUpload ) && ( ( $images = $model->imagesUpload() ) !== false )) { | 134 | if(!empty( $model->imagesUpload ) && ( ( $images = $model->imagesUpload() ) !== false )) { |
common/modules/product/controllers/VariantController.php
| @@ -182,6 +182,7 @@ class VariantController extends Controller | @@ -182,6 +182,7 @@ class VariantController extends Controller | ||
| 182 | { | 182 | { |
| 183 | $model = $this->findModel($id); | 183 | $model = $this->findModel($id); |
| 184 | if ($model->load(Yii::$app->request->post())) { | 184 | if ($model->load(Yii::$app->request->post())) { |
| 185 | + $model->unlinkAll('options',true); | ||
| 185 | 186 | ||
| 186 | if ($model->save()) { | 187 | if ($model->save()) { |
| 187 | 188 |
common/modules/product/helpers/ProductHelper.php
| @@ -251,17 +251,21 @@ | @@ -251,17 +251,21 @@ | ||
| 251 | Product::tableName() . '.product_id IN ( | 251 | Product::tableName() . '.product_id IN ( |
| 252 | SELECT DISTINCT products | 252 | SELECT DISTINCT products |
| 253 | FROM ( | 253 | FROM ( |
| 254 | - SELECT product_id AS products | 254 | + SELECT product_id AS products FROM product |
| 255 | + WHERE | ||
| 256 | + product_id IN ( | ||
| 257 | + SELECT product_id | ||
| 255 | FROM product_option | 258 | FROM product_option |
| 256 | INNER JOIN tax_option ON tax_option.tax_option_id = product_option.option_id | 259 | INNER JOIN tax_option ON tax_option.tax_option_id = product_option.option_id |
| 257 | INNER JOIN tax_group ON tax_group.tax_group_id = tax_option.tax_group_id | 260 | INNER JOIN tax_group ON tax_group.tax_group_id = tax_option.tax_group_id |
| 258 | - WHERE tax_group.alias LIKE \''. $key .'\' AND tax_option.alias IN (\'' . implode('\',\'', $param) . '\') OR product_id IN ( | ||
| 259 | - (SELECT product_id AS products | 261 | + WHERE tax_group.alias LIKE \''. $key .'\' AND tax_option.alias IN (\'' . implode('\',\'', $param) . '\')) |
| 262 | + OR product_id IN ( | ||
| 263 | + SELECT product_id | ||
| 260 | FROM product_variant_option | 264 | FROM product_variant_option |
| 261 | INNER JOIN product_variant ON product_variant_option.product_variant_id = product_variant.product_variant_id | 265 | INNER JOIN product_variant ON product_variant_option.product_variant_id = product_variant.product_variant_id |
| 262 | INNER JOIN tax_option ON tax_option.tax_option_id = product_variant_option.option_id | 266 | INNER JOIN tax_option ON tax_option.tax_option_id = product_variant_option.option_id |
| 263 | INNER JOIN tax_group ON tax_group.tax_group_id = tax_option.tax_group_id | 267 | INNER JOIN tax_group ON tax_group.tax_group_id = tax_option.tax_group_id |
| 264 | - WHERE tax_group.alias LIKE \''. $key .'\' AND tax_option.alias IN (\'' . implode('\',\'', $param) . '\')) | 268 | + WHERE tax_group.alias LIKE \''. $key .'\' AND tax_option.alias IN (\'' . implode('\',\'', $param) . '\') |
| 265 | ) | 269 | ) |
| 266 | ) AS table_name | 270 | ) AS table_name |
| 267 | )' | 271 | )' |
common/modules/product/models/Product.php
| @@ -13,7 +13,8 @@ | @@ -13,7 +13,8 @@ | ||
| 13 | use yii\db\ActiveRecord; | 13 | use yii\db\ActiveRecord; |
| 14 | use yii\helpers\ArrayHelper; | 14 | use yii\helpers\ArrayHelper; |
| 15 | use common\behaviors\DefaultVariantBehavior; | 15 | use common\behaviors\DefaultVariantBehavior; |
| 16 | - | 16 | + use yii\helpers\VarDumper; |
| 17 | + | ||
| 17 | /** | 18 | /** |
| 18 | * This is the model class for table "{{%product}}". | 19 | * This is the model class for table "{{%product}}". |
| 19 | * @property string $name | 20 | * @property string $name |
| @@ -388,51 +389,7 @@ | @@ -388,51 +389,7 @@ | ||
| 388 | ->sum('quantity'); | 389 | ->sum('quantity'); |
| 389 | } | 390 | } |
| 390 | 391 | ||
| 391 | -// public function afterSave($insert, $changedAttributes) | ||
| 392 | -// { | ||
| 393 | -// parent::afterSave($insert, $changedAttributes); | ||
| 394 | -// | ||
| 395 | -// $this->unlinkAll('categories', true); | ||
| 396 | -// $this->unlinkAll('options', true); | ||
| 397 | -// | ||
| 398 | -// if($this->_categories) { | ||
| 399 | -// $categories = Category::findAll($this->_categories); | ||
| 400 | -// foreach($categories as $category) { | ||
| 401 | -// $this->link('categories', $category); | ||
| 402 | -// } | ||
| 403 | -// } | ||
| 404 | -// $options = TaxOption::findAll($this->_options); | ||
| 405 | -// | ||
| 406 | -// foreach($options as $option) { | ||
| 407 | -// $this->link('options', $option); | ||
| 408 | -// } | ||
| 409 | -// | ||
| 410 | -// | ||
| 411 | -// if(!empty( $this->_variants )) { | ||
| 412 | -// $todel = []; | ||
| 413 | -// foreach($this->variants ? : [] as $_variant) { | ||
| 414 | -// $todel[ $_variant->product_variant_id ] = $_variant->product_variant_id; | ||
| 415 | -// } | ||
| 416 | -// foreach($this->_variants as $_variant) { | ||
| 417 | -// if(!is_array($_variant)) { | ||
| 418 | -// return; | ||
| 419 | -// } | ||
| 420 | -// if(!empty( $_variant[ 'product_variant_id' ] )) { | ||
| 421 | -// unset( $todel[ $_variant[ 'product_variant_id' ] ] ); | ||
| 422 | -// $model = ProductVariant::findOne($_variant[ 'product_variant_id' ]); | ||
| 423 | -// } else { | ||
| 424 | -// $model = new ProductVariant(); | ||
| 425 | -// } | ||
| 426 | -// $_variant[ 'product_id' ] = $this->product_id; | ||
| 427 | -// $model->load([ 'ProductVariant' => $_variant ]); | ||
| 428 | -// $model->product_id = $this->product_id; | ||
| 429 | -// $model->save(); | ||
| 430 | -// } | ||
| 431 | -// if(!empty( $todel )) { | ||
| 432 | -// ProductVariant::deleteAll([ 'product_variant_id' => $todel ]); | ||
| 433 | -// } | ||
| 434 | -// } | ||
| 435 | -// } | 392 | + |
| 436 | public function afterSave($insert, $changedAttributes) | 393 | public function afterSave($insert, $changedAttributes) |
| 437 | { | 394 | { |
| 438 | parent::afterSave($insert, $changedAttributes); | 395 | parent::afterSave($insert, $changedAttributes); |
| @@ -446,13 +403,18 @@ | @@ -446,13 +403,18 @@ | ||
| 446 | } | 403 | } |
| 447 | } | 404 | } |
| 448 | 405 | ||
| 449 | - if(!empty($this->options)){ | ||
| 450 | - $options = TaxOption::findAll($this->options); | ||
| 451 | - $this->unlinkAll('options',true); | 406 | + |
| 407 | + $options = TaxOption::findAll($this->options); | ||
| 408 | +// VarDumper::dump($this->options, 10, true); | ||
| 409 | +// die(); | ||
| 410 | + $this->unlinkAll('options',true); | ||
| 411 | + if(is_array($options)){ | ||
| 452 | foreach($options as $option){ | 412 | foreach($options as $option){ |
| 453 | $this->link('options', $option); | 413 | $this->link('options', $option); |
| 454 | } | 414 | } |
| 455 | } | 415 | } |
| 416 | + | ||
| 417 | + | ||
| 456 | 418 | ||
| 457 | 419 | ||
| 458 | if (!empty($this->_variants)) { | 420 | if (!empty($this->_variants)) { |
frontend/controllers/CatalogController.php
| @@ -111,7 +111,7 @@ class CatalogController extends \yii\web\Controller | @@ -111,7 +111,7 @@ class CatalogController extends \yii\web\Controller | ||
| 111 | $productModel = new ProductFrontendSearch(); | 111 | $productModel = new ProductFrontendSearch(); |
| 112 | //$productQuery = $productModel->getSearchQuery($category, $params); | 112 | //$productQuery = $productModel->getSearchQuery($category, $params); |
| 113 | $productProvider = $productModel->search($category, $params); | 113 | $productProvider = $productModel->search($category, $params); |
| 114 | - | 114 | + |
| 115 | $brandModel = new BrandSearch(); | 115 | $brandModel = new BrandSearch(); |
| 116 | $brands = $brandModel->getBrands($category, $params) | 116 | $brands = $brandModel->getBrands($category, $params) |
| 117 | ->all(); | 117 | ->all(); |
frontend/models/ProductFrontendSearch.php
| @@ -98,6 +98,7 @@ class ProductFrontendSearch extends Product { | @@ -98,6 +98,7 @@ class ProductFrontendSearch extends Product { | ||
| 98 | /** @var ActiveQuery $query */ | 98 | /** @var ActiveQuery $query */ |
| 99 | // $query = $category->getRelations('product_categories'); | 99 | // $query = $category->getRelations('product_categories'); |
| 100 | $query = $category->getBaccaraProducts(); | 100 | $query = $category->getBaccaraProducts(); |
| 101 | + | ||
| 101 | } else { | 102 | } else { |
| 102 | $query = Product::find(); | 103 | $query = Product::find(); |
| 103 | } | 104 | } |