|
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\BaseInfo; |
|
17
|
|
|
use Eccube\Entity\ItemHolderInterface; |
|
18
|
|
|
use Eccube\Entity\Order; |
|
19
|
|
|
use Eccube\Service\PurchaseFlow\ItemHolderPreprocessor; |
|
20
|
|
|
use Eccube\Service\PurchaseFlow\PurchaseContext; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* 送料無料条件を適用する. |
|
24
|
|
|
* お届け先ごとに条件判定を行う. |
|
25
|
|
|
*/ |
|
26
|
|
|
class DeliveryFeeFreeByShippingPreprocessor implements ItemHolderPreprocessor |
|
27
|
|
|
{ |
|
28
|
|
|
/** |
|
29
|
|
|
* @var BaseInfo |
|
30
|
|
|
*/ |
|
31
|
|
|
protected $BaseInfo; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* DeliveryFeeProcessor constructor. |
|
35
|
|
|
* |
|
36
|
|
|
* @param BaseInfo $BaseInfo |
|
37
|
|
|
*/ |
|
38
|
70 |
|
public function __construct(BaseInfo $BaseInfo) |
|
39
|
|
|
{ |
|
40
|
70 |
|
$this->BaseInfo = $BaseInfo; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @param ItemHolderInterface $itemHolder |
|
45
|
|
|
* @param PurchaseContext $context |
|
|
|
|
|
|
46
|
|
|
*/ |
|
47
|
62 |
|
public function process(ItemHolderInterface $itemHolder, PurchaseContext $context) |
|
48
|
|
|
{ |
|
49
|
62 |
|
if (!($this->BaseInfo->getDeliveryFreeAmount() || $this->BaseInfo->getDeliveryFreeQuantity())) { |
|
50
|
52 |
|
return; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
// Orderの場合はお届け先ごとに判定する. |
|
54
|
10 |
|
if ($itemHolder instanceof Order) { |
|
55
|
|
|
/** @var Order $Order */ |
|
56
|
10 |
|
$Order = $itemHolder; |
|
57
|
10 |
|
foreach ($Order->getShippings() as $Shipping) { |
|
58
|
10 |
|
$isFree = false; |
|
59
|
10 |
|
$total = 0; |
|
60
|
10 |
|
$quantity = 0; |
|
61
|
10 |
|
foreach ($Shipping->getProductOrderItems() as $Item) { |
|
62
|
10 |
|
$total += $Item->getPriceIncTax() * $Item->getQuantity(); |
|
63
|
10 |
|
$quantity += $Item->getQuantity(); |
|
64
|
|
|
} |
|
65
|
|
|
// 送料無料(金額)を超えている |
|
66
|
10 |
|
if ($this->BaseInfo->getDeliveryFreeAmount()) { |
|
67
|
5 |
|
if ($total >= $this->BaseInfo->getDeliveryFreeAmount()) { |
|
68
|
3 |
|
$isFree = true; |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
// 送料無料(個数)を超えている |
|
72
|
10 |
|
if ($this->BaseInfo->getDeliveryFreeQuantity()) { |
|
73
|
5 |
|
if ($quantity >= $this->BaseInfo->getDeliveryFreeQuantity()) { |
|
74
|
3 |
|
$isFree = true; |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
10 |
|
if ($isFree) { |
|
78
|
6 |
|
foreach ($Shipping->getOrderItems() as $Item) { |
|
79
|
6 |
|
if ($Item->isDeliveryFee()) { |
|
80
|
10 |
|
$Item->setQuantity(0); |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|