[Catalog Promotions] add rule to catalog promotion#13001
Conversation
AdamKasp
commented
Aug 24, 2021
| Q | A |
|---|---|
| Branch? | master |
| Bug fix? | no |
| New feature? | yes |
| BC breaks? | no |
| License | MIT |
474ca57 to
7df15ef
Compare
| <attribute name="input">Sylius\Component\Promotion\DTO\CatalogPromotion</attribute> | ||
|
|
There was a problem hiding this comment.
Should it be added here also? Or only in post? ( just asking )
There was a problem hiding this comment.
no, it is unnecessary :)
| protected $id; | ||
|
|
||
| protected ?string $type; | ||
|
|
||
| protected array $configuration = []; | ||
|
|
||
| protected ?CatalogPromotionInterface $catalogPromotion; |
There was a problem hiding this comment.
Similar with DTO i think there should not be empty lines🤔
There was a problem hiding this comment.
I am not sure :D for my personal preferences, it looks more readable with extra spaces.
7df15ef to
f1e9661
Compare
f1e9661 to
4534b2e
Compare
4534b2e to
55b813d
Compare
1cbf0a9 to
b001ade
Compare
a5ffdf0 to
4d79a9f
Compare
|
There is one more thing - the configuration of rules is not directly related to the entities. I don't see the benefit that would justify the necessity of custom persisters and normalizers to convert IRIs into codes. We don't have to remove this part in this PR - but I would suggest it next time we touch rule and/or action functionality. |
3dc5064 to
19378c0
Compare
19378c0 to
2cd687d
Compare
| } | ||
|
|
||
| /** | ||
| * @Then it should have "contains variants" rule |
There was a problem hiding this comment.
This step is not needed anymore
| ); | ||
| } | ||
|
|
||
| private function catalogPromotionAppliesOn(ProductVariantInterface ...$productVariants): bool |
There was a problem hiding this comment.
isCatalogPromotionAppliedOn?
| */ | ||
| public function itWillBeAppliedOnVariant(CatalogPromotionInterface $catalogPromotion, ProductVariantInterface $variant): void | ||
| { | ||
| $catalogPromotionRule = new CatalogPromotionRule(); |
There was a problem hiding this comment.
We should use a CatalogPromotion factory here
| { | ||
| $catalogPromotionRule = new CatalogPromotionRule(); | ||
|
|
||
| $catalogPromotionRule->setType(CatalogPromotionRule::TYPE_CONTAINS_VARIANTS); |
There was a problem hiding this comment.
Maybe it's also a good idea to introduce per-type create methods? Like createContainsVariant(array $configuration)? But it can be an improvement
| ] | ||
| ] | ||
| ] | ||
| ); |
There was a problem hiding this comment.
What if we make the return array a one-liner?
$normalizer
->normalize($catalogPromotion, null, ['sylius_catalog_promotion_normalizer_already_called' => true])
->willReturn(['rules' => [['configuration' => ['MUG', 'MUG_2']]]])
;still readable and takes a few lines less 💃
|
Thank you, Adam and Dominik! 🎉 |
|
|
||
| interface CatalogPromotionRuleInterface extends ResourceInterface | ||
| { | ||
| public const TYPE_CONTAINS_VARIANTS = 'contains_variants'; |
There was a problem hiding this comment.
IMO this const should be defined in Core as Promotion component has no dependency to Product bundle/component
…pplication (Zales0123) This PR was merged into the 1.11-dev branch. Discussion ---------- | Q | A | --------------- | ----- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | | Related tickets | based on #13001 | License | MIT Commits ------- fead5a9 Use rules in catalog promotion application 80dfb73 Adjust and implement Behat scenarios 51a7109 Include CatalogPromotionRule in doctrine listener a1378c9 Fix adding CP rule to CP in Behat 28e9cb6 Apply CP on variant and change the rule name