diff --git a/features/promotion/managing_promotions/editing_promotion.feature b/features/promotion/managing_promotions/editing_promotion.feature index d09c42bb71..6ca86484ed 100644 --- a/features/promotion/managing_promotions/editing_promotion.feature +++ b/features/promotion/managing_promotions/editing_promotion.feature @@ -6,7 +6,8 @@ Feature: Editing promotion Background: Given the store operates on a single channel in "United States" - And there is a promotion "Christmas sale" + And there is a promotion "Christmas sale" with priority 0 + And there is a promotion "Holiday sale" with priority 1 And I am logged in as an administrator @ui @@ -59,3 +60,11 @@ Feature: Editing promotion Given this promotion gives "$10.00" discount to every order When the store also operates on another channel named "EU-WEB" Then I should be able to modify a "Christmas sale" promotion + + @ui + Scenario: Remove priority from existing promotion + Given I want to modify a "Christmas sale" promotion + When I remove its priority + And I save my changes + Then I should be notified that it has been successfully edited + And the "Christmas sale" promotion should have priority 1 diff --git a/src/Sylius/Behat/Context/Ui/Admin/ManagingPromotionsContext.php b/src/Sylius/Behat/Context/Ui/Admin/ManagingPromotionsContext.php index bab54a1b41..b93abc38ae 100644 --- a/src/Sylius/Behat/Context/Ui/Admin/ManagingPromotionsContext.php +++ b/src/Sylius/Behat/Context/Ui/Admin/ManagingPromotionsContext.php @@ -117,6 +117,14 @@ final class ManagingPromotionsContext implements Context $this->createPage->nameIt($name); } + /** + * @When I remove its priority + */ + public function iRemoveItsPriority() + { + $this->updatePage->setPriority(null); + } + /** * @Then the :promotionName promotion should appear in the registry * @Then the :promotionName promotion should exist in the registry @@ -603,6 +611,16 @@ final class ManagingPromotionsContext implements Context ); } + /** + * @Given the :promotion promotion should have priority :priority + */ + public function thePromotionsShouldHavePriority(PromotionInterface $promotion, $priority) + { + $this->iWantToModifyAPromotion($promotion); + + Assert::same($this->updatePage->getPriority(), $priority); + } + /** * @param string $element * @param string $expectedMessage diff --git a/src/Sylius/Behat/Page/Admin/Promotion/UpdatePage.php b/src/Sylius/Behat/Page/Admin/Promotion/UpdatePage.php index ada403606d..437ab94ef1 100644 --- a/src/Sylius/Behat/Page/Admin/Promotion/UpdatePage.php +++ b/src/Sylius/Behat/Page/Admin/Promotion/UpdatePage.php @@ -24,6 +24,22 @@ class UpdatePage extends BaseUpdatePage implements UpdatePageInterface use NamesIt; use ChecksCodeImmutability; + /** + * {@inheritdoc} + */ + public function setPriority($priority) + { + $this->getDocument()->fillField('Priority', $priority); + } + + /** + * {@inheritdoc} + */ + public function getPriority() + { + return $this->getElement('priority')->getValue(); + } + /** * {@inheritdoc} */ @@ -116,6 +132,7 @@ class UpdatePage extends BaseUpdatePage implements UpdatePageInterface { return [ 'code' => '#sylius_promotion_code', + 'priority' => '#sylius_promotion_priority', 'coupon_based' => '#sylius_promotion_couponBased', 'ends_at' => '#sylius_promotion_endsAt', 'ends_at_date' => '#sylius_promotion_endsAt_date', diff --git a/src/Sylius/Behat/Page/Admin/Promotion/UpdatePageInterface.php b/src/Sylius/Behat/Page/Admin/Promotion/UpdatePageInterface.php index f471706d1d..1a9f3ff227 100644 --- a/src/Sylius/Behat/Page/Admin/Promotion/UpdatePageInterface.php +++ b/src/Sylius/Behat/Page/Admin/Promotion/UpdatePageInterface.php @@ -19,6 +19,17 @@ use Sylius\Behat\Page\Admin\Crud\UpdatePageInterface as BaseUpdatePageInterface; */ interface UpdatePageInterface extends BaseUpdatePageInterface { + + /** + * @param int|null $priority + */ + public function setPriority($priority); + + /** + * @return int + */ + public function getPriority(); + /** * @param string $name */ diff --git a/src/Sylius/Bundle/PromotionBundle/Form/Type/PromotionType.php b/src/Sylius/Bundle/PromotionBundle/Form/Type/PromotionType.php index 24ab525b4a..14d4d15ee4 100644 --- a/src/Sylius/Bundle/PromotionBundle/Form/Type/PromotionType.php +++ b/src/Sylius/Bundle/PromotionBundle/Form/Type/PromotionType.php @@ -11,6 +11,7 @@ namespace Sylius\Bundle\PromotionBundle\Form\Type; +use Sylius\Bundle\PromotionBundle\Form\EventListener\SetPriorityFormSubscriber; use Sylius\Bundle\ResourceBundle\Form\EventSubscriber\AddCodeFormSubscriber; use Sylius\Bundle\ResourceBundle\Form\Type\AbstractResourceType; use Symfony\Component\Form\Extension\Core\Type\CheckboxType; diff --git a/src/Sylius/Component/Promotion/Model/Promotion.php b/src/Sylius/Component/Promotion/Model/Promotion.php index c864ff99b6..ac52157272 100644 --- a/src/Sylius/Component/Promotion/Model/Promotion.php +++ b/src/Sylius/Component/Promotion/Model/Promotion.php @@ -174,7 +174,7 @@ class Promotion implements PromotionInterface */ public function setPriority($priority) { - $this->priority = $priority; + $this->priority = null === $priority ? -1 : $priority; } /**