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

Skip to content

Commit b2698ae

Browse files
authored
feature #13132 [API][UI] Toggle catalog promotion (AdamKasp)
This PR was merged into the 1.11-dev branch. Discussion ---------- | Q | A | --------------- | ----- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | License | MIT <!-- - Bug fixes must be submitted against the 1.9 or 1.10 branch (the lowest possible) - Features and deprecations must be submitted against the master branch - Make sure that the correct base branch is set To be sure you are not breaking any Backward Compatibilities, check the documentation: https://docs.sylius.com/en/latest/book/organization/backward-compatibility-promise.html --> Commits ------- de564fc [CatalogPromotion][Behats] toggling promotion 897d6e2 [CatalogPromotion] behats contexts and toggle on catalog Promotion f0229fd [CatalogPromotion] UI with tests
2 parents 1cb2981 + f0229fd commit b2698ae

29 files changed

Lines changed: 311 additions & 9 deletions

File tree

features/promotion/managing_catalog_promotions/creating_catalog_promotion.feature

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,40 @@ Feature: Creating a catalog promotion
1818
And it should have "winter_sale" code and "Winter sale" name
1919

2020
@api @ui @javascript
21-
Scenario: Creating a catalog promotion
21+
Scenario: Creating an enabled catalog promotion
2222
When I want to create a new catalog promotion
2323
And I specify its code as "winter_sale"
2424
And I name it "Winter sale"
2525
And I specify its label as "Winter -50%" in "English (United States)"
2626
And I describe it as "This promotion gives a 50% discount on all products" in "English (United States)"
2727
And I add rule that applies on variants "PHP T-Shirt" variant and "Kotlin T-Shirt" variant
2828
And I add action that gives "50%" percentage discount
29+
And I make it available in channel "United States"
30+
And I enable this catalog promotion
2931
And I add it
3032
Then there should be 1 new catalog promotion on the list
3133
And it should have "winter_sale" code and "Winter sale" name
3234
And "Winter sale" catalog promotion should apply to "PHP T-Shirt" variant and "Kotlin T-Shirt" variant
3335
And it should have "50%" discount
3436
And this catalog promotion should be usable
37+
And "PHP T-Shirt" variant and "Kotlin T-Shirt" variant should be discounted
38+
39+
@api @ui @javascript
40+
Scenario: Creating a disabled catalog promotion
41+
When I want to create a new catalog promotion
42+
And I specify its code as "winter_sale"
43+
And I name it "Winter sale"
44+
And I specify its label as "Winter -50%" in "English (United States)"
45+
And I describe it as "This promotion gives a 50% discount on all products" in "English (United States)"
46+
And I add rule that applies on variants "PHP T-Shirt" variant and "Kotlin T-Shirt" variant
47+
And I add action that gives "50%" percentage discount
48+
And I disable this catalog promotion
49+
And I add it
50+
Then there should be 1 new catalog promotion on the list
51+
And it should have "winter_sale" code and "Winter sale" name
52+
And "Winter sale" catalog promotion should apply to "PHP T-Shirt" variant and "Kotlin T-Shirt" variant
53+
And it should have "50%" discount
54+
And "PHP T-Shirt" variant and "Kotlin T-Shirt" variant should not be discounted
3555

3656
@api @ui
3757
Scenario: Creating a catalog promotion for channel

features/promotion/managing_catalog_promotions/editing_catalog_promotion.feature

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ Feature: Editing catalog promotion
66

77
Background:
88
Given the store operates on a single channel in "United States"
9-
And the store operates on a channel named "Europe"
109
And the store has a "T-Shirt" configurable product
1110
And this product has "PHP T-Shirt" variant priced at "$20.00"
1211
And this product has "Kotlin T-Shirt" variant priced at "$40.00"
1312
And there is a catalog promotion with "christmas_sale" code and "Christmas sale" name
1413
And it applies on "PHP T-Shirt" variant
1514
And it reduces price by "30%"
15+
And it is enabled
1616
And I am logged in as an administrator
1717

1818
@api @ui
@@ -33,6 +33,7 @@ Feature: Editing catalog promotion
3333
@api @ui
3434
Scenario: Changing availability in channels for catalog promotion
3535
Given the catalog promotion "Christmas sale" is available in "United States"
36+
And the store operates on a channel named "Europe"
3637
When I want to modify a catalog promotion "Christmas sale"
3738
And I make it available in channel "Europe"
3839
And I make it unavailable in channel "United States"
@@ -57,3 +58,14 @@ Feature: Editing catalog promotion
5758
When I edit "Christmas sale" catalog promotion to have "40%" discount
5859
Then I should be notified that it has been successfully edited
5960
And this catalog promotion should have "40%" percentage discount
61+
62+
@api @ui
63+
Scenario: Disabling catalog promotion
64+
When I disable "Christmas sale" catalog promotion
65+
Then "PHP T-Shirt" variant should not be discounted
66+
67+
@api @ui
68+
Scenario: Enabling catalog promotion
69+
Given this catalog promotion is disabled
70+
When I enable "Christmas sale" catalog promotion
71+
Then "PHP T-Shirt" variant should be discounted

src/Sylius/Behat/Context/Api/Admin/ManagingCatalogPromotionsContext.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,22 @@ public function iSpecifyItsAsIn(string $field, string $value, string $localeCode
101101
$this->client->updateRequestData($data);
102102
}
103103

104+
/**
105+
* @When I disable this catalog promotion
106+
*/
107+
public function iDisableCatalogPromotion(): void
108+
{
109+
$this->client->updateRequestData(['enabled' => false]);
110+
}
111+
112+
/**
113+
* @When I enable this catalog promotion
114+
*/
115+
public function iEnableThisCatalogPromotion(): void
116+
{
117+
$this->client->updateRequestData(['enabled' => true]);
118+
}
119+
104120
/**
105121
* @When I describe it as :description in :localeCode
106122
*/
@@ -285,6 +301,22 @@ public function iEditCatalogPromotionToBeAppliedOn(CatalogPromotionInterface $ca
285301
$this->client->update();
286302
}
287303

304+
/**
305+
* @When /^I disable ("[^"]*" catalog promotion)$/
306+
*/
307+
public function iDisableThisCatalogPromotion(CatalogPromotionInterface $catalogPromotion): void
308+
{
309+
$this->toggleCatalogPromotion($catalogPromotion, false);
310+
}
311+
312+
/**
313+
* @When /^I enable ("[^"]*" catalog promotion)$/
314+
*/
315+
public function iEnableCatalogPromotion(CatalogPromotionInterface $catalogPromotion): void
316+
{
317+
$this->toggleCatalogPromotion($catalogPromotion, true);
318+
}
319+
288320
/**
289321
* @When /^I edit ("[^"]+" catalog promotion) to have ("[^"]+") discount$/
290322
*/
@@ -756,4 +788,12 @@ private function hasVariantInConfiguration(array $configuration, ProductVariantI
756788

757789
return false;
758790
}
791+
792+
private function toggleCatalogPromotion(CatalogPromotionInterface $catalogPromotion, bool $enabled): void
793+
{
794+
$this->client->buildUpdateRequest($catalogPromotion->getCode());
795+
796+
$this->client->updateRequestData(['enabled' => $enabled]);
797+
$this->client->update();
798+
}
759799
}

src/Sylius/Behat/Context/Api/Shop/ProductVariantContext.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,44 @@ public function iShouldSeeThisVariantIsNotDiscounted(): void
123123
Assert::keyNotExists($content, 'appliedPromotions');
124124
}
125125

126+
/**
127+
* @Then /^("[^"]+" variant) and ("[^"]+" variant) should be discounted$/
128+
* @Then /^("[^"]+" variant) should be discounted$/
129+
*/
130+
public function variantAndVariantShouldBeDiscounted(ProductVariantInterface ...$variants): void
131+
{
132+
$this->sharedStorage->set('token', null);
133+
134+
/** @var ProductVariantInterface $variant */
135+
foreach ($variants as $variant) {
136+
$content = $this->responseChecker->getResponseContent($this->client->show($variant->getCode()));
137+
Assert::keyExists(
138+
$content,
139+
'appliedPromotions',
140+
sprintf('%s variant should be discounted', $variant->getName())
141+
);
142+
}
143+
}
144+
145+
/**
146+
* @Then /^("[^"]+" variant) and ("[^"]+" variant) should not be discounted$/
147+
* @Then /^("[^"]+" variant) should not be discounted$/
148+
*/
149+
public function variantAndVariantShouldNotBeDiscounted(ProductVariantInterface ...$variants): void
150+
{
151+
$this->sharedStorage->set('token', null);
152+
153+
/** @var ProductVariantInterface $variant */
154+
foreach ($variants as $variant) {
155+
$content = $this->responseChecker->getResponseContent($this->client->show($variant->getCode()));
156+
Assert::keyNotExists(
157+
$content,
158+
'appliedPromotions',
159+
sprintf('%s variant should not be discounted', $variant->getName())
160+
);
161+
}
162+
}
163+
126164
private function findVariant(?ProductVariantInterface $variant): array
127165
{
128166
$response = $this->client->getLastResponse();

src/Sylius/Behat/Context/Setup/CatalogPromotionContext.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,26 @@ public function thereIsACatalogPromotionWithCodeAndName(string $code, string $na
6666
$this->entityManager->flush();
6767
}
6868

69+
/**
70+
* @Given /^(it) is enabled$/
71+
*/
72+
public function itIsEnabled(CatalogPromotionInterface $catalogPromotion): void
73+
{
74+
$catalogPromotion->setEnabled(true);
75+
76+
$this->entityManager->flush();
77+
}
78+
79+
/**
80+
* @Given /^(this catalog promotion) is disabled$/
81+
*/
82+
public function thisCatalogPromotionIsDisabled(CatalogPromotionInterface $catalogPromotion): void
83+
{
84+
$catalogPromotion->setEnabled(false);
85+
86+
$this->entityManager->flush();
87+
}
88+
6989
/**
7090
* @Given there are catalog promotions named :firstName and :secondName
7191
*/

src/Sylius/Behat/Context/Ui/Admin/ManagingCatalogPromotionsContext.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,22 @@ public function iDescribeItAsIn(string $description, string $localeCode): void
112112
$this->formElement->describeIt($description, $localeCode);
113113
}
114114

115+
/**
116+
* @When I enable this catalog promotion
117+
*/
118+
public function iEnableCatalogPromotion(): void
119+
{
120+
$this->formElement->changeEnableTo(true);
121+
}
122+
123+
/**
124+
* @When I disable this catalog promotion
125+
*/
126+
public function iDisableThisCatalogPromotion(): void
127+
{
128+
$this->formElement->changeEnableTo(false);
129+
}
130+
115131
/**
116132
* @When I make it available in channel :channelName
117133
*/
@@ -207,6 +223,26 @@ public function iEditCatalogPromotionToHaveDiscount(CatalogPromotionInterface $c
207223
$this->updatePage->saveChanges();
208224
}
209225

226+
/**
227+
* @When /^I disable ("[^"]*" catalog promotion)$/
228+
*/
229+
public function iDisableCatalogPromotion(CatalogPromotionInterface $catalogPromotion): void
230+
{
231+
$this->updatePage->open(['id' => $catalogPromotion->getId()]);
232+
$this->formElement->changeEnableTo(false);
233+
$this->updatePage->saveChanges();
234+
}
235+
236+
/**
237+
* @When /^I enable ("[^"]*" catalog promotion)$/
238+
*/
239+
public function iEnableThisCatalogPromotion(CatalogPromotionInterface $catalogPromotion): void
240+
{
241+
$this->updatePage->open(['id' => $catalogPromotion->getId()]);
242+
$this->formElement->changeEnableTo(true);
243+
$this->updatePage->saveChanges();
244+
}
245+
210246
/**
211247
* @When I add for variants rule without variants configured
212248
*/

src/Sylius/Behat/Context/Ui/Shop/ProductContext.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,35 @@ public function iTryToOpenProductPage(ProductInterface $product, $localeCode = '
9393
]);
9494
}
9595

96+
/**
97+
* @Then /^("[^"]+" variant) and ("[^"]+" variant) should be discounted$/
98+
* @Then /^("[^"]+" variant) should be discounted$/
99+
*/
100+
public function variantAndVariantShouldBeDiscounted(ProductVariantInterface ...$variants): void
101+
{
102+
/** @var ProductVariantInterface $variant */
103+
foreach ($variants as $variant) {
104+
$this->showPage->open(['slug' => $variant->getProduct()->getTranslation('en_US')->getSlug(), '_locale' => 'en_US']);
105+
$this->showPage->selectVariant($variant->getName());
106+
Assert::greaterThan($this->showPage->getOriginalPrice(), $this->showPage->getPrice());
107+
}
108+
}
109+
110+
/**
111+
* @Then /^("[^"]+" variant) and ("[^"]+" variant) should not be discounted$/
112+
* @Then /^("[^"]+" variant) should not be discounted$/
113+
*/
114+
public function variantAndVariantShouldNotBeDiscounted(ProductVariantInterface ...$variants): void
115+
{
116+
/** @var ProductVariantInterface $variant */
117+
foreach ($variants as $variant) {
118+
$this->showPage->open(['slug' => $variant->getProduct()->getTranslation('en_US')->getSlug(), '_locale' => 'en_US']);
119+
$this->showPage->selectVariant($variant->getName());
120+
121+
Assert::isEmpty($this->showPage->getOriginalPrice());
122+
}
123+
}
124+
96125
/**
97126
* @When I try to reach unexistent product
98127
*/

src/Sylius/Behat/Element/Admin/CatalogPromotion/FormElement.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ public function describeIt(string $description, string $localeCode): void
3535
$this->getElement('description', ['%localeCode%' => $localeCode])->setValue($description);
3636
}
3737

38+
public function changeEnableTo(bool $enabled): void
39+
{
40+
$this->getElement('enabled')->setValue($enabled);
41+
}
42+
3843
public function checkChannel(string $channelName): void
3944
{
4045
$this->getDocument()->checkField($channelName);
@@ -107,6 +112,7 @@ protected function getDefinedElements(): array
107112
'add_rule_button' => '#rules [data-form-collection="add"]',
108113
'channel' => '#sylius_catalog_promotion_code',
109114
'description' => '#sylius_catalog_promotion_translations_%localeCode%_description',
115+
'enabled' => '#sylius_catalog_promotion_enabled',
110116
'label' => '#sylius_catalog_promotion_translations_%localeCode%_label',
111117
'last_action' => '#actions [data-form-collection="item"]:last-child',
112118
'last_rule' => '#rules [data-form-collection="item"]:last-child',

src/Sylius/Behat/Element/Admin/CatalogPromotion/FormElementInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ public function labelIt(string $label, string $localeCode): void;
2121

2222
public function describeIt(string $description, string $localeCode): void;
2323

24+
public function changeEnableTo(bool $enabled): void;
25+
2426
public function checkChannel(string $channelName): void;
2527

2628
public function uncheckChannel(string $channelName): void;

src/Sylius/Behat/Resources/config/suites/api/promotion/managing_catalog_promotions.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ default:
2121
- Sylius\Behat\Context\Setup\CatalogPromotionContext
2222

2323
- sylius.behat.context.api.admin.managing_catalog_promotions
24+
- sylius.behat.context.api.shop.product_variant
2425

2526
filters:
2627
tags: "@managing_catalog_promotions && @api"

0 commit comments

Comments
 (0)