|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file has been created by developers from BitBag. |
|
5
|
|
|
* Feel free to contact us once you face any issues or want to start |
|
6
|
|
|
* You can find more information about us on https://bitbag.io and write us |
|
7
|
|
|
* an email on [email protected]. |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
declare(strict_types=1); |
|
11
|
|
|
|
|
12
|
|
|
namespace BitBag\SyliusWishlistPlugin\CommandHandler\Wishlist; |
|
13
|
|
|
|
|
14
|
|
|
use BitBag\SyliusWishlistPlugin\Command\Wishlist\CopySelectedProductsToOtherWishlist; |
|
15
|
|
|
use BitBag\SyliusWishlistPlugin\Command\Wishlist\WishlistItemInterface; |
|
16
|
|
|
use BitBag\SyliusWishlistPlugin\Controller\Action\AddProductVariantToWishlistAction; |
|
17
|
|
|
use Doctrine\Common\Collections\Collection; |
|
18
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
19
|
|
|
use Symfony\Component\HttpFoundation\RequestStack; |
|
20
|
|
|
|
|
21
|
|
|
final class CopySelectedProductsToOtherWishlistHandler |
|
22
|
|
|
{ |
|
23
|
|
|
private AddProductVariantToWishlistAction $addProductVariantToWishlistAction; |
|
24
|
|
|
|
|
25
|
|
|
private RequestStack $requestStack; |
|
26
|
|
|
|
|
27
|
|
|
public function __construct(AddProductVariantToWishlistAction $addProductVariantToWishlistAction, RequestStack $requestStack) |
|
28
|
|
|
{ |
|
29
|
|
|
$this->addProductVariantToWishlistAction = $addProductVariantToWishlistAction; |
|
30
|
|
|
$this->requestStack = $requestStack; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function __invoke(CopySelectedProductsToOtherWishlist $copySelectedProductsToOtherWishlistCommand): void |
|
34
|
|
|
{ |
|
35
|
|
|
$destinedWishlistId = $copySelectedProductsToOtherWishlistCommand->getDestinedWishlistId(); |
|
36
|
|
|
|
|
37
|
|
|
$currentRequest = $this->requestStack->getCurrentRequest(); |
|
38
|
|
|
|
|
39
|
|
|
$this->copyWishlistProductsToOtherWishlist($copySelectedProductsToOtherWishlistCommand->getWishlistProducts(), $currentRequest); |
|
|
|
|
|
|
40
|
|
|
|
|
41
|
|
|
$this->addProductVariantToWishlistAction->__invoke($destinedWishlistId, $currentRequest); |
|
|
|
|
|
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
private function copyWishlistProductsToOtherWishlist(Collection $wishlistProducts, Request $request): void |
|
45
|
|
|
{ |
|
46
|
|
|
$variantIds = []; |
|
47
|
|
|
|
|
48
|
|
|
/** @var WishlistItemInterface $wishlistProduct */ |
|
49
|
|
|
foreach ($wishlistProducts as $wishlistProduct) { |
|
50
|
|
|
$variantIds[] = $wishlistProduct->getCartItem()->getCartItem()->getVariant()->getId(); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
$request->attributes->set('variantId', $variantIds); |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|