Commit 66ff49d7ed230119efe817339056d030ee3daa69
1 parent
8e356b8c
-Sizes alpha test
Showing
5 changed files
with
95 additions
and
71 deletions
Show diff stats
controllers/BrandSizeController.php
@@ -8,6 +8,7 @@ | @@ -8,6 +8,7 @@ | ||
8 | use artweb\artbox\ecommerce\models\BrandSize; | 8 | use artweb\artbox\ecommerce\models\BrandSize; |
9 | use artweb\artbox\ecommerce\models\BrandSizeSearch; | 9 | use artweb\artbox\ecommerce\models\BrandSizeSearch; |
10 | use yii\helpers\ArrayHelper; | 10 | use yii\helpers\ArrayHelper; |
11 | + use yii\helpers\VarDumper; | ||
11 | use yii\web\Controller; | 12 | use yii\web\Controller; |
12 | use yii\web\NotFoundHttpException; | 13 | use yii\web\NotFoundHttpException; |
13 | use yii\filters\VerbFilter; | 14 | use yii\filters\VerbFilter; |
@@ -126,7 +127,7 @@ | @@ -126,7 +127,7 @@ | ||
126 | public function actionUpdate($id) | 127 | public function actionUpdate($id) |
127 | { | 128 | { |
128 | $model = $this->findModel($id); | 129 | $model = $this->findModel($id); |
129 | - | 130 | + |
130 | $categories = ArrayHelper::map( | 131 | $categories = ArrayHelper::map( |
131 | Category::find() | 132 | Category::find() |
132 | ->with('lang') | 133 | ->with('lang') |
models/BrandSize.php
@@ -69,7 +69,7 @@ class BrandSize extends \yii\db\ActiveRecord | @@ -69,7 +69,7 @@ class BrandSize extends \yii\db\ActiveRecord | ||
69 | */ | 69 | */ |
70 | public function getBrand() | 70 | public function getBrand() |
71 | { | 71 | { |
72 | - return $this->hasOne(Brand::className(), ['id' => 'brand_id']); | 72 | + return $this->hasOne(Brand::className(), ['id' => 'brand_id'])->with('lang'); |
73 | } | 73 | } |
74 | 74 | ||
75 | /** | 75 | /** |
models/Product.php
@@ -105,7 +105,7 @@ | @@ -105,7 +105,7 @@ | ||
105 | class Product extends ActiveRecord | 105 | class Product extends ActiveRecord |
106 | { | 106 | { |
107 | public $option_id; | 107 | public $option_id; |
108 | - | 108 | + |
109 | public $min; | 109 | public $min; |
110 | public $max; | 110 | public $max; |
111 | 111 | ||
@@ -283,20 +283,17 @@ | @@ -283,20 +283,17 @@ | ||
283 | { | 283 | { |
284 | return $this->getVariant(); | 284 | return $this->getVariant(); |
285 | } | 285 | } |
286 | - | ||
287 | - | ||
288 | - | ||
289 | - | ||
290 | - | 286 | + |
291 | /** | 287 | /** |
292 | * @return \yii\db\ActiveQuery | 288 | * @return \yii\db\ActiveQuery |
293 | */ | 289 | */ |
294 | - public function getEvents(){ | ||
295 | - return $this->hasMany(Event::className(), ['id' => 'event_id'])->viaTable('events_to_products', ['product_id' => 'id'])->where(['status'=>Event::ACTIVE]); | 290 | + public function getEvents() |
291 | + { | ||
292 | + return $this->hasMany(Event::className(), [ 'id' => 'event_id' ]) | ||
293 | + ->viaTable('events_to_products', [ 'product_id' => 'id' ]) | ||
294 | + ->where([ 'status' => Event::ACTIVE ]); | ||
296 | } | 295 | } |
297 | - | ||
298 | - | ||
299 | - | 296 | + |
300 | /** | 297 | /** |
301 | * Get ProductVariant query fetching only available in stock to current Product | 298 | * Get ProductVariant query fetching only available in stock to current Product |
302 | * | 299 | * |
@@ -332,21 +329,20 @@ | @@ -332,21 +329,20 @@ | ||
332 | ] | 329 | ] |
333 | ); | 330 | ); |
334 | } | 331 | } |
335 | - | ||
336 | - | ||
337 | - public function getMaxPrice(){ | 332 | + |
333 | + public function getMaxPrice() | ||
334 | + { | ||
338 | $price = 0; | 335 | $price = 0; |
339 | - if (!empty( $this->enabledVariants )) { | ||
340 | - foreach ( $this->enabledVariants as $variant){ | ||
341 | - if($variant->price > $price){ | 336 | + if (!empty($this->enabledVariants)) { |
337 | + foreach ($this->enabledVariants as $variant) { | ||
338 | + if ($variant->price > $price) { | ||
342 | $price = $variant->price; | 339 | $price = $variant->price; |
343 | } | 340 | } |
344 | } | 341 | } |
345 | } | 342 | } |
346 | return $price; | 343 | return $price; |
347 | } | 344 | } |
348 | - | ||
349 | - | 345 | + |
350 | /** | 346 | /** |
351 | * Get random ProductVariant price or 0 if not exist | 347 | * Get random ProductVariant price or 0 if not exist |
352 | * | 348 | * |
@@ -357,7 +353,7 @@ | @@ -357,7 +353,7 @@ | ||
357 | */ | 353 | */ |
358 | public function getVariantPrice(bool $exception = false): float | 354 | public function getVariantPrice(bool $exception = false): float |
359 | { | 355 | { |
360 | - if (!empty( $this->variant )) { | 356 | + if (!empty($this->variant)) { |
361 | return $this->variant->price; | 357 | return $this->variant->price; |
362 | } elseif ($exception) { | 358 | } elseif ($exception) { |
363 | throw new NotFoundHttpException('Product with ID ' . $this->id . ' hasn\'t got variants'); | 359 | throw new NotFoundHttpException('Product with ID ' . $this->id . ' hasn\'t got variants'); |
@@ -376,7 +372,7 @@ | @@ -376,7 +372,7 @@ | ||
376 | */ | 372 | */ |
377 | public function getEnabledVariantPrice(bool $exception = false): float | 373 | public function getEnabledVariantPrice(bool $exception = false): float |
378 | { | 374 | { |
379 | - if (!empty( $this->enabledVariant )) { | 375 | + if (!empty($this->enabledVariant)) { |
380 | return $this->enabledVariant->price; | 376 | return $this->enabledVariant->price; |
381 | } elseif ($exception) { | 377 | } elseif ($exception) { |
382 | throw new NotFoundHttpException('Product with ID ' . $this->id . ' hasn\'t got enabled variants'); | 378 | throw new NotFoundHttpException('Product with ID ' . $this->id . ' hasn\'t got enabled variants'); |
@@ -384,39 +380,53 @@ | @@ -384,39 +380,53 @@ | ||
384 | return 0; | 380 | return 0; |
385 | } | 381 | } |
386 | } | 382 | } |
387 | - | ||
388 | 383 | ||
389 | /** | 384 | /** |
390 | * Get Product name concatenated with Brand name | 385 | * Get Product name concatenated with Brand name |
391 | * | 386 | * |
392 | * @return string | 387 | * @return string |
393 | */ | 388 | */ |
394 | - public function getFullName():string | 389 | + public function getFullName(): string |
395 | { | 390 | { |
396 | $name = ''; | 391 | $name = ''; |
397 | - $groupName = (new Query())->select(['tax_option.*','tax_option_lang.*']) | ||
398 | - ->from([ 'tax_option' ]) | ||
399 | - ->innerJoin('tax_group', 'tax_group.id = tax_option.tax_group_id') | ||
400 | - ->innerJoin('tax_option_lang', 'tax_option.id = tax_option_lang.tax_option_id') | ||
401 | - ->innerJoin('tax_group_to_category', 'tax_group.id = tax_group_to_category.tax_group_id') | ||
402 | - ->where(['tax_group_to_category.category_id' => $this->category->id, 'tax_group.use_in_name'=>1, 'tax_option.id' => ArrayHelper::getColumn($this->options,'id')]) | ||
403 | - ->one(); | ||
404 | - | ||
405 | - | ||
406 | - if($groupName != null ){ | ||
407 | - $groupName = $groupName['value']; | 392 | + $groupName = ( new Query() )->select( |
393 | + [ | ||
394 | + 'tax_option.*', | ||
395 | + 'tax_option_lang.*', | ||
396 | + ] | ||
397 | + ) | ||
398 | + ->from([ 'tax_option' ]) | ||
399 | + ->innerJoin('tax_group', 'tax_group.id = tax_option.tax_group_id') | ||
400 | + ->innerJoin('tax_option_lang', 'tax_option.id = tax_option_lang.tax_option_id') | ||
401 | + ->innerJoin( | ||
402 | + 'tax_group_to_category', | ||
403 | + 'tax_group.id = tax_group_to_category.tax_group_id' | ||
404 | + ) | ||
405 | + ->where( | ||
406 | + [ | ||
407 | + 'tax_group_to_category.category_id' => $this->category->id, | ||
408 | + 'tax_group.use_in_name' => 1, | ||
409 | + 'tax_option.id' => ArrayHelper::getColumn( | ||
410 | + $this->options, | ||
411 | + 'id' | ||
412 | + ), | ||
413 | + ] | ||
414 | + ) | ||
415 | + ->one(); | ||
416 | + | ||
417 | + if ($groupName != NULL) { | ||
418 | + $groupName = $groupName[ 'value' ]; | ||
408 | } else { | 419 | } else { |
409 | $groupName = ''; | 420 | $groupName = ''; |
410 | } | 421 | } |
411 | - | ||
412 | - | ||
413 | - if (!empty( $this->category->lang->category_synonym )) { | ||
414 | - $name = $name . ($groupName ? $groupName : $this->category->lang->category_synonym) . ' '; | 422 | + |
423 | + if (!empty($this->category->lang->category_synonym)) { | ||
424 | + $name = $name . ( $groupName ? $groupName : $this->category->lang->category_synonym ) . ' '; | ||
415 | } else { | 425 | } else { |
416 | - $name = $name . ($groupName ? $groupName : $this->category->lang->title) . ' '; | 426 | + $name = $name . ( $groupName ? $groupName : $this->category->lang->title ) . ' '; |
417 | } | 427 | } |
418 | - | ||
419 | - if (!empty( $this->brand )) { | 428 | + |
429 | + if (!empty($this->brand)) { | ||
420 | $name = $name . $this->brand->lang->title . ' '; | 430 | $name = $name . $this->brand->lang->title . ' '; |
421 | } | 431 | } |
422 | $name .= $this->lang->title; | 432 | $name .= $this->lang->title; |
@@ -485,11 +495,10 @@ | @@ -485,11 +495,10 @@ | ||
485 | public function getOptions() | 495 | public function getOptions() |
486 | { | 496 | { |
487 | return $this->hasMany(TaxOption::className(), [ 'id' => 'option_id' ]) | 497 | return $this->hasMany(TaxOption::className(), [ 'id' => 'option_id' ]) |
488 | - ->viaTable('product_option', [ 'product_id' => 'id' ]); | ||
489 | - | 498 | + ->viaTable('product_option', [ 'product_id' => 'id' ]); |
499 | + | ||
490 | } | 500 | } |
491 | - | ||
492 | - | 501 | + |
493 | /** | 502 | /** |
494 | * Get TaxOptions query for current Product that will by used in filter | 503 | * Get TaxOptions query for current Product that will by used in filter |
495 | * | 504 | * |
@@ -497,13 +506,17 @@ | @@ -497,13 +506,17 @@ | ||
497 | */ | 506 | */ |
498 | public function getFilterOptions() | 507 | public function getFilterOptions() |
499 | { | 508 | { |
500 | - | 509 | + |
501 | return $this->getOptions() | 510 | return $this->getOptions() |
502 | - ->joinWith(['lang','taxGroup']) | ||
503 | - ->where(['is_filter' => true]); | 511 | + ->joinWith( |
512 | + [ | ||
513 | + 'lang', | ||
514 | + 'taxGroup', | ||
515 | + ] | ||
516 | + ) | ||
517 | + ->where([ 'is_filter' => true ]); | ||
504 | } | 518 | } |
505 | - | ||
506 | - | 519 | + |
507 | /** | 520 | /** |
508 | * Get TaxGroup for current Product | 521 | * Get TaxGroup for current Product |
509 | * | 522 | * |
@@ -511,11 +524,10 @@ | @@ -511,11 +524,10 @@ | ||
511 | */ | 524 | */ |
512 | public function getGroups() | 525 | public function getGroups() |
513 | { | 526 | { |
514 | - return $this->hasMany(TaxGroup::className(), [ 'id' => 'tax_group_id' ]) | ||
515 | - ->via('options'); | 527 | + return $this->hasMany(TaxGroup::className(), [ 'id' => 'tax_group_id' ]) |
528 | + ->via('options'); | ||
516 | } | 529 | } |
517 | - | ||
518 | - | 530 | + |
519 | /** | 531 | /** |
520 | * Get TaxOptions query for current Product joined with TaxGroups | 532 | * Get TaxOptions query for current Product joined with TaxGroups |
521 | * | 533 | * |
@@ -552,7 +564,7 @@ | @@ -552,7 +564,7 @@ | ||
552 | /** | 564 | /** |
553 | * @var TaxGroup $group | 565 | * @var TaxGroup $group |
554 | */ | 566 | */ |
555 | - if (!empty( $options[ $group->id ] )) { | 567 | + if (!empty($options[ $group->id ])) { |
556 | $group->customOptions = $options[ $group->id ]; | 568 | $group->customOptions = $options[ $group->id ]; |
557 | $groups[] = $group; | 569 | $groups[] = $group; |
558 | } | 570 | } |
@@ -593,7 +605,7 @@ | @@ -593,7 +605,7 @@ | ||
593 | * @see Product::getProductStocks() | 605 | * @see Product::getProductStocks() |
594 | * @return int | 606 | * @return int |
595 | */ | 607 | */ |
596 | - public function getQuantity():int | 608 | + public function getQuantity(): int |
597 | { | 609 | { |
598 | return $this->getProductStocks() | 610 | return $this->getProductStocks() |
599 | ->sum('quantity'); | 611 | ->sum('quantity'); |
@@ -607,10 +619,8 @@ | @@ -607,10 +619,8 @@ | ||
607 | public function afterSave($insert, $changedAttributes) | 619 | public function afterSave($insert, $changedAttributes) |
608 | { | 620 | { |
609 | parent::afterSave($insert, $changedAttributes); | 621 | parent::afterSave($insert, $changedAttributes); |
610 | - | ||
611 | - | ||
612 | - | ||
613 | - if (!empty( $this->categories )) { | 622 | + |
623 | + if (!empty($this->categories)) { | ||
614 | $categories = Category::findAll($this->categories); | 624 | $categories = Category::findAll($this->categories); |
615 | $this->unlinkAll('categories', true); | 625 | $this->unlinkAll('categories', true); |
616 | foreach ($categories as $category) { | 626 | foreach ($categories as $category) { |
@@ -618,7 +628,7 @@ | @@ -618,7 +628,7 @@ | ||
618 | } | 628 | } |
619 | } | 629 | } |
620 | 630 | ||
621 | - if (!empty( $this->options )) { | 631 | + if (!empty($this->options)) { |
622 | $options = TaxOption::findAll($this->options); | 632 | $options = TaxOption::findAll($this->options); |
623 | $this->unlinkAll('options', true); | 633 | $this->unlinkAll('options', true); |
624 | foreach ($options as $option) { | 634 | foreach ($options as $option) { |
@@ -664,7 +674,20 @@ | @@ -664,7 +674,20 @@ | ||
664 | 674 | ||
665 | public function getSize() | 675 | public function getSize() |
666 | { | 676 | { |
667 | - $size = BrandSize::find()->joinWith('categories')->createCommand()->rawSql; | 677 | + $subQuery = Product::find() |
678 | + ->select('category.id as x') | ||
679 | + ->joinWith('categories') | ||
680 | + ->where([ 'product.id' => $this->id, ]); | ||
681 | + $size = BrandSize::find() | ||
682 | + ->joinWith('categories') | ||
683 | + ->innerJoin([ 's' => $subQuery ], 's.x = category.id') | ||
684 | + ->where( | ||
685 | + [ | ||
686 | + 'brand_size.brand_id' => $this->brand->id, | ||
687 | + ] | ||
688 | + ) | ||
689 | + ->one(); | ||
690 | + return $size; | ||
668 | } | 691 | } |
669 | 692 | ||
670 | /** | 693 | /** |
@@ -686,17 +709,17 @@ | @@ -686,17 +709,17 @@ | ||
686 | { | 709 | { |
687 | $this->options = $values; | 710 | $this->options = $values; |
688 | } | 711 | } |
689 | - | 712 | + |
690 | public function beforeSave($insert) | 713 | public function beforeSave($insert) |
691 | { | 714 | { |
692 | if (parent::beforeSave($insert)) { | 715 | if (parent::beforeSave($insert)) { |
693 | - | 716 | + |
694 | return true; | 717 | return true; |
695 | } else { | 718 | } else { |
696 | return false; | 719 | return false; |
697 | } | 720 | } |
698 | } | 721 | } |
699 | - | 722 | + |
700 | public function beforeDelete() | 723 | public function beforeDelete() |
701 | { | 724 | { |
702 | if (parent::beforeDelete()) { | 725 | if (parent::beforeDelete()) { |
views/brand-size/index.php
@@ -25,8 +25,8 @@ $this->params['breadcrumbs'][] = $this->title; | @@ -25,8 +25,8 @@ $this->params['breadcrumbs'][] = $this->title; | ||
25 | ['class' => 'yii\grid\SerialColumn'], | 25 | ['class' => 'yii\grid\SerialColumn'], |
26 | 26 | ||
27 | 'id', | 27 | 'id', |
28 | - 'brand_id', | ||
29 | - 'image', | 28 | + 'brand.lang.title', |
29 | + 'imageUrl:image', | ||
30 | 30 | ||
31 | ['class' => 'yii\grid\ActionColumn'], | 31 | ['class' => 'yii\grid\ActionColumn'], |
32 | ], | 32 | ], |
views/brand-size/view.php