From 6a83c03a3727143e88c17650aa70f38e2fcfb694 Mon Sep 17 00:00:00 2001 From: milwoz Date: Thu, 3 Mar 2022 10:33:00 +0100 Subject: [PATCH] location reload after request --- ...ySelectedProductsToOtherWishlistAction.php | 19 ++++++++++++++++++- .../shop/js/handleCopyToWishlistListModal.js | 3 +-- src/Resources/config/services.yml | 7 +------ 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/Controller/Action/CopySelectedProductsToOtherWishlistAction.php b/src/Controller/Action/CopySelectedProductsToOtherWishlistAction.php index 095ac58c..bdf8eb01 100644 --- a/src/Controller/Action/CopySelectedProductsToOtherWishlistAction.php +++ b/src/Controller/Action/CopySelectedProductsToOtherWishlistAction.php @@ -12,20 +12,32 @@ namespace BitBag\SyliusWishlistPlugin\Controller\Action; use BitBag\SyliusWishlistPlugin\Command\Wishlist\CopySelectedProductsToOtherWishlist; +use BitBag\SyliusWishlistPlugin\Exception\WishlistProductsActionFailedException; use Doctrine\Common\Collections\ArrayCollection; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface; +use Symfony\Component\Messenger\Exception\HandlerFailedException; use Symfony\Component\Messenger\MessageBusInterface; +use Symfony\Contracts\Translation\TranslatorInterface; final class CopySelectedProductsToOtherWishlistAction { private MessageBusInterface $commandBus; + private FlashBagInterface $flashBag; + + private TranslatorInterface $translator; + public function __construct( - MessageBusInterface $commandBus + MessageBusInterface $commandBus, + FlashBagInterface $flashBag, + TranslatorInterface $translator ) { $this->commandBus = $commandBus; + $this->flashBag = $flashBag; + $this->translator = $translator; } public function __invoke(Request $request): Response @@ -42,6 +54,11 @@ public function __invoke(Request $request): Response $copyProductsToAnotherWishlist = new CopySelectedProductsToOtherWishlist($selectedProducts, $destinedWishlist); $this->commandBus->dispatch($copyProductsToAnotherWishlist); + $this->flashBag->add( + 'success', + $this->translator->trans('bitbag_sylius_wishlist_plugin.ui.copied_selected_wishlist_items') + ); + return new JsonResponse(); } } diff --git a/src/Resources/assets/shop/js/handleCopyToWishlistListModal.js b/src/Resources/assets/shop/js/handleCopyToWishlistListModal.js index a905f575..197b0ffd 100644 --- a/src/Resources/assets/shop/js/handleCopyToWishlistListModal.js +++ b/src/Resources/assets/shop/js/handleCopyToWishlistListModal.js @@ -42,7 +42,7 @@ const setAddWishlistModal = () => { }, 900); console.error(error); } finally { - + location.reload(); } }, } @@ -59,4 +59,3 @@ const turnOnListener = () => { }; turnOnListener(); - diff --git a/src/Resources/config/services.yml b/src/Resources/config/services.yml index a3f05909..37effbb9 100644 --- a/src/Resources/config/services.yml +++ b/src/Resources/config/services.yml @@ -309,13 +309,8 @@ services: bitbag_sylius_wishlist_plugin.controller.action.copy_selected_products_to_other_wishlist: class: BitBag\SyliusWishlistPlugin\Controller\Action\CopySelectedProductsToOtherWishlistAction arguments: - - "@sylius.context.cart" - - "@form.factory" - - "@session.flash_bag" - "@sylius.command_bus" - - "@bitbag_sylius_wishlist_plugin.processor.wishlist_command_processor" - - "@router" - - "@bitbag_sylius_wishlist_plugin.repository.wishlist" + - "@session.flash_bag" - "@translator" tags: - { name: controller.service_arguments }