-
-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathWatchlistItemHandler.php
More file actions
46 lines (36 loc) · 1.15 KB
/
WatchlistItemHandler.php
File metadata and controls
46 lines (36 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
declare(strict_types=1);
namespace Extcode\CartProducts\Handler;
/*
* This file is part of the package extcode/cart-products.
*
* For the full copyright and license information, please read the
* LICENSE file that was distributed with this source code.
*/
use Extcode\CartProducts\Domain\DoctrineRepository\Product\ProductRepository;
use Extcode\CartProducts\Domain\Model\WatchlistItem;
use WerkraumMedia\Watchlist\Domain\ItemHandlerInterface;
use WerkraumMedia\Watchlist\Domain\Model\Item;
final class WatchlistItemHandler implements ItemHandlerInterface
{
public function __construct(
private readonly ProductRepository $productRepository,
) {}
public function return(string $identifier): ?Item
{
list($uid, $detailPid) = explode('-', $identifier);
$product = $this->productRepository->findProductByUid((int)$uid);
if ($product === false) {
return null;
}
return new WatchlistItem(
(int)$uid,
(int)$detailPid,
(string)$product['title']
);
}
public function handlesType(): string
{
return 'CartProducts';
}
}