|
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\Entity\ItemHolderInterface; |
|
27
|
|
|
use Eccube\Entity\Master\OrderItemType; |
|
28
|
|
|
use Eccube\Entity\Master\TaxDisplayType; |
|
29
|
|
|
use Eccube\Entity\Master\TaxType; |
|
30
|
|
|
use Eccube\Entity\Order; |
|
31
|
|
|
use Eccube\Entity\ShipmentItem; |
|
32
|
|
|
use Eccube\Entity\Shipping; |
|
33
|
|
|
use Eccube\Service\PurchaseFlow\ItemHolderProcessor; |
|
34
|
|
|
use Eccube\Service\PurchaseFlow\ProcessResult; |
|
35
|
|
|
use Eccube\Service\PurchaseFlow\PurchaseContext; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* 送料明細追加. |
|
39
|
|
|
*/ |
|
40
|
|
|
class DeliveryFeeProcessor implements ItemHolderProcessor |
|
41
|
|
|
{ |
|
42
|
|
|
private $app; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
|
|
|
|
|
45
|
|
|
* DeliveryFeeProcessor constructor. |
|
46
|
|
|
* |
|
47
|
|
|
* @param $app |
|
|
|
|
|
|
48
|
|
|
*/ |
|
49
|
|
|
public function __construct($app) |
|
50
|
|
|
{ |
|
51
|
|
|
$this->app = $app; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @param ItemHolderInterface $itemHolder |
|
56
|
|
|
* @param PurchaseContext $context |
|
57
|
|
|
* |
|
58
|
|
|
* @return ProcessResult |
|
59
|
|
|
*/ |
|
60
|
|
|
public function process(ItemHolderInterface $itemHolder, PurchaseContext $context) |
|
61
|
|
|
{ |
|
62
|
|
|
if ($this->containsDeliveryFeeItem($itemHolder) == false) { |
|
|
|
|
|
|
63
|
|
|
$this->addDeliveryFeeItem($itemHolder); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
return ProcessResult::success(); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @param ItemHolderInterface $itemHolder |
|
71
|
|
|
* |
|
72
|
|
|
* @return bool |
|
73
|
|
|
*/ |
|
74
|
|
|
private function containsDeliveryFeeItem(ItemHolderInterface $itemHolder) |
|
75
|
|
|
{ |
|
76
|
|
|
foreach ($itemHolder->getItems() as $item) { |
|
77
|
|
|
if ($item->isDeliveryFee()) { |
|
78
|
|
|
return true; |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
return false; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* TODO 送料無料計算. |
|
87
|
|
|
* |
|
88
|
|
|
* @param ItemHolderInterface $itemHolder |
|
89
|
|
|
*/ |
|
90
|
|
|
private function addDeliveryFeeItem(ItemHolderInterface $itemHolder) |
|
91
|
|
|
{ |
|
92
|
|
|
$DeliveryFeeType = $this->app['eccube.repository.master.order_item_type']->find(OrderItemType::DELIVERY_FEE); |
|
93
|
|
|
// TODO |
|
94
|
|
|
$TaxInclude = $this->app['orm.em']->getRepository(TaxDisplayType::class)->find(TaxDisplayType::INCLUDED); |
|
95
|
|
|
$Taxion = $this->app['orm.em']->getRepository(TaxType::class)->find(TaxType::TAXATION); |
|
96
|
|
|
|
|
97
|
|
|
/** @var Order $Order */ |
|
98
|
|
|
$Order = $itemHolder; |
|
99
|
|
|
/* @var Shipping $Shipping */ |
|
100
|
|
|
foreach ($Order->getShippings() as $Shipping) { |
|
101
|
|
|
$ShipmentItem = new ShipmentItem(); |
|
102
|
|
|
$ShipmentItem->setProductName('送料') |
|
103
|
|
|
->setPrice($Shipping->getShippingDeliveryFee()) |
|
104
|
|
|
->setPriceIncTax($Shipping->getShippingDeliveryFee()) |
|
105
|
|
|
->setTaxRate(8) |
|
106
|
|
|
->setQuantity(1) |
|
107
|
|
|
->setOrderItemType($DeliveryFeeType) |
|
108
|
|
|
->setShipping($Shipping) |
|
109
|
|
|
->setTaxDisplayType($TaxInclude) |
|
110
|
|
|
->setTaxType($Taxion); |
|
111
|
|
|
|
|
112
|
|
|
$itemHolder->addItem($ShipmentItem); |
|
113
|
|
|
$Shipping->addShipmentItem($ShipmentItem); |
|
114
|
|
|
} |
|
115
|
|
|
} |
|
116
|
|
|
} |
|
117
|
|
|
|