| 1 | <?php |
||
| 13 | class StockValidator extends ValidatableItemProcessor |
||
| 14 | { |
||
| 15 | 16 | protected function validate(ItemInterface $item, PurchaseContext $context) |
|
| 16 | { |
||
| 17 | 16 | if (!$item->isProduct()) { |
|
| 18 | return; |
||
| 19 | } |
||
| 20 | 16 | if ($item->getProductClass()->getStockUnlimited()) { |
|
| 21 | 13 | return; |
|
| 22 | } |
||
| 23 | 3 | $stock = $item->getProductClass()->getStock(); |
|
| 24 | 3 | $quantity = $item->getQuantity(); |
|
| 25 | 3 | if ($stock == 0) { |
|
| 26 | throw ItemValidateException::fromProductClass('cart.zero.stock', $item->getProductClass()); |
||
| 27 | } |
||
| 28 | 3 | if ($stock < $quantity) { |
|
| 29 | 1 | throw ItemValidateException::fromProductClass('cart.over.stock', $item->getProductClass()); |
|
| 30 | } |
||
| 31 | } |
||
| 32 | |||
| 33 | 1 | protected function handle(ItemInterface $item, PurchaseContext $context) |
|
| 38 | } |
||
| 39 |