Commit 65f5712c43c2b6f9f4971a92ebdc5e343b77745e
1 parent
b1cc502f
select characteristic
Showing
2 changed files
with
66 additions
and
1 deletions
Show diff stats
models/Product.php
| @@ -571,7 +571,40 @@ | @@ -571,7 +571,40 @@ | ||
| 571 | } | 571 | } |
| 572 | return $groups; | 572 | return $groups; |
| 573 | } | 573 | } |
| 574 | - | 574 | + |
| 575 | + | ||
| 576 | + /** | ||
| 577 | + * Get characteristic from TaxGroups for current Product filled with $customOptions that satisfy current Product | ||
| 578 | + * | ||
| 579 | + * @return TaxGroup[] | ||
| 580 | + */ | ||
| 581 | + public function getCharacteristic(): array | ||
| 582 | + { | ||
| 583 | + $groups = $options = []; | ||
| 584 | + foreach ($this->getOptions() | ||
| 585 | + ->with('lang') | ||
| 586 | + ->all() as $option) { | ||
| 587 | + /** | ||
| 588 | + * @var TaxOption $option | ||
| 589 | + */ | ||
| 590 | + $options[ $option[ 'tax_group_id' ] ][] = $option; | ||
| 591 | + } | ||
| 592 | + foreach (TaxGroup::find() | ||
| 593 | + ->where(['is_menu'=>true]) | ||
| 594 | + ->andWhere([ 'id' => array_keys($options) ]) | ||
| 595 | + ->with('lang') | ||
| 596 | + ->all() as $group) { | ||
| 597 | + /** | ||
| 598 | + * @var TaxGroup $group | ||
| 599 | + */ | ||
| 600 | + if (!empty($options[ $group->id ])) { | ||
| 601 | + $group->customOptions = $options[ $group->id ]; | ||
| 602 | + $groups[] = $group; | ||
| 603 | + } | ||
| 604 | + } | ||
| 605 | + return $groups; | ||
| 606 | + } | ||
| 607 | + | ||
| 575 | public function getVideos() | 608 | public function getVideos() |
| 576 | { | 609 | { |
| 577 | return $this->hasMany(ProductVideo::className(), [ 'product_id' => 'id' ]); | 610 | return $this->hasMany(ProductVideo::className(), [ 'product_id' => 'id' ]); |
models/ProductVariant.php
| @@ -398,6 +398,38 @@ | @@ -398,6 +398,38 @@ | ||
| 398 | } | 398 | } |
| 399 | return $groups; | 399 | return $groups; |
| 400 | } | 400 | } |
| 401 | + | ||
| 402 | + /** | ||
| 403 | + * Get characteristic from TaxGroups for current ProductVariant filled with $customOptions that satisfy current Product | ||
| 404 | + * | ||
| 405 | + * @return TaxGroup[] | ||
| 406 | + */ | ||
| 407 | + public function getCharacteristic(): array | ||
| 408 | + { | ||
| 409 | + $groups = $options = []; | ||
| 410 | + foreach ($this->getOptions() | ||
| 411 | + ->with('lang') | ||
| 412 | + ->all() as $option) { | ||
| 413 | + /** | ||
| 414 | + * @var TaxOption $option | ||
| 415 | + */ | ||
| 416 | + $options[ $option[ 'tax_group_id' ] ][] = $option; | ||
| 417 | + } | ||
| 418 | + foreach (TaxGroup::find() | ||
| 419 | + ->where(['is_menu'=>true]) | ||
| 420 | + ->andWhere([ 'id' => array_keys($options) ]) | ||
| 421 | + ->with('lang') | ||
| 422 | + ->all() as $group) { | ||
| 423 | + /** | ||
| 424 | + * @var TaxGroup $group | ||
| 425 | + */ | ||
| 426 | + if (!empty($options[ $group->id ])) { | ||
| 427 | + $group->customOptions = $options[ $group->id ]; | ||
| 428 | + $groups[] = $group; | ||
| 429 | + } | ||
| 430 | + } | ||
| 431 | + return $groups; | ||
| 432 | + } | ||
| 401 | 433 | ||
| 402 | /** | 434 | /** |
| 403 | * Set stocks to override existing in product_stock table | 435 | * Set stocks to override existing in product_stock table |