Skip to content

Commit

Permalink
feature #14291 [CatalogPromotions][UI] Removal of catalog promotions …
Browse files Browse the repository at this point in the history
…(Rafikooo)

This PR was merged into the 1.12 branch.

Discussion
----------

| Q               | A                                                            |
|-----------------|--------------------------------------------------------------|
| Branch?         | 1.12 <!-- see the comment below -->                  |
| Bug fix?        | no                                                       |
| New feature?    | yes                                                       |
| BC breaks?      | yes                                                       |
| Deprecations?   | no <!-- don't forget to update the UPGRADE-*.md file --> |
| Related tickets | #14270
| License         | MIT                                                          |

<img width="1159" alt="image" src="https://user-images.githubusercontent.com/40125720/189155094-6d322ff0-d207-4193-9ff4-aa00af69e429.png">


Commits
-------

15f3696 [CatalogPromotions][Behat][UI] Removing catalog promotion scenarios implemented
c95d73a [CatalogPromotions][UI] Removing catalog promotion
  • Loading branch information
GSadee committed Sep 16, 2022
2 parents bd28203 + c95d73a commit e4b0bce
Show file tree
Hide file tree
Showing 11 changed files with 149 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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%
*/
Expand Down
12 changes: 12 additions & 0 deletions src/Sylius/Behat/Context/Ui/Admin/NotificationContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
1 change: 1 addition & 0 deletions src/Sylius/Behat/Resources/config/suites.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Sylius\Bundle\AdminBundle\Controller;

use Sylius\Bundle\CoreBundle\CatalogPromotion\Processor\CatalogPromotionRemovalProcessorInterface;
use Sylius\Component\Promotion\Exception\CatalogPromotionNotFoundException;
use Sylius\Component\Promotion\Exception\InvalidCatalogPromotionStateException;
use Symfony\Component\HttpFoundation\Exception\BadRequestException;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

final class RemoveCatalogPromotionAction
{
public function __construct(private CatalogPromotionRemovalProcessorInterface $catalogPromotionRemovalProcessor)
{
}

public function __invoke(Request $request): Response
{
try {
$this->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());
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
sylius_grid:
templates:
action:
delete_catalog_promotion: "@SyliusAdmin/Grid/deleteCatalogPromotion.html.twig"
grids:
sylius_admin_catalog_promotion:
driver:
Expand Down Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@
<argument type="string">%kernel.environment%</argument>
</service>

<service id="Sylius\Bundle\AdminBundle\Controller\RemoveCatalogPromotionAction" public="true">
<argument type="service" id="Sylius\Bundle\CoreBundle\CatalogPromotion\Processor\CatalogPromotionRemovalProcessorInterface" />
</service>

<service
id="Sylius\Bundle\AdminBundle\Controller\RedirectHandler"
decorates="sylius.resource_controller.redirect_handler"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{% set path = options.link.url|default(path(options.link.route, options.link.parameters)) %}

<form action="{{ path }}" method="post">
<button
{% if options.state == 'processing' %} disabled {% endif %}
class="ui labeled {% if options.state != 'processing' %}red {% endif %}icon button"
type="submit"
data-requires-confirmation {{ sylius_test_html_attribute('delete-button') }}
>
<i class="icon {% if action.icon is not empty %} {{ action.icon }} {% else %}trash{% endif %}"></i>
{% if action.label is not empty %} {{ action.label|trans }} {% else %} {{ 'sylius.ui.delete'|trans }} {% endif %}
</button>
<input type="hidden" name="_csrf_token" value="{{ csrf_token(options.link.parameters.code) }}" />
<input type="hidden" name="_method" value="DELETE"/>
</form>
Original file line number Diff line number Diff line change
Expand Up @@ -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.'

0 comments on commit e4b0bce

Please sign in to comment.