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

Skip to content

Commit 8f2a954

Browse files
committed
Reapply CP after changes on taxons
1 parent 36bedf4 commit 8f2a954

3 files changed

Lines changed: 52 additions & 1 deletion

File tree

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
@applying_catalog_promotions
2+
Feature: Reapplying catalog promotions on taxon once its data changes
3+
In order to have proper discounts on taxon
4+
As a Store Owner
5+
I want to have discounts reapplied on taxon once its data changes
6+
7+
Background:
8+
Given the store operates on a channel named "Web-US" with hostname "web-us"
9+
And the store classifies its products as "Clothes" and "Dishes"
10+
And the store has a "T-Shirt" configurable product
11+
And this product belongs to "Clothes"
12+
And this product has "PHP T-Shirt" variant priced at "$100.00"
13+
And the store has a "Mug" configurable product
14+
And this product belongs to "Dishes"
15+
And this product has "PHP Mug" variant priced at "$10.00"
16+
And I am logged in as an administrator
17+
18+
@api @ui @javascript
19+
Scenario: Reapplying catalog promotion after changing the taxon of catalog promotion
20+
Given there is a catalog promotion "Winter sale" that reduces price by "30%" and applies on "Clothes" taxon
21+
When I edit "Winter sale" catalog promotion to be applied on "Dishes" taxon
22+
Then the visitor should see "$100.00" as the price of the "T-Shirt" product in the "Web-US" channel
23+
And the visitor should see "$7.00" as the price of the "Mug" product in the "Web-US" channel
24+
And the visitor should still see "$10.00" as the original price of the "Mug" product in the "Web-US" channel
25+
26+
@api @ui @javascript
27+
Scenario: Reapplying catalog promotion after changing scope from variant to taxon based
28+
Given there is a catalog promotion "Winter sale" that reduces price by "30%" and applies on "PHP T-Shirt" variant
29+
When I edit "Winter sale" catalog promotion to be applied on "Dishes" taxon
30+
Then the visitor should see "$100.00" as the price of the "T-Shirt" product in the "Web-US" channel
31+
And the visitor should see "$7.00" as the price of the "Mug" product in the "Web-US" channel
32+
And the visitor should still see "$10.00" as the original price of the "Mug" product in the "Web-US" channel

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use Sylius\Component\Core\Model\CatalogPromotionScopeInterface;
2323
use Sylius\Component\Core\Model\ChannelInterface;
2424
use Sylius\Component\Core\Model\ProductVariantInterface;
25+
use Sylius\Component\Core\Model\TaxonInterface;
2526
use Webmozart\Assert\Assert;
2627

2728
final class ManagingCatalogPromotionsContext implements Context
@@ -217,14 +218,25 @@ public function iSaveMyChanges(): void
217218
/**
218219
* @When /^I edit ("[^"]+" catalog promotion) to be applied on ("[^"]+" variant)$/
219220
*/
220-
public function iEditCatalogPromotionToBeAppliedOn(CatalogPromotionInterface $catalogPromotion, ProductVariantInterface $productVariant): void
221+
public function iEditCatalogPromotionToBeAppliedOnVariant(CatalogPromotionInterface $catalogPromotion, ProductVariantInterface $productVariant): void
221222
{
222223
$this->updatePage->open(['id' => $catalogPromotion->getId()]);
223224

224225
$this->formElement->chooseLastScopeVariants([$productVariant->getCode()]);
225226
$this->updatePage->saveChanges();
226227
}
227228

229+
/**
230+
* @When /^I edit ("[^"]+" catalog promotion) to be applied on ("[^"]+" taxon)$/
231+
*/
232+
public function iEditCatalogPromotionToBeAppliedOnTaxon(CatalogPromotionInterface $catalogPromotion, TaxonInterface $taxon): void
233+
{
234+
$this->updatePage->open(['id' => $catalogPromotion->getId()]);
235+
236+
$this->formElement->chooseLastScopeTaxons([$taxon]);
237+
$this->updatePage->saveChanges();
238+
}
239+
228240
/**
229241
* @When I remove its every scope
230242
*/

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@ public function chooseLastScopeVariants(array $variantCodes): void
6767
$lastScope->find('css', 'input[type="hidden"]')->setValue(implode(',', $variantCodes));
6868
}
6969

70+
public function chooseLastScopeTaxons(array $taxons): void
71+
{
72+
$lastScope = $this->getElement('last_scope');
73+
74+
$lastScope->find('css', 'input[type="hidden"]')->setValue(implode(',', $taxons));
75+
}
76+
7077
public function specifyLastActionDiscount(string $discount): void
7178
{
7279
$lastAction = $this->getElement('last_action');

0 commit comments

Comments
 (0)