Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Catalog Promotions] Fixing issues with multiple variants #13080

Merged
merged 2 commits into from
Sep 10, 2021

Conversation

arti0090
Copy link
Contributor

@arti0090 arti0090 commented Sep 9, 2021

Q A
Branch? master
Bug fix? no
New feature? no
BC breaks? no
Deprecations? no
License MIT

@arti0090 arti0090 requested a review from a team as a code owner September 9, 2021 10:03
Comment on lines 87 to 95
public function addAppliedPromotion(array $promotion): void
{
if ($this->appliedPromotions === null) {
$this->appliedPromotions = $promotion;
return;
}

$this->appliedPromotions = array_merge_recursive($this->appliedPromotions, $promotion);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should consider some changes for
/** @var array */ protected $appliedPromotions = [];
value.
At this moment it does not safe us from storing null value. This lead to problem with array_merge where one value sometimes is null.
Sugestion: change this to protected array $appliedPromotions = []; make adjust in orm file and create the migration that will make this field not null and put default value of empty array.

@GSadee GSadee added the Bug Confirmed bugs or bugfixes. label Sep 9, 2021

/** @var CatalogPromotionRuleInterface $catalogPromotionRule */
$catalogPromotionRule = $this->catalogPromotionRuleFactory->createNew();
$catalogPromotionRule->setType(CatalogPromotionRuleInterface::TYPE_FOR_VARIANTS);
$catalogPromotionRule->setConfiguration(['variants' => [$variant->getCode()]]);
$catalogPromotionRule->setConfiguration(['variants' => array_values($variantCodes)]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$catalogPromotionRule->setConfiguration(['variants' => array_values($variantCodes)]);
$catalogPromotionRule->setConfiguration(['variants' => $variantCodes]);

should be enough 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

then it creates something like: 'variants' => 0: 'code1' , 1:'code2' that is why I used array_values

@GSadee GSadee merged commit 185f7f0 into Sylius:master Sep 10, 2021
@GSadee
Copy link
Member

GSadee commented Sep 10, 2021

Thanks, @arti0090! 🥇

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Confirmed bugs or bugfixes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants