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

[Admin][Promotion] Fix removing taxon used in promotion rule #10365

Merged
merged 8 commits into from
May 13, 2019
Prev Previous commit
Next Next commit
[Promotion] Fixes after PR review
  • Loading branch information
GSadee committed May 10, 2019
commit 40835021b7d17508fb03dbac6c968746186b2830
21 changes: 16 additions & 5 deletions src/Sylius/Behat/Context/Ui/Admin/ManagingPromotionsContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,13 @@ public function iSpecifyThatThisActionShouldBeAppliedToItemsFromCategory($taxonN
}

/**
* @When /^I add the "([^"]+)" action configured with a percentage value of (?:|-)([^"]+)% for ("[^"]+" channel)$/
* @When /^I add the "([^"]+)" action configured with a percentage value of (?:|-)([^"]+)% for ("[^"]+") channel$/
*/
public function iAddTheActionConfiguredWithAPercentageValueForChannel($actionType, $percentage = null, $channelName)
{
public function iAddTheActionConfiguredWithAPercentageValueForChannel(
string $actionType,
string $percentage = null,
string $channelName
): void {
$this->createPage->addAction($actionType);
$this->createPage->fillActionOptionForChannel($channelName, 'Percentage', $percentage);
}
Expand Down Expand Up @@ -408,7 +411,6 @@ public function thePromotionShouldBeApplicableForTheChannel(PromotionInterface $
/**
* @Given I want to modify a :promotion promotion
* @Given /^I want to modify (this promotion)$/
* @Then I should be able to modify a :promotion promotion
*/
public function iWantToModifyAPromotion(PromotionInterface $promotion)
{
Expand Down Expand Up @@ -617,12 +619,22 @@ public function thePromotionsShouldHavePriority(PromotionInterface $promotion, i
Assert::same($this->updatePage->getPriority(), $priority);
}

/**
* @Then I should be able to modify a :promotion promotion
*/
public function iShouldBeAbleToModifyAPromotion(PromotionInterface $promotion): void
{
$this->iWantToModifyAPromotion($promotion);
$this->updatePage->saveChanges();
}

/**
* @Then the :promotion promotion should have :ruleName rule configured
*/
public function thePromotionShouldHaveRuleConfigured(PromotionInterface $promotion, string $ruleName): void
{
$this->iWantToModifyAPromotion($promotion);
GSadee marked this conversation as resolved.
Show resolved Hide resolved
$this->updatePage->saveChanges();

Assert::true($this->updatePage->hasRule($ruleName));
}
Expand All @@ -637,7 +649,6 @@ public function thePromotionShouldNotHaveAnyRuleConfigured(PromotionInterface $p
Assert::false($this->updatePage->hasAnyRule());
}


/**
* @param string $element
* @param string $expectedMessage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,7 @@ private function resolveHasTaxonRules(string $taxonCode): void
foreach ($promotionRules as $promotionRule) {
$configuration = $promotionRule->getConfiguration();
if (in_array($taxonCode, $configuration['taxons'])) {
GSadee marked this conversation as resolved.
Show resolved Hide resolved
$taxons = array_filter(
$configuration['taxons'],
function (string $code) use ($taxonCode) {
return $taxonCode !== $code;
}
);

$configuration['taxons'] = array_values($taxons);
$configuration['taxons'] = array_values(array_diff($configuration['taxons'], [$taxonCode]));
$promotionRule->setConfiguration($configuration);
}
}
Expand Down