diff --git a/UPGRADE-1.12.md b/UPGRADE-1.12.md index c2f145511d..646ed7b4f0 100644 --- a/UPGRADE-1.12.md +++ b/UPGRADE-1.12.md @@ -7,6 +7,10 @@ 1. The default checkout resolving route pattern has been changed from `/checkout/.+` to `%sylius.security.shop_regex%/checkout/.+` to reduce the probability of conflicts with other routes. +1. The `src/Sylius/Bundle/AdminBundle/Resources/views/Taxon/_treeWithButtons.html.twig` template has been updated to + implement new changing taxon's position logic. If you have overridden this template, you need to update it. + If you want to check what has changed, you might use [this PR](https://github.com/Sylius/Sylius/pull/15272) as a reference. + # UPGRADE FROM `v1.12.9` TO `v1.12.10` 1. The `Sylius\Component\Core\OrderProcessing\OrderPaymentProcessor` constructor has been changed: diff --git a/config/packages/_sylius.yaml b/config/packages/_sylius.yaml index dc5417459d..fa411e6185 100644 --- a/config/packages/_sylius.yaml +++ b/config/packages/_sylius.yaml @@ -11,7 +11,7 @@ parameters: sylius_core.public_dir: '%kernel.project_dir%/public' sylius_api: - enabled: false + enabled: true sylius_shop: product_grid: diff --git a/docs/book/orders/cart-promotions.rst b/docs/book/orders/cart-promotions.rst index 5702ec0bc8..790f138028 100644 --- a/docs/book/orders/cart-promotions.rst +++ b/docs/book/orders/cart-promotions.rst @@ -118,7 +118,7 @@ There are a few kinds of actions in **Sylius**: * percentage discount on the order (for example: -10% on the whole order) * fixed unit discount (for example: -1$ off the order total but *distributed and applied on each order item unit*) * percentage unit discount (for example: -10% off the order total but *distributed and applied on each order item unit*) -* shipping discount (for example: -6$ on the costs of shipping) +* shipping precentage discount (for example: -10% off the costs of shipping) .. tip:: diff --git a/features/taxonomy/managing_taxons/reordering_taxon.feature b/features/taxonomy/managing_taxons/reordering_taxon.feature index 1e14969e9c..6c1772a7b0 100644 --- a/features/taxonomy/managing_taxons/reordering_taxon.feature +++ b/features/taxonomy/managing_taxons/reordering_taxon.feature @@ -24,6 +24,20 @@ Feature: Reordering taxons And I should see the taxon named "Watches" in the list But the first taxon on the list should be "Watches" + @ui @javascript + Scenario: Moving up the first taxon on list + When I want to see all taxons in store + And I move up "T-Shirts" taxon + Then I should see 4 taxons on the list + And the first taxon on the list should be "T-Shirts" + + @ui @javascript + Scenario: Moving down the last taxon on list + When I want to see all taxons in store + And I move down "Wallets" taxon + Then I should see 4 taxons on the list + And the last taxon on the list should be "Wallets" + @ui @javascript @todo Scenario: Changing order of the taxon on list When I want to see all taxons in store diff --git a/src/Sylius/Behat/Context/Ui/Admin/ManagingTaxonsContext.php b/src/Sylius/Behat/Context/Ui/Admin/ManagingTaxonsContext.php index b9fd13058e..3842a0db14 100644 --- a/src/Sylius/Behat/Context/Ui/Admin/ManagingTaxonsContext.php +++ b/src/Sylius/Behat/Context/Ui/Admin/ManagingTaxonsContext.php @@ -429,6 +429,14 @@ final class ManagingTaxonsContext implements Context Assert::same($this->createPage->getFirstTaxonOnTheList(), $taxonName); } + /** + * @Then the last taxon on the list should be :taxonName + */ + public function theLastTaxonOnTheListShouldBe(string $taxonName): void + { + Assert::same($this->createPage->getLastTaxonOnTheList(), $taxonName); + } + /** * @When I enable it */ diff --git a/src/Sylius/Behat/Page/Admin/Taxon/CreatePage.php b/src/Sylius/Behat/Page/Admin/Taxon/CreatePage.php index 4b56b8888b..44b3b669bc 100644 --- a/src/Sylius/Behat/Page/Admin/Taxon/CreatePage.php +++ b/src/Sylius/Behat/Page/Admin/Taxon/CreatePage.php @@ -144,6 +144,13 @@ class CreatePage extends BaseCreatePage implements CreatePageInterface return $this->getLeaves()[0]->getText(); } + public function getLastTaxonOnTheList(): string + { + $leaves = $this->getLeaves(); + + return $leaves[count($leaves) - 1]->getText(); + } + protected function getElement(string $name, array $parameters = []): NodeElement { if (!isset($parameters['%language%'])) { diff --git a/src/Sylius/Behat/Page/Admin/Taxon/CreatePageInterface.php b/src/Sylius/Behat/Page/Admin/Taxon/CreatePageInterface.php index c95477152c..2b17512979 100644 --- a/src/Sylius/Behat/Page/Admin/Taxon/CreatePageInterface.php +++ b/src/Sylius/Behat/Page/Admin/Taxon/CreatePageInterface.php @@ -52,4 +52,6 @@ interface CreatePageInterface extends BaseCreatePageInterface public function moveDownTaxon(string $name): void; public function getFirstTaxonOnTheList(): string; + + public function getLastTaxonOnTheList(): string; } diff --git a/src/Sylius/Bundle/AdminBundle/Resources/config/routing/ajax/taxon.yml b/src/Sylius/Bundle/AdminBundle/Resources/config/routing/ajax/taxon.yml index f5f15b2456..0dc13c77a5 100644 --- a/src/Sylius/Bundle/AdminBundle/Resources/config/routing/ajax/taxon.yml +++ b/src/Sylius/Bundle/AdminBundle/Resources/config/routing/ajax/taxon.yml @@ -69,3 +69,21 @@ sylius_admin_ajax_taxon_move: _sylius: permission: true form: Sylius\Bundle\TaxonomyBundle\Form\Type\TaxonPositionType + +sylius_admin_ajax_taxon_move_up: + path: /{id}/move-up + methods: [PUT] + defaults: + _controller: sylius.controller.taxon_position::moveUpAction + _format: json + _sylius: + permission: true + +sylius_admin_ajax_taxon_move_down: + path: /{id}/move-down + methods: [PUT] + defaults: + _controller: sylius.controller.taxon_position::moveDownAction + _format: json + _sylius: + permission: true diff --git a/src/Sylius/Bundle/AdminBundle/Resources/private/js/app.js b/src/Sylius/Bundle/AdminBundle/Resources/private/js/app.js index bfbe6e4288..1735b49d17 100644 --- a/src/Sylius/Bundle/AdminBundle/Resources/private/js/app.js +++ b/src/Sylius/Bundle/AdminBundle/Resources/private/js/app.js @@ -54,8 +54,9 @@ $(document).ready(() => { }); $('.sylius-update-product-variants').moveProductVariant($('.sylius-product-variant-position')); - $('.sylius-taxon-move-up').taxonMoveUp(); - $('.sylius-taxon-move-down').taxonMoveDown(); + + $('.sylius-taxon-move-up').taxonMove(); + $('.sylius-taxon-move-down').taxonMove(); $('#sylius_shipping_method_calculator').handlePrototypes({ prototypePrefix: 'sylius_shipping_method_calculator_calculators', diff --git a/src/Sylius/Bundle/AdminBundle/Resources/private/js/sylius-move-taxon.js b/src/Sylius/Bundle/AdminBundle/Resources/private/js/sylius-move-taxon.js index 7be2866a2c..c10bbaf156 100644 --- a/src/Sylius/Bundle/AdminBundle/Resources/private/js/sylius-move-taxon.js +++ b/src/Sylius/Bundle/AdminBundle/Resources/private/js/sylius-move-taxon.js @@ -11,40 +11,12 @@ import 'semantic-ui-css/components/api'; import $ from 'jquery'; $.fn.extend({ - taxonMoveUp() { + taxonMove() { const element = this; element.api({ method: 'PUT', on: 'click', - beforeSend(settings) { - /* eslint-disable-next-line no-param-reassign */ - settings.data = { - position: $(this).data('position') - 1, - }; - - return settings; - }, - onSuccess() { - window.location.reload(); - }, - }); - }, - - taxonMoveDown() { - const element = this; - - element.api({ - method: 'PUT', - on: 'click', - beforeSend(settings) { - /* eslint-disable-next-line no-param-reassign */ - settings.data = { - position: $(this).data('position') + 1, - }; - - return settings; - }, onSuccess() { window.location.reload(); }, diff --git a/src/Sylius/Bundle/AdminBundle/Resources/views/Taxon/_treeWithButtons.html.twig b/src/Sylius/Bundle/AdminBundle/Resources/views/Taxon/_treeWithButtons.html.twig index 9b450d0e50..fe5492abe3 100644 --- a/src/Sylius/Bundle/AdminBundle/Resources/views/Taxon/_treeWithButtons.html.twig +++ b/src/Sylius/Bundle/AdminBundle/Resources/views/Taxon/_treeWithButtons.html.twig @@ -34,10 +34,10 @@
-
+
{{ 'sylius.ui.move_up'|trans }}
-
+
{{ 'sylius.ui.move_down'|trans }}
diff --git a/src/Sylius/Bundle/TaxonomyBundle/Controller/TaxonPositionController.php b/src/Sylius/Bundle/TaxonomyBundle/Controller/TaxonPositionController.php new file mode 100644 index 0000000000..8dad118828 --- /dev/null +++ b/src/Sylius/Bundle/TaxonomyBundle/Controller/TaxonPositionController.php @@ -0,0 +1,67 @@ +findTaxonOr404($id); + + if ($taxonToBeMoved->getPosition() > 0) { + $taxonToBeMoved->setPosition($taxonToBeMoved->getPosition() - 1); + $this->taxonManager->flush(); + } + + return new JsonResponse('', Response::HTTP_NO_CONTENT); + } + + public function moveDownAction(int $id): Response + { + $taxonToBeMoved = $this->findTaxonOr404($id); + + $taxonToBeMoved->setPosition($taxonToBeMoved->getPosition() + 1); + $this->taxonManager->flush(); + + return new JsonResponse('', Response::HTTP_NO_CONTENT); + } + + private function findTaxonOr404(int $id): TaxonInterface + { + /** @var TaxonInterface|null $taxon */ + $taxon = $this->taxonRepository->find($id); + + if (null === $taxon) { + throw new NotFoundHttpException(sprintf('Taxon with id %d does not exist.', $id)); + } + + Assert::isInstanceOf($taxon, TaxonInterface::class); + + return $taxon; + } +} diff --git a/src/Sylius/Bundle/TaxonomyBundle/Resources/config/services.xml b/src/Sylius/Bundle/TaxonomyBundle/Resources/config/services.xml index f27c592d3f..505e391180 100644 --- a/src/Sylius/Bundle/TaxonomyBundle/Resources/config/services.xml +++ b/src/Sylius/Bundle/TaxonomyBundle/Resources/config/services.xml @@ -26,6 +26,11 @@ + + + + +