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\Repository\DeliveryRepository; |
18
|
|
|
use Eccube\Service\PurchaseFlow\InvalidItemException; |
19
|
|
|
use Eccube\Service\PurchaseFlow\PurchaseContext; |
20
|
|
|
use Eccube\Service\PurchaseFlow\ItemValidator; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* 販売種別に配送業者が設定されているかどうか. |
24
|
|
|
*/ |
25
|
|
|
class DeliverySettingValidator extends ItemValidator |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* @var DeliveryRepository |
29
|
|
|
*/ |
30
|
|
|
protected $deliveryRepository; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* DeliverySettingValidator constructor. |
34
|
|
|
* |
35
|
|
|
* @param DeliveryRepository $deliveryRepository |
36
|
|
|
*/ |
37
|
161 |
|
public function __construct(DeliveryRepository $deliveryRepository) |
38
|
|
|
{ |
39
|
161 |
|
$this->deliveryRepository = $deliveryRepository; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* validate |
44
|
|
|
* |
45
|
|
|
* @param ItemInterface $item |
46
|
|
|
* @param PurchaseContext $context |
47
|
|
|
* |
48
|
|
|
* @throws InvalidItemException |
49
|
|
|
*/ |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @param ItemInterface $item |
53
|
|
|
* @param PurchaseContext $context |
54
|
|
|
* |
55
|
|
|
* @throws InvalidItemException |
56
|
|
|
*/ |
57
|
80 |
|
protected function validate(ItemInterface $item, PurchaseContext $context) |
58
|
|
|
{ |
59
|
80 |
|
if (!$item->isProduct()) { |
60
|
51 |
|
return; |
61
|
|
|
} |
62
|
|
|
|
63
|
80 |
|
$SaleType = $item->getProductClass()->getSaleType(); |
64
|
80 |
|
$Deliveries = $this->deliveryRepository->findBy(['SaleType' => $SaleType, 'visible' => true]); |
65
|
|
|
|
66
|
80 |
|
if (empty($Deliveries)) { |
67
|
1 |
|
$this->throwInvalidItemException('cart.product.not.saletype', $item->getProductClass()); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* handle |
73
|
|
|
* |
74
|
|
|
* @param ItemInterface $item |
75
|
|
|
* @param PurchaseContext $context |
76
|
|
|
*/ |
77
|
1 |
|
protected function handle(ItemInterface $item, PurchaseContext $context) |
78
|
|
|
{ |
79
|
1 |
|
$item->setQuantity(0); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|