1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of EC-CUBE |
5
|
|
|
* |
6
|
|
|
* Copyright(c) LOCKON CO.,LTD. All Rights Reserved. |
7
|
|
|
* |
8
|
|
|
* http://www.lockon.co.jp/ |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Eccube\Service\PurchaseFlow\Processor; |
15
|
|
|
|
16
|
|
|
use Eccube\Entity\ItemInterface; |
17
|
|
|
use Eccube\Service\PurchaseFlow\PurchaseContext; |
18
|
|
|
use Eccube\Service\PurchaseFlow\ItemValidator; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* 在庫制限チェック. |
22
|
|
|
*/ |
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) |
50
|
|
|
{ |
51
|
17 |
|
$stock = $item->getProductClass()->getStock(); |
52
|
17 |
|
$item->setQuantity($stock); |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|