Failed Conditions
Push — experimental/3.1 ( 965511...751c7a )
by chihiro
21s
created

DeliverySettingValidator::handle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Eccube\Service\PurchaseFlow\Processor;
4
5
use Eccube\Entity\ItemInterface;
6
use Eccube\Repository\DeliveryRepository;
7
use Eccube\Service\PurchaseFlow\ItemValidateException;
8
use Eccube\Service\PurchaseFlow\ValidatableItemProcessor;
9
use Eccube\Service\PurchaseFlow\PurchaseContext;
10
11
/**
12
 * 商品種別に配送業者が設定されているかどうか.
13
 */
14
class DeliverySettingValidator extends ValidatableItemProcessor
15
{
16
    /**
17
     * @var DeliveryRepository
18
     */
19
    protected $deliveryRepository;
20
21
    public function __construct(DeliveryRepository $deliveryRepository)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
22
    {
23
        $this->deliveryRepository = $deliveryRepository;
24
    }
25
26
    protected function validate(ItemInterface $item, PurchaseContext $context)
27
    {
28
        if (!$item->isProduct()) {
29
            return;
30
        }
31
32
        $ProductType = $item->getProductClass()->getProductType();
33
        $Deliveries = $this->deliveryRepository->findBy(['ProductType' => $ProductType]);
34
35
        if (empty($Deliveries)) {
36
            throw new ItemValidateException('cart.product.not.producttype', ['%product%' => $item->getProductClass()->getProduct()->getName()]);
37
        }
38
    }
39
40
    protected function handle(ItemInterface $item, PurchaseContext $context)
41
    {
42
        $item->setQuantity(0);
43
    }
44
}
45