|
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\Form\Type\WishlistCollectionType; |
|
15
|
|
|
use BitBag\SyliusWishlistPlugin\Processor\WishlistCommandProcessorInterface; |
|
16
|
|
|
use BitBag\SyliusWishlistPlugin\Repository\WishlistRepositoryInterface; |
|
17
|
|
|
use Sylius\Component\Order\Context\CartContextInterface; |
|
18
|
|
|
use Symfony\Component\Form\FormFactoryInterface; |
|
19
|
|
|
use Symfony\Component\Form\FormInterface; |
|
20
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
21
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
22
|
|
|
use Twig\Environment; |
|
23
|
|
|
|
|
24
|
|
|
final class ShowChosenWishlistAction |
|
25
|
|
|
{ |
|
26
|
|
|
private WishlistRepositoryInterface $wishlistRepository; |
|
27
|
|
|
|
|
28
|
|
|
private CartContextInterface $cartContext; |
|
29
|
|
|
|
|
30
|
|
|
private FormFactoryInterface $formFactory; |
|
31
|
|
|
|
|
32
|
|
|
private Environment $twigEnvironment; |
|
33
|
|
|
|
|
34
|
|
|
private WishlistCommandProcessorInterface $wishlistCommandProcessor; |
|
35
|
|
|
|
|
36
|
|
|
public function __construct( |
|
37
|
|
|
WishlistRepositoryInterface $wishlistRepository, |
|
38
|
|
|
CartContextInterface $cartContext, |
|
39
|
|
|
FormFactoryInterface $formFactory, |
|
40
|
|
|
Environment $twigEnvironment, |
|
41
|
|
|
WishlistCommandProcessorInterface $wishlistCommandProcessor |
|
42
|
|
|
) { |
|
43
|
|
|
$this->wishlistRepository = $wishlistRepository; |
|
44
|
|
|
$this->cartContext = $cartContext; |
|
45
|
|
|
$this->formFactory = $formFactory; |
|
46
|
|
|
$this->twigEnvironment = $twigEnvironment; |
|
47
|
|
|
$this->wishlistCommandProcessor = $wishlistCommandProcessor; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function __invoke(int $wishlistId, Request $request): Response |
|
51
|
|
|
{ |
|
52
|
|
|
/** @var WishlistInterface $wishlist */ |
|
53
|
|
|
$wishlist = $this->wishlistRepository->find($wishlistId); |
|
54
|
|
|
|
|
55
|
|
|
$form = $this->createForm($wishlist); |
|
56
|
|
|
|
|
57
|
|
|
return new Response( |
|
58
|
|
|
$this->twigEnvironment->render('@BitBagSyliusWishlistPlugin/WishlistDetails/index.html.twig', [ |
|
59
|
|
|
'wishlist' => $wishlist, |
|
60
|
|
|
'form' => $form->createView(), |
|
61
|
|
|
]) |
|
62
|
|
|
); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
private function createForm(WishlistInterface $wishlist): FormInterface |
|
66
|
|
|
{ |
|
67
|
|
|
$cart = $this->cartContext->getCart(); |
|
68
|
|
|
|
|
69
|
|
|
$commandsArray = $this->wishlistCommandProcessor->createAddCommandCollectionFromWishlistProducts($wishlist->getWishlistProducts()); |
|
70
|
|
|
|
|
71
|
|
|
return $this->formFactory->create(WishlistCollectionType::class, ['items' => $commandsArray], [ |
|
72
|
|
|
'cart' => $cart, |
|
73
|
|
|
]); |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|