|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace BitBag\SyliusWishlistPlugin\CommandHandler\Wishlist; |
|
6
|
|
|
|
|
7
|
|
|
use BitBag\SyliusWishlistPlugin\Command\Wishlist\RemoveProductFromWishlist; |
|
8
|
|
|
use BitBag\SyliusWishlistPlugin\Repository\WishlistRepositoryInterface; |
|
9
|
|
|
use BitBag\SyliusWishlistPlugin\Updater\WishlistUpdaterInterface; |
|
10
|
|
|
use Sylius\Component\Core\Repository\ProductRepositoryInterface; |
|
11
|
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
|
12
|
|
|
use Symfony\Component\Messenger\Handler\MessageHandlerInterface; |
|
13
|
|
|
|
|
14
|
|
|
final class RemoveProductFromWishlistHandler implements MessageHandlerInterface |
|
15
|
|
|
{ |
|
16
|
|
|
private ProductRepositoryInterface $productRepository; |
|
17
|
|
|
|
|
18
|
|
|
private WishlistRepositoryInterface $wishlistRepository; |
|
19
|
|
|
|
|
20
|
|
|
private WishlistUpdaterInterface $wishlistUpdater; |
|
21
|
|
|
|
|
22
|
|
|
public function __construct( |
|
23
|
|
|
ProductRepositoryInterface $productRepository, |
|
24
|
|
|
WishlistRepositoryInterface $wishlistRepository, |
|
25
|
|
|
WishlistUpdaterInterface $wishlistUpdater |
|
26
|
|
|
) { |
|
27
|
|
|
$this->productRepository = $productRepository; |
|
28
|
|
|
$this->wishlistRepository = $wishlistRepository; |
|
29
|
|
|
$this->wishlistUpdater = $wishlistUpdater; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function __invoke(RemoveProductFromWishlist $removeProductFromWishlist) |
|
33
|
|
|
{ |
|
34
|
|
|
$product = $this->productRepository->find($removeProductFromWishlist->getProductIdValue()); |
|
35
|
|
|
$wishlist = $this->wishlistRepository->findByToken($removeProductFromWishlist->getWishlistTokenValue()); |
|
36
|
|
|
|
|
37
|
|
|
if (!$product || !$wishlist) { |
|
38
|
|
|
throw new NotFoundHttpException(); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
$this->wishlistUpdater->removeProductFromWishlist($wishlist, $product); |
|
42
|
|
|
} |
|
43
|
|
|
} |
|
44
|
|
|
|