Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

location reload after request #112

Merged
merged 1 commit into from
Mar 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const setAddWishlistModal = () => {
}, 900);
console.error(error);
} finally {

location.reload();
}
},
}
Expand All @@ -59,4 +59,3 @@ const turnOnListener = () => {
};

turnOnListener();

7 changes: 1 addition & 6 deletions src/Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down