|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file was created by developers working at BitBag |
|
5
|
|
|
* Do you need more information about us and what we do? Visit our https://bitbag.io website! |
|
6
|
|
|
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
declare(strict_types=1); |
|
10
|
|
|
|
|
11
|
|
|
namespace BitBag\SyliusWishlistPlugin\Controller\Action; |
|
12
|
|
|
|
|
13
|
|
|
use BitBag\SyliusWishlistPlugin\Entity\WishlistInterface; |
|
14
|
|
|
use BitBag\SyliusWishlistPlugin\Repository\WishlistRepositoryInterface; |
|
15
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
|
16
|
|
|
use Symfony\Component\HttpFoundation\RedirectResponse; |
|
17
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
18
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
19
|
|
|
use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface; |
|
20
|
|
|
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; |
|
21
|
|
|
use Symfony\Contracts\Translation\TranslatorInterface; |
|
22
|
|
|
|
|
23
|
|
|
final class CleanWishlistAction |
|
24
|
|
|
{ |
|
25
|
|
|
private WishlistRepositoryInterface $wishlistRepository; |
|
26
|
|
|
|
|
27
|
|
|
private EntityManagerInterface $wishlistManager; |
|
28
|
|
|
|
|
29
|
|
|
private FlashBagInterface $flashBag; |
|
30
|
|
|
|
|
31
|
|
|
private TranslatorInterface $translator; |
|
32
|
|
|
|
|
33
|
|
|
private UrlGeneratorInterface $urlGenerator; |
|
34
|
|
|
|
|
35
|
|
|
public function __construct( |
|
36
|
|
|
WishlistRepositoryInterface $wishlistRepository, |
|
37
|
|
|
EntityManagerInterface $wishlistManager, |
|
38
|
|
|
FlashBagInterface $flashBag, |
|
39
|
|
|
TranslatorInterface $translator, |
|
40
|
|
|
UrlGeneratorInterface $urlGenerator |
|
41
|
|
|
) { |
|
42
|
|
|
$this->wishlistRepository = $wishlistRepository; |
|
43
|
|
|
$this->wishlistManager = $wishlistManager; |
|
44
|
|
|
$this->urlGenerator = $urlGenerator; |
|
45
|
|
|
$this->flashBag = $flashBag; |
|
46
|
|
|
$this->translator = $translator; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function __invoke(int $wishlistId, Request $request): Response |
|
50
|
|
|
{ |
|
51
|
|
|
/** @var WishlistInterface $wishlist */ |
|
52
|
|
|
$wishlist = $this->wishlistRepository->find($wishlistId); |
|
53
|
|
|
|
|
54
|
|
|
$wishlist->clear(); |
|
|
|
|
|
|
55
|
|
|
$this->wishlistManager->flush(); |
|
56
|
|
|
|
|
57
|
|
|
$this->flashBag->add('success', $this->translator->trans('bitbag_sylius_wishlist_plugin.ui.clear_wishlist')); |
|
58
|
|
|
|
|
59
|
|
|
return new RedirectResponse( |
|
60
|
|
|
$this->urlGenerator->generate('bitbag_sylius_wishlist_plugin_shop_wishlist_show_chosen_wishlist', [ |
|
61
|
|
|
'wishlistId' => $wishlistId, |
|
62
|
|
|
]) |
|
63
|
|
|
); |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|