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 Doctrine\ORM\EntityManagerInterface; |
17
|
|
|
use Eccube\Entity\BaseInfo; |
18
|
|
|
use Eccube\Entity\ItemHolderInterface; |
19
|
|
|
use Eccube\Entity\Master\OrderItemType; |
20
|
|
|
use Eccube\Entity\Master\TaxDisplayType; |
21
|
|
|
use Eccube\Entity\Master\TaxType; |
22
|
|
|
use Eccube\Entity\Order; |
23
|
|
|
use Eccube\Entity\OrderItem; |
24
|
|
|
use Eccube\Service\PurchaseFlow\ItemHolderProcessor; |
25
|
|
|
use Eccube\Service\PurchaseFlow\ProcessResult; |
26
|
|
|
use Eccube\Service\PurchaseFlow\PurchaseContext; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* 使用ポイント値引明細追加. |
30
|
|
|
*/ |
31
|
|
|
class UsePointProcessor implements ItemHolderProcessor |
32
|
|
|
{ |
33
|
|
|
/** |
34
|
|
|
* @var EntityManagerInterface |
35
|
|
|
*/ |
36
|
|
|
protected $entityManager; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var BaseInfo |
40
|
|
|
*/ |
41
|
|
|
protected $BaseInfo; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* UsePointProcessor constructor. |
45
|
|
|
* |
46
|
|
|
* @param EntityManagerInterface $entityManager |
47
|
|
|
* @param BaseInfo $BaseInfo |
48
|
|
|
*/ |
49
|
|
|
public function __construct(EntityManagerInterface $entityManager, BaseInfo $BaseInfo) |
50
|
|
|
{ |
51
|
|
|
$this->entityManager = $entityManager; |
52
|
|
|
$this->BaseInfo = $BaseInfo; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @param ItemHolderInterface $itemHolder |
57
|
|
|
* @param PurchaseContext $context |
58
|
|
|
* |
59
|
|
|
* @return ProcessResult |
60
|
|
|
*/ |
61
|
|
|
public function process(ItemHolderInterface $itemHolder, PurchaseContext $context) |
62
|
|
|
{ |
63
|
|
|
if ($itemHolder->getUsePoint() > 0) { |
64
|
|
|
if ($itemHolder->getUsePoint() > $context->getUser()->getPoint()) { |
65
|
|
|
// TODO カートに戻さないように修正する |
66
|
|
|
return ProcessResult::error('利用ポイントが所有ポイントを上回っています.'); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
// XXX delete/insert ではなく, update/insert の方がいいかも |
70
|
|
|
$this->removePointDiscountItem($itemHolder); |
71
|
|
|
|
72
|
|
|
return $this->addPointDiscountItem($itemHolder); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
return ProcessResult::success(); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* 明細追加処理 |
80
|
|
|
* |
81
|
|
|
* @param ItemHolderInterface $itemHolder |
82
|
|
|
*/ |
83
|
|
|
protected function addPointDiscountItem(ItemHolderInterface $itemHolder) |
84
|
|
|
{ |
85
|
|
|
$DiscountType = $this->entityManager |
86
|
|
|
->find(OrderItemType::class, OrderItemType::DISCOUNT); |
87
|
|
|
// TODO |
88
|
|
|
$TaxInclude = $this->entityManager |
89
|
|
|
->find(TaxDisplayType::class, TaxDisplayType::INCLUDED); |
90
|
|
|
$Taxion = $this->entityManager |
91
|
|
|
->find(TaxType::class, TaxType::TAXATION); |
92
|
|
|
|
93
|
|
|
/** @var Order $Order */ |
94
|
|
|
$Order = $itemHolder; |
95
|
|
|
|
96
|
|
|
$priceOfUsePoint = $this->usePointToPrice($Order->getUsePoint()); |
97
|
|
|
if (($itemHolder->getTotal() + $priceOfUsePoint) < 0) { |
98
|
|
|
// TODO カートに戻さないように修正する |
99
|
|
|
// TODO 送料・手数料も考慮する |
100
|
|
|
return ProcessResult::error('利用ポイントがお支払い金額を上回っています.'); |
101
|
|
|
} |
102
|
|
|
$OrderItem = new OrderItem(); |
103
|
|
|
$OrderItem->setProductName('ポイント値引') |
104
|
|
|
->setPrice($priceOfUsePoint) |
105
|
|
|
->setPriceIncTax($priceOfUsePoint) |
106
|
|
|
->setTaxRate(8) |
107
|
|
|
->setQuantity(1) |
108
|
|
|
->setOrderItemType($DiscountType) |
109
|
|
|
->setTaxDisplayType($TaxInclude) |
110
|
|
|
->setTaxType($Taxion) |
111
|
|
|
->setOrder($itemHolder); |
|
|
|
|
112
|
|
|
$itemHolder->addItem($OrderItem); |
113
|
|
|
|
114
|
|
|
return ProcessResult::success(); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* 既存のポイント明細を削除する. |
119
|
|
|
* |
120
|
|
|
* @param ItemHolderInterface $itemHolder |
121
|
|
|
*/ |
122
|
|
View Code Duplication |
protected function removePointDiscountItem(ItemHolderInterface $itemHolder) |
|
|
|
|
123
|
|
|
{ |
124
|
|
|
foreach ($itemHolder->getItems() as $item) { |
125
|
|
|
if ($item->isDiscount() && $item->getProductName() == 'ポイント値引') { |
|
|
|
|
126
|
|
|
$itemHolder->removeOrderItem($item); |
|
|
|
|
127
|
|
|
$this->entityManager->remove($item); |
128
|
|
|
} |
129
|
|
|
} |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* 利用ポイントを単価に換算する. |
134
|
|
|
* |
135
|
|
|
* @param integer $usePoint 利用ポイント |
136
|
|
|
* |
137
|
|
|
* @return integer |
138
|
|
|
*/ |
139
|
|
|
protected function usePointToPrice($usePoint) |
140
|
|
|
{ |
141
|
|
|
return ($usePoint * $this->BaseInfo->getPointConversionRate()) * -1; |
142
|
|
|
} |
143
|
|
|
} |
144
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: