diff --git a/features/promotion/removing_catalog_promotions/removing_catalog_promotions.feature b/features/promotion/removing_catalog_promotions/removing_catalog_promotions.feature index 110fb96a8d8..df3bcf2929d 100644 --- a/features/promotion/removing_catalog_promotions/removing_catalog_promotions.feature +++ b/features/promotion/removing_catalog_promotions/removing_catalog_promotions.feature @@ -13,7 +13,7 @@ Feature: Removing a catalog promotions And there is a catalog promotion "Winter Sale" that reduces price by "30%" and applies on "Clothes" taxon And I am logged in as an administrator - @api + @api @ui Scenario: Removing an expired catalog promotion Given it is "2022-08-22" now And the catalog promotion "Winter sale" operates between "2021-12-20" and "2021-12-30" @@ -22,14 +22,14 @@ Feature: Removing a catalog promotions And there should be an empty list of catalog promotions And "PHP T-Shirt" variant should not be discounted - @api + @api @ui Scenario: Removing an active catalog promotion without any time limits When I request the removal of "Winter Sale" catalog promotion Then I should be notified that the removal operation has started successfully And there should be an empty list of catalog promotions And "PHP T-Shirt" variant should not be discounted - @api + @api @ui Scenario: Removing an active catalog promotion in the time range Given it is "2022-12-15" now And the catalog promotion "Winter sale" operates between "2022-12-01" and "2022-12-30" @@ -38,7 +38,7 @@ Feature: Removing a catalog promotions And there should be an empty list of catalog promotions And "PHP T-Shirt" variant should not be discounted - @api + @api @ui Scenario: Removing a scheduled catalog promotion Given it is "2022-08-22" now And the catalog promotion "Winter sale" operates between "2022-12-01" and "2023-02-28" diff --git a/src/Sylius/Behat/Context/Ui/Admin/ManagingCatalogPromotionsContext.php b/src/Sylius/Behat/Context/Ui/Admin/ManagingCatalogPromotionsContext.php index ab9b050c067..d2fc3167fda 100644 --- a/src/Sylius/Behat/Context/Ui/Admin/ManagingCatalogPromotionsContext.php +++ b/src/Sylius/Behat/Context/Ui/Admin/ManagingCatalogPromotionsContext.php @@ -676,6 +676,15 @@ public function iFilterByDateFromDateToDate(string $dateType, string $fromDate, $this->filterElement->filter(); } + /** + * @When I request the removal of :catalogPromotion catalog promotion + */ + public function iRequestTheRemovalOfCatalogPromotion(CatalogPromotionInterface $catalogPromotion): void + { + $this->indexPage->open(); + $this->indexPage->deleteResourceOnPage(['name' => $catalogPromotion->getName()]); + } + /** * @Then I should be notified that a discount amount should be between 0% and 100% */ diff --git a/src/Sylius/Behat/Context/Ui/Admin/NotificationContext.php b/src/Sylius/Behat/Context/Ui/Admin/NotificationContext.php index 295bbb1d5bb..5655dae98a6 100644 --- a/src/Sylius/Behat/Context/Ui/Admin/NotificationContext.php +++ b/src/Sylius/Behat/Context/Ui/Admin/NotificationContext.php @@ -63,6 +63,18 @@ public function iShouldBeNotifiedThatItHasBeenSuccessfullyDeleted(string $hasHav ); } + /** + * @Then I should be notified that the removal operation has started successfully + */ + public function iShouldBeNotifiedThatTheRemovalOperationHasStartedSuccessfully(): void + { + $this->testHelper->waitUntilNotificationPopups( + $this->notificationChecker, + NotificationType::success(), + 'has been requested. This process can take a while depending on the number of affected products.', + ); + } + /** * @Then I should be notified that it has been failed deleted :name */ diff --git a/src/Sylius/Behat/Resources/config/suites.yml b/src/Sylius/Behat/Resources/config/suites.yml index f8bb0ace9cc..7991505739d 100644 --- a/src/Sylius/Behat/Resources/config/suites.yml +++ b/src/Sylius/Behat/Resources/config/suites.yml @@ -119,6 +119,7 @@ imports: - suites/ui/promotion/managing_promotion_coupons.yml - suites/ui/promotion/managing_promotions.yml - suites/ui/promotion/receiving_discount.yml + - suites/ui/promotion/removing_catalog_promotions.yml - suites/ui/shipping/applying_shipping_fee.yml - suites/ui/shipping/applying_shipping_method_rules.yml - suites/ui/shipping/viewing_shipping_methods.yml diff --git a/src/Sylius/Behat/Resources/config/suites/ui/promotion/removing_catalog_promotions.yml b/src/Sylius/Behat/Resources/config/suites/ui/promotion/removing_catalog_promotions.yml new file mode 100644 index 00000000000..f91b90c6a53 --- /dev/null +++ b/src/Sylius/Behat/Resources/config/suites/ui/promotion/removing_catalog_promotions.yml @@ -0,0 +1,33 @@ +# This file is part of the Sylius package. +# (c) Paweł Jędrzejewski + +default: + suites: + ui_removing_catalog_promotions: + contexts: + - sylius.behat.context.hook.doctrine_orm + - Sylius\Calendar\Tests\Behat\Context\Hook\CalendarContext + + - sylius.behat.context.transform.channel + - sylius.behat.context.transform.lexical + - sylius.behat.context.transform.locale + - sylius.behat.context.transform.product + - sylius.behat.context.transform.product_variant + - sylius.behat.context.transform.shared_storage + - sylius.behat.context.transform.taxon + - Sylius\Behat\Context\Transform\CatalogPromotionContext + + - sylius.behat.context.setup.admin_security + - sylius.behat.context.setup.channel + - sylius.behat.context.setup.product + - sylius.behat.context.setup.product_taxon + - sylius.behat.context.setup.taxonomy + - Sylius\Behat\Context\Setup\CatalogPromotionContext + - Sylius\Calendar\Tests\Behat\Context\Setup\CalendarContext + + - sylius.behat.context.ui.admin.notification + - sylius.behat.context.ui.shop.product + - Sylius\Behat\Context\Ui\Admin\ManagingCatalogPromotionsContext + + filters: + tags: "@removing_catalog_promotions&&@ui" diff --git a/src/Sylius/Bundle/AdminBundle/Controller/RemoveCatalogPromotionAction.php b/src/Sylius/Bundle/AdminBundle/Controller/RemoveCatalogPromotionAction.php new file mode 100644 index 00000000000..df0d5015e17 --- /dev/null +++ b/src/Sylius/Bundle/AdminBundle/Controller/RemoveCatalogPromotionAction.php @@ -0,0 +1,48 @@ +catalogPromotionRemovalProcessor->removeCatalogPromotion($request->attributes->get('code')); + + /** @var Session $session */ + $session = $request->getSession(); + $session->getFlashBag()->add('success', 'sylius.catalog_promotion.remove'); + + return new RedirectResponse($request->headers->get('referer')); + } catch (CatalogPromotionNotFoundException) { + throw new NotFoundHttpException('The catalog promotion has not been found'); + } catch (InvalidCatalogPromotionStateException $exception) { + throw new BadRequestException($exception->getMessage()); + } + } +} diff --git a/src/Sylius/Bundle/AdminBundle/Resources/config/grids/catalog_promotion.yaml b/src/Sylius/Bundle/AdminBundle/Resources/config/grids/catalog_promotion.yaml index e702f29a79f..fc0aa953810 100644 --- a/src/Sylius/Bundle/AdminBundle/Resources/config/grids/catalog_promotion.yaml +++ b/src/Sylius/Bundle/AdminBundle/Resources/config/grids/catalog_promotion.yaml @@ -1,4 +1,7 @@ sylius_grid: + templates: + action: + delete_catalog_promotion: "@SyliusAdmin/Grid/deleteCatalogPromotion.html.twig" grids: sylius_admin_catalog_promotion: driver: @@ -90,3 +93,11 @@ sylius_grid: type: show update: type: update + delete: + type: delete_catalog_promotion + options: + link: + route: sylius_admin_catalog_promotion_delete + parameters: + code: resource.code + state: resource.state diff --git a/src/Sylius/Bundle/AdminBundle/Resources/config/routing/catalog_promotion.yaml b/src/Sylius/Bundle/AdminBundle/Resources/config/routing/catalog_promotion.yaml index cf617670391..7929057d70c 100644 --- a/src/Sylius/Bundle/AdminBundle/Resources/config/routing/catalog_promotion.yaml +++ b/src/Sylius/Bundle/AdminBundle/Resources/config/routing/catalog_promotion.yaml @@ -18,9 +18,19 @@ sylius_admin_catalog_promotion: sylius_admin_catalog_promotion_show: path: /catalog-promotions/{id} + methods: [GET] defaults: _controller: sylius.controller.catalog_promotion:showAction _sylius: section: admin template: "@SyliusAdmin/CatalogPromotion/show.html.twig" permission: true + +sylius_admin_catalog_promotion_delete: + path: /catalog-promotions/{code} + methods: [DELETE] + defaults: + _controller: Sylius\Bundle\AdminBundle\Controller\RemoveCatalogPromotionAction + _sylius: + section: admin + permission: true diff --git a/src/Sylius/Bundle/AdminBundle/Resources/config/services/controller.xml b/src/Sylius/Bundle/AdminBundle/Resources/config/services/controller.xml index e6b0e5d68b5..5b9d6d4c0a4 100644 --- a/src/Sylius/Bundle/AdminBundle/Resources/config/services/controller.xml +++ b/src/Sylius/Bundle/AdminBundle/Resources/config/services/controller.xml @@ -95,6 +95,10 @@ %kernel.environment% + + + + + + + + diff --git a/src/Sylius/Bundle/PromotionBundle/Resources/translations/flashes.en.yml b/src/Sylius/Bundle/PromotionBundle/Resources/translations/flashes.en.yml index 5ab44154207..0cc56be9cdb 100644 --- a/src/Sylius/Bundle/PromotionBundle/Resources/translations/flashes.en.yml +++ b/src/Sylius/Bundle/PromotionBundle/Resources/translations/flashes.en.yml @@ -4,3 +4,5 @@ sylius: promotion_coupon: generate: 'Promotion coupons have been successfully generated.' + catalog_promotion: + remove: 'Removing of catalog promotion has been requested. This process can take a while depending on the number of affected products.'