|
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\Service\PurchaseFlow\ItemHolderPreprocessor; |
|
17
|
|
|
use Eccube\Entity\ItemHolderInterface; |
|
18
|
|
|
use Eccube\Service\PurchaseFlow\PurchaseContext; |
|
19
|
|
|
use Eccube\Entity\OrderItem; |
|
20
|
|
|
use Eccube\Repository\Master\OrderItemTypeRepository; |
|
21
|
|
|
use Eccube\Repository\Master\TaxDisplayTypeRepository; |
|
22
|
|
|
use Eccube\Entity\Master\OrderItemType; |
|
23
|
|
|
use Eccube\Entity\Master\TaxDisplayType; |
|
24
|
|
|
use Eccube\Entity\Order; |
|
25
|
|
|
use Eccube\Entity\Payment; |
|
26
|
|
|
use Eccube\Repository\Master\TaxTypeRepository; |
|
27
|
|
|
use Eccube\Entity\Master\TaxType; |
|
28
|
|
|
|
|
29
|
|
|
class PaymentChargePreprocessor implements ItemHolderPreprocessor |
|
30
|
|
|
{ |
|
31
|
|
|
/** |
|
32
|
|
|
* @var OrderItemTypeRepository |
|
33
|
|
|
*/ |
|
34
|
|
|
protected $orderItemTypeRepository; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @var TaxDisplayTypeRepository |
|
38
|
|
|
*/ |
|
39
|
|
|
protected $taxDisplayTypeRepository; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @var TaxTypeRepository |
|
43
|
|
|
*/ |
|
44
|
|
|
protected $taxTypeRepository; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* PaymentChargePreprocessor constructor. |
|
48
|
|
|
* |
|
49
|
|
|
* @param OrderItemTypeRepository $orderItemTypeRepository |
|
50
|
|
|
* @param TaxDisplayTypeRepository $taxDisplayTypeRepository |
|
51
|
|
|
* @param TaxTypeRepository $taxTypeRepository |
|
52
|
|
|
*/ |
|
53
|
|
|
public function __construct( |
|
54
|
|
|
OrderItemTypeRepository $orderItemTypeRepository, |
|
55
|
|
|
TaxDisplayTypeRepository $taxDisplayTypeRepository, |
|
56
|
|
|
TaxTypeRepository $taxTypeRepository |
|
57
|
|
|
) { |
|
58
|
|
|
$this->orderItemTypeRepository = $orderItemTypeRepository; |
|
59
|
|
|
$this->taxDisplayTypeRepository = $taxDisplayTypeRepository; |
|
60
|
|
|
$this->taxTypeRepository = $taxTypeRepository; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* {@inheritdoc} |
|
65
|
|
|
* |
|
66
|
|
|
* @param ItemHolderInterface $itemHolder |
|
67
|
|
|
* @param PurchaseContext $context |
|
68
|
|
|
*/ |
|
69
|
|
|
public function process(ItemHolderInterface $itemHolder, PurchaseContext $context) |
|
70
|
|
|
{ |
|
71
|
|
|
if (!$itemHolder instanceof Order) { |
|
72
|
|
|
return; |
|
73
|
|
|
} |
|
74
|
|
|
if (!$itemHolder->getPayment() instanceof Payment || !$itemHolder->getPayment()->getId()) { |
|
75
|
|
|
return; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
foreach ($itemHolder->getItems() as $item) { |
|
79
|
|
|
if ($item->isCharge()) { |
|
80
|
|
|
$item->setPrice($itemHolder->getPayment()->getCharge()); |
|
81
|
|
|
|
|
82
|
|
|
return; |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
$this->addChargeItem($itemHolder); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* Add charge item to item holder |
|
91
|
|
|
* |
|
92
|
|
|
* @param ItemHolderInterface $itemHolder |
|
93
|
|
|
*/ |
|
94
|
|
|
protected function addChargeItem(ItemHolderInterface $itemHolder) |
|
95
|
|
|
{ |
|
96
|
|
|
/** @var Order $itemHolder */ |
|
97
|
|
|
$OrderItemType = $this->orderItemTypeRepository->find(OrderItemType::CHARGE); |
|
98
|
|
|
$TaxDisplayType = $this->taxDisplayTypeRepository->find(TaxDisplayType::INCLUDED); |
|
99
|
|
|
$Taxion = $this->taxTypeRepository->find(TaxType::TAXATION); |
|
100
|
|
|
$item = new OrderItem(); |
|
101
|
|
|
$item->setProductName(trans('paymentprocessor.label.charge')) |
|
102
|
|
|
->setQuantity(1) |
|
103
|
|
|
->setPrice($itemHolder->getPayment()->getCharge()) |
|
104
|
|
|
->setOrderItemType($OrderItemType) |
|
|
|
|
|
|
105
|
|
|
->setOrder($itemHolder) |
|
106
|
|
|
->setTaxDisplayType($TaxDisplayType) |
|
|
|
|
|
|
107
|
|
|
->setTaxType($Taxion); |
|
|
|
|
|
|
108
|
|
|
$itemHolder->addItem($item); |
|
109
|
|
|
} |
|
110
|
|
|
} |
|
111
|
|
|
|
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.