Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Catalog Promotions] add rule to catalog promotion#13001

Merged
Zales0123 merged 20 commits into
Sylius:masterfrom
AdamKasp:create-catalog-promotion-with-rule
Aug 30, 2021
Merged

[Catalog Promotions] add rule to catalog promotion#13001
Zales0123 merged 20 commits into
Sylius:masterfrom
AdamKasp:create-catalog-promotion-with-rule

Conversation

@AdamKasp
Copy link
Copy Markdown
Contributor

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

@AdamKasp AdamKasp requested a review from a team as a code owner August 24, 2021 12:34
@probot-autolabeler probot-autolabeler Bot added the API APIs related issues and PRs. label Aug 26, 2021
@AdamKasp AdamKasp force-pushed the create-catalog-promotion-with-rule branch 2 times, most recently from 474ca57 to 7df15ef Compare August 26, 2021 10:05
Comment on lines +23 to +24
<attribute name="input">Sylius\Component\Promotion\DTO\CatalogPromotion</attribute>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should it be added here also? Or only in post? ( just asking )

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

no, it is unnecessary :)

Comment thread src/Sylius/Component/Promotion/DTO/CatalogPromotion.php Outdated
Comment on lines +19 to +25
protected $id;

protected ?string $type;

protected array $configuration = [];

protected ?CatalogPromotionInterface $catalogPromotion;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Similar with DTO i think there should not be empty lines🤔

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I am not sure :D for my personal preferences, it looks more readable with extra spaces.

@AdamKasp AdamKasp force-pushed the create-catalog-promotion-with-rule branch from 7df15ef to f1e9661 Compare August 26, 2021 10:17
@AdamKasp AdamKasp changed the title [WIP] [Behats] catalog promotion with rule [WIP] catalog promotion with rule Aug 26, 2021
@AdamKasp AdamKasp force-pushed the create-catalog-promotion-with-rule branch from f1e9661 to 4534b2e Compare August 26, 2021 10:32
Comment thread src/Sylius/Behat/Context/Api/Admin/ManagingCatalogPromotionsContext.php Outdated
Comment thread src/Sylius/Bundle/ApiBundle/DataTransformer/CatalogPromotionDataTransformer.php Outdated
Comment thread src/Sylius/Bundle/ApiBundle/DataTransformer/CatalogPromotionDataTransformer.php Outdated
Comment thread src/Sylius/Bundle/ApiBundle/DataTransformer/CatalogPromotionDataTransformer.php Outdated
Comment thread src/Sylius/Component/Promotion/DTO/CatalogPromotion.php Outdated
Comment thread src/Sylius/Component/Promotion/Model/CatalogPromotion.php
Comment thread src/Sylius/Component/Promotion/Model/CatalogPromotion.php Outdated
Comment thread src/Sylius/Component/Promotion/Model/CatalogPromotionInterface.php Outdated
@AdamKasp AdamKasp force-pushed the create-catalog-promotion-with-rule branch from 4534b2e to 55b813d Compare August 26, 2021 12:16
Comment thread features/promotion/managing_catalog_promotions/creating_catalog_promotion.feature Outdated
Comment thread src/Sylius/Behat/Context/Api/Admin/ManagingCatalogPromotionsContext.php Outdated
Comment thread src/Sylius/Bundle/ApiBundle/DataPersister/CatalogPromotionDataPersister.php Outdated
Comment thread src/Sylius/Bundle/ApiBundle/DataPersister/CatalogPromotionDataPersister.php Outdated
Comment thread src/Sylius/Component/Promotion/Model/CatalogPromotionRuleInterface.php Outdated
Comment thread src/Sylius/Component/Promotion/spec/Model/CatalogPromotionSpec.php Outdated
Comment thread src/Sylius/Component/Promotion/spec/Model/CatalogPromotionSpec.php Outdated
Comment thread src/Sylius/Component/Promotion/spec/Model/CatalogPromotionSpec.php Outdated
@SirDomin SirDomin force-pushed the create-catalog-promotion-with-rule branch from 1cbf0a9 to b001ade Compare August 26, 2021 20:30
@SirDomin SirDomin changed the title [WIP] catalog promotion with rule catalog promotion with rule Aug 26, 2021
@SirDomin SirDomin changed the title catalog promotion with rule [Catalog Promotions] add rule to catalog promotion Aug 26, 2021
Comment thread features/promotion/managing_catalog_promotions/creating_catalog_promotion.feature Outdated
Comment thread features/promotion/managing_catalog_promotions/creating_catalog_promotion.feature Outdated
Comment thread src/Sylius/Behat/Context/Api/Admin/ManagingCatalogPromotionsContext.php Outdated
Comment thread src/Sylius/Bundle/ApiBundle/Serializer/CatalogPromotionNormalizer.php Outdated
Comment thread src/Sylius/Bundle/ApiBundle/Serializer/CatalogPromotionNormalizer.php Outdated
Comment thread src/Sylius/Bundle/ApiBundle/Serializer/CatalogPromotionNormalizer.php Outdated
Comment thread src/Sylius/Component/Promotion/DTO/CatalogPromotion.php Outdated
Comment thread src/Sylius/Component/Promotion/spec/Model/CatalogPromotionRuleSpec.php Outdated
Comment thread tests/Api/Admin/CatalogPromotionsTest.php Outdated
@SirDomin SirDomin force-pushed the create-catalog-promotion-with-rule branch 6 times, most recently from a5ffdf0 to 4d79a9f Compare August 27, 2021 06:49
Comment thread features/promotion/managing_catalog_promotions/creating_catalog_promotion.feature Outdated
Comment thread src/Sylius/Behat/Context/Api/Admin/ManagingCatalogPromotionsContext.php Outdated
@lchrusciel
Copy link
Copy Markdown
Contributor

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.

@SirDomin SirDomin force-pushed the create-catalog-promotion-with-rule branch from 3dc5064 to 19378c0 Compare August 30, 2021 09:05
@SirDomin SirDomin force-pushed the create-catalog-promotion-with-rule branch from 19378c0 to 2cd687d Compare August 30, 2021 09:06
}

/**
* @Then it should have "contains variants" rule
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This step is not needed anymore

);
}

private function catalogPromotionAppliesOn(ProductVariantInterface ...$productVariants): bool
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

isCatalogPromotionAppliedOn?

*/
public function itWillBeAppliedOnVariant(CatalogPromotionInterface $catalogPromotion, ProductVariantInterface $variant): void
{
$catalogPromotionRule = new CatalogPromotionRule();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We should use a CatalogPromotion factory here

{
$catalogPromotionRule = new CatalogPromotionRule();

$catalogPromotionRule->setType(CatalogPromotionRule::TYPE_CONTAINS_VARIANTS);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe it's also a good idea to introduce per-type create methods? Like createContainsVariant(array $configuration)? But it can be an improvement

]
]
]
);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 💃

@Zales0123 Zales0123 merged commit 8b9c8c1 into Sylius:master Aug 30, 2021
@Zales0123
Copy link
Copy Markdown
Contributor

Zales0123 commented Aug 30, 2021

Thank you, Adam and Dominik! 🎉


interface CatalogPromotionRuleInterface extends ResourceInterface
{
public const TYPE_CONTAINS_VARIANTS = 'contains_variants';
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

IMO this const should be defined in Core as Promotion component has no dependency to Product bundle/component

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

yup, it was added in #13029

GSadee added a commit that referenced this pull request Aug 31, 2021
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

API APIs related issues and PRs.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants