| @@ 47-71 (lines=25) @@ | ||
| 44 | * @ShoppingFlow |
|
| 45 | * @OrderFlow |
|
| 46 | */ |
|
| 47 | class SaleLimitOneValidator extends ItemValidator |
|
| 48 | { |
|
| 49 | /** |
|
| 50 | * @param ItemInterface $item |
|
| 51 | * @param PurchaseContext $context |
|
| 52 | * |
|
| 53 | * @throws InvalidItemException |
|
| 54 | */ |
|
| 55 | protected function validate(ItemInterface $item, PurchaseContext $context) |
|
| 56 | { |
|
| 57 | if (!$item->isProduct()) { |
|
| 58 | return; |
|
| 59 | } |
|
| 60 | ||
| 61 | $quantity = $item->getQuantity(); |
|
| 62 | if (1 < $quantity) { |
|
| 63 | $this->throwInvalidItemException('商品は1個しか購入できません。'); |
|
| 64 | } |
|
| 65 | } |
|
| 66 | ||
| 67 | protected function handle(ItemInterface $item, PurchaseContext $context) |
|
| 68 | { |
|
| 69 | $item->setQuantity(1); |
|
| 70 | } |
|
| 71 | } |
|
| 72 | ||
| @@ 21-52 (lines=32) @@ | ||
| 18 | use Eccube\Service\PurchaseFlow\PurchaseContext; |
|
| 19 | use Eccube\Service\PurchaseFlow\ItemValidator; |
|
| 20 | ||
| 21 | class DisplayStatusValidator extends ItemValidator |
|
| 22 | { |
|
| 23 | /** |
|
| 24 | * @param ItemInterface $item |
|
| 25 | * @param PurchaseContext $context |
|
| 26 | * |
|
| 27 | * @throws \Eccube\Service\PurchaseFlow\InvalidItemException |
|
| 28 | */ |
|
| 29 | protected function validate(ItemInterface $item, PurchaseContext $context) |
|
| 30 | { |
|
| 31 | if (!$item->isProduct()) { |
|
| 32 | return; |
|
| 33 | } |
|
| 34 | $ProductClass = $item->getProductClass(); |
|
| 35 | if (!$ProductClass->isEnable()) { |
|
| 36 | $this->throwInvalidItemException('cart.product.not.status'); |
|
| 37 | } |
|
| 38 | } |
|
| 39 | ||
| 40 | /** |
|
| 41 | * handle |
|
| 42 | * |
|
| 43 | * @param ItemInterface $item |
|
| 44 | * @param PurchaseContext $context |
|
| 45 | */ |
|
| 46 | protected function handle(ItemInterface $item, PurchaseContext $context) |
|
| 47 | { |
|
| 48 | if ($item instanceof CartItem) { |
|
| 49 | $item->setQuantity(0); |
|
| 50 | } |
|
| 51 | } |
|
| 52 | } |
|
| 53 | ||