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

DeliveryFeeFreeProcessor::process()   C

Complexity

Conditions 8
Paths 18

Size

Total Lines 33
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 8
eloc 15
nc 18
nop 2
dl 0
loc 33
rs 5.3846
c 0
b 0
f 0
1
<?php
2
/*
3
 * This file is part of EC-CUBE
4
 *
5
 * Copyright(c) 2000-2017 LOCKON CO.,LTD. All Rights Reserved.
6
 *
7
 * http://www.lockon.co.jp/
8
 *
9
 * This program is free software; you can redistribute it and/or
10
 * modify it under the terms of the GNU General Public License
11
 * as published by the Free Software Foundation; either version 2
12
 * of the License, or (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU General Public License
20
 * along with this program; if not, write to the Free Software
21
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
 */
23
24
namespace Eccube\Service\PurchaseFlow\Processor;
25
26
use Eccube\Application;
27
use Eccube\Entity\ItemHolderInterface;
28
use Eccube\Service\PurchaseFlow\ItemHolderProcessor;
29
use Eccube\Service\PurchaseFlow\ProcessResult;
30
use Eccube\Service\PurchaseFlow\PurchaseContext;
31
32
/**
33
 * 送料無料条件.
34
 */
35
class DeliveryFeeFreeProcessor implements ItemHolderProcessor
36
{
37
    /**
38
     * @var Application
39
     */
40
    private $app;
41
42
    /**
43
     * DeliveryFeeProcessor constructor.
44
     *
45
     * @param Application $app
46
     */
47
    public function __construct(Application $app)
48
    {
49
        $this->app = $app;
50
    }
51
52
    /**
53
     * @param ItemHolderInterface $itemHolder
54
     * @param PurchaseContext     $context
55
     *
56
     * @return ProcessResult
57
     */
58
    public function process(ItemHolderInterface $itemHolder, PurchaseContext $context)
59
    {
60
        /* @var $BaseInfo \Eccube\Entity\BaseInfo */
61
        $BaseInfo = $this->app['eccube.repository.base_info']->get();
62
63
        $isDeliveryFree = false;
64
65
        if ($BaseInfo->getDeliveryFreeAmount()) {
66
            if ($BaseInfo->getDeliveryFreeAmount() <= $itemHolder->getTotal()) {
67
                // 送料無料(金額)を超えている
68
                $isDeliveryFree = true;
69
            }
70
        }
71
72
        if ($BaseInfo->getDeliveryFreeQuantity()) {
73
            if ($BaseInfo->getDeliveryFreeQuantity() <= $itemHolder->getQuantity()) {
74
                // 送料無料(個数)を超えている
75
                $isDeliveryFree = true;
76
            }
77
        }
78
79
        // 送料無料条件に合致した場合は、送料明細の個数を0に設定
80
        if ($isDeliveryFree) {
81
            $items = $itemHolder->getItems();
82
            foreach ($items as $item) {
83
                if ($item->isDeliveryFee()) {
84
                    $item->setQuantity(0);
85
                }
86
            }
87
        }
88
89
        return ProcessResult::success();
90
    }
91
}
92