|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace BitBag\SyliusWishlistPlugin\CommandHandler\Wishlist; |
|
6
|
|
|
|
|
7
|
|
|
use BitBag\SyliusWishlistPlugin\Command\Wishlist\RemoveProductVariantFromWishlist; |
|
8
|
|
|
use BitBag\SyliusWishlistPlugin\Exception\ProductVariantNotFoundException; |
|
9
|
|
|
use BitBag\SyliusWishlistPlugin\Repository\WishlistRepositoryInterface; |
|
10
|
|
|
use BitBag\SyliusWishlistPlugin\Updater\WishlistUpdaterInterface; |
|
11
|
|
|
use Sylius\Component\Core\Repository\ProductVariantRepositoryInterface; |
|
12
|
|
|
use Symfony\Component\Messenger\Handler\MessageHandlerInterface; |
|
13
|
|
|
|
|
14
|
|
|
final class RemoveProductVariantFromWishlistHandler implements MessageHandlerInterface |
|
15
|
|
|
{ |
|
16
|
|
|
private WishlistRepositoryInterface $wishlistRepository; |
|
17
|
|
|
|
|
18
|
|
|
private ProductVariantRepositoryInterface $productVariantRepository; |
|
19
|
|
|
|
|
20
|
|
|
private WishlistUpdaterInterface $wishlistUpdater; |
|
21
|
|
|
|
|
22
|
|
|
public function __construct( |
|
23
|
|
|
WishlistRepositoryInterface $wishlistRepository, |
|
24
|
|
|
ProductVariantRepositoryInterface $productVariantRepository, |
|
25
|
|
|
WishlistUpdaterInterface $wishlistUpdater |
|
26
|
|
|
) |
|
27
|
|
|
{ |
|
28
|
|
|
$this->productVariantRepository = $productVariantRepository; |
|
29
|
|
|
$this->wishlistRepository = $wishlistRepository; |
|
30
|
|
|
$this->wishlistUpdater = $wishlistUpdater; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function __invoke(RemoveProductVariantFromWishlist $removeProductVariantFromWishlist) |
|
34
|
|
|
{ |
|
35
|
|
|
$variant = $this->productVariantRepository->find($removeProductVariantFromWishlist->getProductVariantIdValue()); |
|
36
|
|
|
$wishlist = $this->wishlistRepository->findByToken($removeProductVariantFromWishlist->getWishlistTokenValue()); |
|
37
|
|
|
|
|
38
|
|
|
if(null === $variant) { |
|
39
|
|
|
throw new ProductVariantNotFoundException( |
|
40
|
|
|
sprintf("The Product %s does not exist", $removeProductVariantFromWishlist->getProductVariantIdValue()) |
|
41
|
|
|
); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
$this->wishlistUpdater->removeProductVariantFromWishlist($wishlist, $variant); |
|
|
|
|
|
|
45
|
|
|
} |
|
46
|
|
|
} |
|
47
|
|
|
|