1 | <?php |
||
23 | class StockValidator extends ItemValidator |
||
24 | { |
||
25 | /** |
||
26 | * @param ItemInterface $item |
||
27 | * @param PurchaseContext $context |
||
28 | * |
||
29 | * @throws \Eccube\Service\PurchaseFlow\InvalidItemException |
||
30 | */ |
||
31 | 81 | protected function validate(ItemInterface $item, PurchaseContext $context) |
|
32 | { |
||
33 | 81 | if (!$item->isProduct()) { |
|
34 | return; |
||
35 | } |
||
36 | 81 | if ($item->getProductClass()->isStockUnlimited()) { |
|
37 | 30 | return; |
|
38 | } |
||
39 | 54 | $stock = $item->getProductClass()->getStock(); |
|
40 | 54 | $quantity = $item->getQuantity(); |
|
41 | 54 | if ($stock == 0) { |
|
42 | 7 | $this->throwInvalidItemException('cart.zero.stock', $item->getProductClass()); |
|
43 | } |
||
44 | 53 | if ($stock < $quantity) { |
|
45 | 10 | $this->throwInvalidItemException('cart.over.stock', $item->getProductClass()); |
|
46 | } |
||
47 | } |
||
48 | |||
49 | 17 | protected function handle(ItemInterface $item, PurchaseContext $context) |
|
54 | } |
||
55 |