1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is part of EC-CUBE |
4
|
|
|
* |
5
|
|
|
* Copyright(c) 2000-2015 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; |
25
|
|
|
|
26
|
|
|
use Doctrine\ORM\EntityManager; |
27
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
28
|
|
|
use Eccube\Annotation\Service; |
29
|
|
|
use Eccube\Common\EccubeConfig; |
30
|
|
|
use Eccube\Entity\BaseInfo; |
31
|
|
|
use Eccube\Entity\Customer; |
32
|
|
|
use Eccube\Entity\Delivery; |
33
|
|
|
use Eccube\Entity\MailHistory; |
34
|
|
|
use Eccube\Entity\Master\DeviceType; |
35
|
|
|
use Eccube\Entity\Master\OrderStatus; |
36
|
|
|
use Eccube\Entity\Order; |
37
|
|
|
use Eccube\Entity\OrderItem; |
38
|
|
|
use Eccube\Entity\Product; |
39
|
|
|
use Eccube\Entity\ProductClass; |
40
|
|
|
use Eccube\Entity\Shipping; |
41
|
|
|
use Eccube\Event\EccubeEvents; |
42
|
|
|
use Eccube\Event\EventArgs; |
43
|
|
|
use Eccube\Exception\CartException; |
44
|
|
|
use Eccube\Form\Type\ShippingItemType; |
45
|
|
|
use Eccube\Repository\CustomerAddressRepository; |
46
|
|
|
use Eccube\Repository\DeliveryFeeRepository; |
47
|
|
|
use Eccube\Repository\DeliveryRepository; |
48
|
|
|
use Eccube\Repository\DeliveryTimeRepository; |
49
|
|
|
use Eccube\Repository\MailTemplateRepository; |
50
|
|
|
use Eccube\Repository\Master\DeviceTypeRepository; |
51
|
|
|
use Eccube\Repository\Master\OrderStatusRepository; |
52
|
|
|
use Eccube\Repository\Master\PrefRepository; |
53
|
|
|
use Eccube\Repository\OrderRepository; |
54
|
|
|
use Eccube\Repository\PaymentRepository; |
55
|
|
|
use Eccube\Repository\TaxRuleRepository; |
56
|
|
|
use Eccube\Util\StringUtil; |
57
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcher; |
58
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
59
|
|
|
use Symfony\Component\Form\Extension\Core\Type\CollectionType; |
60
|
|
|
use Symfony\Component\Form\FormFactory; |
61
|
|
|
use Symfony\Component\Form\FormFactoryInterface; |
62
|
|
|
use Symfony\Component\HttpFoundation\Session\Session; |
63
|
|
|
use Symfony\Component\HttpFoundation\Session\SessionInterface; |
64
|
|
|
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @Service |
68
|
|
|
*/ |
69
|
|
|
class ShoppingService |
70
|
|
|
{ |
71
|
|
|
/** |
72
|
|
|
* @var MailTemplateRepository |
73
|
|
|
*/ |
74
|
|
|
protected $mailTemplateRepository; |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @var MailService |
78
|
|
|
*/ |
79
|
|
|
protected $mailService; |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @var EventDispatcher |
83
|
|
|
*/ |
84
|
|
|
protected $eventDispatcher; |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @var FormFactory |
88
|
|
|
*/ |
89
|
|
|
protected $formFactory; |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @var DeliveryFeeRepository |
93
|
|
|
*/ |
94
|
|
|
protected $deliveryFeeRepository; |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @var TaxRuleRepository |
98
|
|
|
*/ |
99
|
|
|
protected $taxRuleRepository; |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @var CustomerAddressRepository |
103
|
|
|
*/ |
104
|
|
|
protected $customerAddressRepository; |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @var DeliveryRepository |
108
|
|
|
*/ |
109
|
|
|
protected $deliveryRepository; |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @var DeliveryTimeRepository |
113
|
|
|
*/ |
114
|
|
|
protected $deliveryTimeRepository; |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @var OrderStatusRepository |
118
|
|
|
*/ |
119
|
|
|
protected $orderStatusRepository; |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* @var PaymentRepository |
123
|
|
|
*/ |
124
|
|
|
protected $paymentRepository; |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @var DeviceTypeRepository |
128
|
|
|
*/ |
129
|
|
|
protected $deviceTypeRepository; |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* @var EntityManager |
133
|
|
|
*/ |
134
|
|
|
protected $entityManager; |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* @var EccubeConfig |
138
|
|
|
*/ |
139
|
|
|
protected $eccubeConfig; |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* @var PrefRepository |
143
|
|
|
*/ |
144
|
|
|
protected $prefRepository; |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* @var Session |
148
|
|
|
*/ |
149
|
|
|
protected $session; |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* @var OrderRepository |
153
|
|
|
*/ |
154
|
|
|
protected $orderRepository; |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* @var BaseInfo |
158
|
|
|
*/ |
159
|
|
|
protected $BaseInfo; |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* @var \Eccube\Service\CartService |
163
|
|
|
*/ |
164
|
|
|
protected $cartService; |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* @var \Eccube\Service\OrderService |
168
|
|
|
* |
169
|
|
|
* @deprecated |
170
|
|
|
*/ |
171
|
|
|
protected $orderService; |
172
|
|
|
|
173
|
|
|
/** |
174
|
|
|
* @var AuthorizationCheckerInterface |
175
|
|
|
*/ |
176
|
|
|
protected $authorizationChecker; |
177
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* ShoppingService constructor. |
180
|
|
|
* |
181
|
|
|
* @param MailTemplateRepository $mailTemplateRepository |
|
|
|
|
182
|
|
|
* @param MailService $mailService |
|
|
|
|
183
|
|
|
* @param EventDispatcher $eventDispatcher |
|
|
|
|
184
|
|
|
* @param FormFactory $formFactory |
|
|
|
|
185
|
|
|
* @param DeliveryFeeRepository $deliveryFeeRepository |
|
|
|
|
186
|
|
|
* @param TaxRuleRepository $taxRuleRepository |
|
|
|
|
187
|
|
|
* @param CustomerAddressRepository $customerAddressRepository |
|
|
|
|
188
|
|
|
* @param DeliveryRepository $deliveryRepository |
|
|
|
|
189
|
|
|
* @param DeliveryTimeRepository $deliveryTimeRepository |
|
|
|
|
190
|
|
|
* @param OrderStatusRepository $orderStatusRepository |
|
|
|
|
191
|
|
|
* @param PaymentRepository $paymentRepository |
|
|
|
|
192
|
|
|
* @param DeviceTypeRepository $deviceTypeRepository |
|
|
|
|
193
|
|
|
* @param EntityManager $entityManager |
|
|
|
|
194
|
|
|
* @param EccubeConfig $eccubeConfig |
|
|
|
|
195
|
|
|
* @param PrefRepository $prefRepository |
|
|
|
|
196
|
|
|
* @param Session $session |
|
|
|
|
197
|
|
|
* @param OrderRepository $orderRepository |
|
|
|
|
198
|
|
|
* @param CartService $cartService |
|
|
|
|
199
|
|
|
* @param OrderService $orderService |
|
|
|
|
200
|
|
|
* @param BaseInfo $BaseInfo |
|
|
|
|
201
|
|
|
* @param AuthorizationCheckerInterface $authorizationChecker |
202
|
|
|
*/ |
203
|
36 |
|
public function __construct( |
204
|
|
|
MailTemplateRepository $mailTemplateRepository, |
205
|
|
|
MailService $mailService, |
206
|
|
|
EventDispatcherInterface $eventDispatcher, |
207
|
|
|
FormFactoryInterface $formFactory, |
208
|
|
|
DeliveryFeeRepository $deliveryFeeRepository, |
209
|
|
|
TaxRuleRepository $taxRuleRepository, |
210
|
|
|
CustomerAddressRepository $customerAddressRepository, |
211
|
|
|
DeliveryRepository $deliveryRepository, |
212
|
|
|
DeliveryTimeRepository $deliveryTimeRepository, |
213
|
|
|
OrderStatusRepository $orderStatusRepository, |
214
|
|
|
PaymentRepository $paymentRepository, |
215
|
|
|
DeviceTypeRepository $deviceTypeRepository, |
216
|
|
|
EntityManagerInterface $entityManager, |
217
|
|
|
EccubeConfig $eccubeConfig, |
218
|
|
|
PrefRepository $prefRepository, |
219
|
|
|
SessionInterface $session, |
220
|
|
|
OrderRepository $orderRepository, |
221
|
|
|
CartService $cartService, |
222
|
|
|
OrderService $orderService, |
223
|
|
|
BaseInfo $BaseInfo, |
224
|
|
|
AuthorizationCheckerInterface $authorizationChecker |
225
|
|
|
) { |
226
|
36 |
|
$this->mailTemplateRepository = $mailTemplateRepository; |
227
|
36 |
|
$this->mailService = $mailService; |
228
|
36 |
|
$this->eventDispatcher = $eventDispatcher; |
|
|
|
|
229
|
36 |
|
$this->formFactory = $formFactory; |
|
|
|
|
230
|
36 |
|
$this->deliveryFeeRepository = $deliveryFeeRepository; |
231
|
36 |
|
$this->taxRuleRepository = $taxRuleRepository; |
232
|
36 |
|
$this->customerAddressRepository = $customerAddressRepository; |
233
|
36 |
|
$this->deliveryRepository = $deliveryRepository; |
234
|
36 |
|
$this->deliveryTimeRepository = $deliveryTimeRepository; |
235
|
36 |
|
$this->orderStatusRepository = $orderStatusRepository; |
236
|
36 |
|
$this->paymentRepository = $paymentRepository; |
237
|
36 |
|
$this->deviceTypeRepository = $deviceTypeRepository; |
238
|
36 |
|
$this->entityManager = $entityManager; |
|
|
|
|
239
|
36 |
|
$this->eccubeConfig = $eccubeConfig; |
240
|
36 |
|
$this->prefRepository = $prefRepository; |
241
|
36 |
|
$this->session = $session; |
|
|
|
|
242
|
36 |
|
$this->orderRepository = $orderRepository; |
243
|
36 |
|
$this->cartService = $cartService; |
244
|
36 |
|
$this->orderService = $orderService; |
|
|
|
|
245
|
36 |
|
$this->BaseInfo = $BaseInfo; |
246
|
36 |
|
$this->authorizationChecker = $authorizationChecker; |
247
|
|
|
} |
248
|
|
|
|
249
|
|
|
/** |
250
|
|
|
* セッションにセットされた受注情報を取得 |
251
|
|
|
* |
252
|
|
|
* @param null $status |
253
|
|
|
* |
254
|
|
|
* @return null|object |
255
|
|
|
*/ |
256
|
26 |
|
public function getOrder($status = null) |
257
|
|
|
{ |
258
|
|
|
// 受注データを取得 |
259
|
26 |
|
$preOrderId = $this->cartService->getPreOrderId(); |
260
|
26 |
|
if (!$preOrderId) { |
261
|
26 |
|
return null; |
262
|
|
|
} |
263
|
|
|
|
264
|
|
|
$condition = [ |
265
|
13 |
|
'pre_order_id' => $preOrderId, |
266
|
|
|
]; |
267
|
|
|
|
268
|
13 |
|
if (!is_null($status)) { |
269
|
|
|
$condition += [ |
270
|
13 |
|
'OrderStatus' => $status, |
271
|
|
|
]; |
272
|
|
|
} |
273
|
|
|
|
274
|
13 |
|
$Order = $this->orderRepository->findOneBy($condition); |
275
|
|
|
|
276
|
13 |
|
return $Order; |
277
|
|
|
} |
278
|
|
|
|
279
|
|
|
/** |
|
|
|
|
280
|
|
|
* 非会員情報を取得 |
281
|
|
|
* |
282
|
|
|
* @param $sesisonKey |
|
|
|
|
283
|
|
|
* |
284
|
|
|
* @return $Customer|null |
|
|
|
|
285
|
|
|
*/ |
286
|
|
|
public function getNonMember($sesisonKey) |
287
|
|
|
{ |
288
|
|
|
// 非会員でも一度会員登録されていればショッピング画面へ遷移 |
289
|
|
|
$nonMember = $this->session->get($sesisonKey); |
290
|
|
|
if (is_null($nonMember)) { |
291
|
|
|
return null; |
292
|
|
|
} |
293
|
|
|
if (!array_key_exists('customer', $nonMember) || !array_key_exists('pref', $nonMember)) { |
294
|
|
|
return null; |
295
|
|
|
} |
296
|
|
|
|
297
|
|
|
$Customer = $nonMember['customer']; |
298
|
|
|
$Customer->setPref($this->prefRepository->find($nonMember['pref'])); |
299
|
|
|
|
300
|
|
|
foreach ($Customer->getCustomerAddresses() as $CustomerAddress) { |
301
|
|
|
$Pref = $CustomerAddress->getPref(); |
302
|
|
|
if ($Pref) { |
303
|
|
|
$CustomerAddress->setPref($this->prefRepository->find($Pref->getId())); |
304
|
|
|
} |
305
|
|
|
} |
306
|
|
|
|
307
|
|
|
return $Customer; |
308
|
|
|
} |
309
|
|
|
|
310
|
|
|
/** |
|
|
|
|
311
|
|
|
* 受注情報を作成 |
312
|
|
|
* |
313
|
|
|
* @param $Customer |
|
|
|
|
314
|
|
|
* |
315
|
|
|
* @return \Eccube\Entity\Order |
316
|
|
|
*/ |
317
|
|
|
public function createOrder($Customer) |
318
|
|
|
{ |
319
|
|
|
// ランダムなpre_order_idを作成 |
320
|
|
View Code Duplication |
do { |
|
|
|
|
321
|
|
|
$preOrderId = sha1(StringUtil::random(32)); |
322
|
|
|
$Order = $this->orderRepository->findOneBy([ |
323
|
|
|
'pre_order_id' => $preOrderId, |
324
|
|
|
'OrderStatus' => OrderStatus::PROCESSING, |
325
|
|
|
]); |
326
|
|
|
} while ($Order); |
327
|
|
|
|
328
|
|
|
// 受注情報、受注明細情報、お届け先情報、配送商品情報を作成 |
329
|
|
|
$Order = $this->registerPreOrder( |
330
|
|
|
$Customer, |
331
|
|
|
$preOrderId); |
332
|
|
|
|
333
|
|
|
$this->cartService->setPreOrderId($preOrderId); |
334
|
|
|
$this->cartService->save(); |
335
|
|
|
|
336
|
|
|
return $Order; |
337
|
|
|
} |
338
|
|
|
|
339
|
|
|
/** |
|
|
|
|
340
|
|
|
* 仮受注情報作成 |
341
|
|
|
* |
342
|
|
|
* @param $Customer |
|
|
|
|
343
|
|
|
* @param $preOrderId |
|
|
|
|
344
|
|
|
* |
345
|
|
|
* @return mixed |
346
|
|
|
* |
347
|
|
|
* @throws \Doctrine\ORM\NoResultException |
348
|
|
|
* @throws \Doctrine\ORM\NonUniqueResultException |
349
|
|
|
*/ |
350
|
|
|
public function registerPreOrder(Customer $Customer, $preOrderId) |
351
|
|
|
{ |
352
|
|
|
$this->em = $this->entityManager; |
|
|
|
|
353
|
|
|
|
354
|
|
|
// 受注情報を作成 |
355
|
|
|
$Order = $this->getNewOrder($Customer); |
356
|
|
|
$Order->setPreOrderId($preOrderId); |
357
|
|
|
|
358
|
|
|
$mobileDetect = new \Mobile_Detect(); |
359
|
|
|
$DeviceType = $this->deviceTypeRepository->find($mobileDetect->isMobile() ? DeviceType::DEVICE_TYPE_SP : DeviceType::DEVICE_TYPE_PC); |
360
|
|
|
$Order->setDeviceType($DeviceType); |
361
|
|
|
|
362
|
|
|
$this->entityManager->persist($Order); |
363
|
|
|
|
364
|
|
|
// 配送業者情報を取得 |
365
|
|
|
$deliveries = $this->getDeliveriesCart(); |
366
|
|
|
|
367
|
|
|
// お届け先情報を作成 |
368
|
|
|
$Order = $this->getNewShipping($Order, $Customer, $deliveries); |
369
|
|
|
|
370
|
|
|
// 受注明細情報、配送商品情報を作成 |
371
|
|
|
$Order = $this->getNewDetails($Order); |
372
|
|
|
|
373
|
|
|
// 小計 |
374
|
|
|
$subTotal = $this->orderService->getSubTotal($Order); |
|
|
|
|
375
|
|
|
|
376
|
|
|
// 消費税のみの小計 |
377
|
|
|
$tax = $this->orderService->getTotalTax($Order); |
|
|
|
|
378
|
|
|
|
379
|
|
|
// 配送料合計金額 |
380
|
|
|
// TODO CalculateDeliveryFeeStrategy でセットする |
381
|
|
|
// $Order->setDeliveryFeeTotal($this->getShippingDeliveryFeeTotal($Order->getShippings())); |
|
|
|
|
382
|
|
|
|
383
|
|
|
// 小計 |
384
|
|
|
$Order->setSubTotal($subTotal); |
385
|
|
|
|
386
|
|
|
// 配送料無料条件(合計金額) |
387
|
|
|
$this->setDeliveryFreeAmount($Order); |
388
|
|
|
|
389
|
|
|
// 配送料無料条件(合計数量) |
390
|
|
|
$this->setDeliveryFreeQuantity($Order); |
391
|
|
|
|
392
|
|
|
// 初期選択の支払い方法をセット |
393
|
|
|
$payments = $this->paymentRepository->findAllowedPayments($deliveries); |
394
|
|
|
$payments = $this->getPayments($payments, $subTotal); |
395
|
|
|
|
396
|
|
|
if (count($payments) > 0) { |
397
|
|
|
$payment = $payments[0]; |
398
|
|
|
$Order->setPayment($payment); |
399
|
|
|
$Order->setPaymentMethod($payment->getMethod()); |
400
|
|
|
$Order->setCharge($payment->getCharge()); |
401
|
|
|
} else { |
402
|
|
|
$Order->setCharge(0); |
403
|
|
|
} |
404
|
|
|
|
405
|
|
|
$Order->setTax($tax); |
406
|
|
|
|
407
|
|
|
// 合計金額の計算 |
408
|
|
|
$this->calculatePrice($Order); |
409
|
|
|
|
410
|
|
|
$this->entityManager->flush(); |
411
|
|
|
|
412
|
|
|
return $Order; |
413
|
|
|
} |
414
|
|
|
|
415
|
|
|
/** |
|
|
|
|
416
|
|
|
* 受注情報を作成 |
417
|
|
|
* |
418
|
|
|
* @param $Customer |
|
|
|
|
419
|
|
|
* |
420
|
|
|
* @return \Eccube\Entity\Order |
421
|
|
|
*/ |
422
|
|
|
public function getNewOrder(Customer $Customer) |
423
|
|
|
{ |
424
|
|
|
$Order = $this->newOrder(); |
425
|
|
|
$this->copyToOrderFromCustomer($Order, $Customer); |
426
|
|
|
|
427
|
|
|
return $Order; |
428
|
|
|
} |
429
|
|
|
|
430
|
|
|
/** |
431
|
|
|
* 受注情報を作成 |
432
|
|
|
* |
433
|
|
|
* @return \Eccube\Entity\Order |
434
|
|
|
*/ |
435
|
|
|
public function newOrder() |
436
|
|
|
{ |
437
|
|
|
$OrderStatus = $this->orderStatusRepository->find(OrderStatus::PROCESSING); |
438
|
|
|
$Order = new \Eccube\Entity\Order($OrderStatus); |
439
|
|
|
|
440
|
|
|
return $Order; |
441
|
|
|
} |
442
|
|
|
|
443
|
|
|
/** |
444
|
|
|
* 受注情報を作成 |
445
|
|
|
* |
446
|
|
|
* @param \Eccube\Entity\Order $Order |
|
|
|
|
447
|
|
|
* @param \Eccube\Entity\Customer|null $Customer |
448
|
|
|
* |
449
|
|
|
* @return \Eccube\Entity\Order |
450
|
|
|
*/ |
451
|
|
|
public function copyToOrderFromCustomer(Order $Order, Customer $Customer = null) |
452
|
|
|
{ |
453
|
|
|
if (is_null($Customer)) { |
454
|
|
|
return $Order; |
455
|
|
|
} |
456
|
|
|
|
457
|
|
|
if ($Customer->getId()) { |
458
|
|
|
$Order->setCustomer($Customer); |
459
|
|
|
} |
460
|
|
|
$Order |
461
|
|
|
->setName01($Customer->getName01()) |
462
|
|
|
->setName02($Customer->getName02()) |
463
|
|
|
->setKana01($Customer->getKana01()) |
464
|
|
|
->setKana02($Customer->getKana02()) |
465
|
|
|
->setCompanyName($Customer->getCompanyName()) |
466
|
|
|
->setEmail($Customer->getEmail()) |
467
|
|
|
->setTel01($Customer->getTel01()) |
468
|
|
|
->setTel02($Customer->getTel02()) |
469
|
|
|
->setTel03($Customer->getTel03()) |
470
|
|
|
->setFax01($Customer->getFax01()) |
471
|
|
|
->setFax02($Customer->getFax02()) |
472
|
|
|
->setFax03($Customer->getFax03()) |
473
|
|
|
->setZip01($Customer->getZip01()) |
474
|
|
|
->setZip02($Customer->getZip02()) |
475
|
|
|
->setZipCode($Customer->getZip01().$Customer->getZip02()) |
476
|
|
|
->setPref($Customer->getPref()) |
477
|
|
|
->setAddr01($Customer->getAddr01()) |
478
|
|
|
->setAddr02($Customer->getAddr02()) |
479
|
|
|
->setSex($Customer->getSex()) |
480
|
|
|
->setBirth($Customer->getBirth()) |
481
|
|
|
->setJob($Customer->getJob()); |
482
|
|
|
|
483
|
|
|
return $Order; |
484
|
|
|
} |
485
|
|
|
|
486
|
|
|
/** |
487
|
|
|
* 配送業者情報を取得 |
488
|
|
|
* |
489
|
|
|
* @return array |
490
|
|
|
*/ |
491
|
|
|
public function getDeliveriesCart() |
492
|
|
|
{ |
493
|
|
|
// カートに保持されている販売種別を取得 |
494
|
|
|
$saleTypes = $this->cartService->getSaleTypes(); |
|
|
|
|
495
|
|
|
|
496
|
|
|
return $this->getDeliveries($saleTypes); |
497
|
|
|
} |
498
|
|
|
|
499
|
|
|
/** |
500
|
|
|
* 配送業者情報を取得 |
501
|
|
|
* |
502
|
|
|
* @param Order $Order |
503
|
|
|
* |
504
|
|
|
* @return array |
505
|
|
|
*/ |
506
|
|
|
public function getDeliveriesOrder(Order $Order) |
507
|
|
|
{ |
508
|
|
|
// 受注情報から販売種別を取得 |
509
|
|
|
$saleTypes = $this->orderService->getSaleTypes($Order); |
|
|
|
|
510
|
|
|
|
511
|
|
|
return $this->getDeliveries($saleTypes); |
512
|
|
|
} |
513
|
|
|
|
514
|
|
|
/** |
|
|
|
|
515
|
|
|
* 配送業者情報を取得 |
516
|
|
|
* |
517
|
|
|
* @param $saleTypes |
|
|
|
|
518
|
|
|
* |
519
|
|
|
* @return array |
520
|
|
|
*/ |
521
|
|
|
public function getDeliveries($saleTypes) |
522
|
|
|
{ |
523
|
|
|
// 販売種別に紐づく配送業者を取得 |
524
|
|
|
$deliveries = $this->deliveryRepository->getDeliveries($saleTypes); |
525
|
|
|
|
526
|
|
|
if ($this->BaseInfo->isOptionMultipleShipping()) { |
527
|
|
|
// 複数配送対応 |
528
|
|
|
|
529
|
|
|
// 支払方法を取得 |
530
|
|
|
$payments = $this->paymentRepository->findAllowedPayments($deliveries); |
531
|
|
|
|
532
|
|
|
if (count($saleTypes) > 1) { |
533
|
|
|
// 販売種別が複数ある場合、配送対象となる配送業者を取得 |
534
|
|
|
$deliveries = $this->deliveryRepository->findAllowedDeliveries($saleTypes, $payments); |
535
|
|
|
} |
536
|
|
|
} |
537
|
|
|
|
538
|
|
|
return $deliveries; |
539
|
|
|
} |
540
|
|
|
|
541
|
|
|
/** |
|
|
|
|
542
|
|
|
* お届け先情報を作成 |
543
|
|
|
* |
544
|
|
|
* @param Order $Order |
|
|
|
|
545
|
|
|
* @param Customer $Customer |
|
|
|
|
546
|
|
|
* @param $deliveries |
|
|
|
|
547
|
|
|
* |
548
|
|
|
* @return Order |
549
|
|
|
*/ |
550
|
|
|
public function getNewShipping(Order $Order, Customer $Customer, $deliveries) |
551
|
|
|
{ |
552
|
|
|
$saleTypes = []; |
553
|
|
|
foreach ($deliveries as $Delivery) { |
554
|
|
|
if (!in_array($Delivery->getSaleType()->getId(), $saleTypes)) { |
555
|
|
|
$Shipping = new Shipping(); |
556
|
|
|
|
557
|
|
|
$this->copyToShippingFromCustomer($Shipping, $Customer) |
558
|
|
|
->setOrder($Order); |
559
|
|
|
|
560
|
|
|
// 配送料金の設定 |
561
|
|
|
$this->setShippingDeliveryFee($Shipping, $Delivery); |
562
|
|
|
|
563
|
|
|
$this->entityManager->persist($Shipping); |
564
|
|
|
|
565
|
|
|
$Order->addShipping($Shipping); |
566
|
|
|
|
567
|
|
|
$saleTypes[] = $Delivery->getProductType()->getId(); |
568
|
|
|
} |
569
|
|
|
} |
570
|
|
|
|
571
|
|
|
return $Order; |
572
|
|
|
} |
573
|
|
|
|
574
|
|
|
/** |
575
|
|
|
* お届け先情報を作成 |
576
|
|
|
* |
577
|
|
|
* @param \Eccube\Entity\Shipping $Shipping |
|
|
|
|
578
|
|
|
* @param \Eccube\Entity\Customer|null $Customer |
579
|
|
|
* |
580
|
|
|
* @return \Eccube\Entity\Shipping |
581
|
|
|
*/ |
582
|
|
|
public function copyToShippingFromCustomer(Shipping $Shipping, Customer $Customer = null) |
583
|
|
|
{ |
584
|
|
|
if (is_null($Customer)) { |
585
|
|
|
return $Shipping; |
586
|
|
|
} |
587
|
|
|
|
588
|
|
|
$CustomerAddress = $this->customerAddressRepository->findOneBy( |
589
|
|
|
['Customer' => $Customer], |
590
|
|
|
['id' => 'ASC'] |
591
|
|
|
); |
592
|
|
|
|
593
|
|
|
if (!is_null($CustomerAddress)) { |
594
|
|
|
$Shipping |
595
|
|
|
->setName01($CustomerAddress->getName01()) |
596
|
|
|
->setName02($CustomerAddress->getName02()) |
597
|
|
|
->setKana01($CustomerAddress->getKana01()) |
598
|
|
|
->setKana02($CustomerAddress->getKana02()) |
599
|
|
|
->setCompanyName($CustomerAddress->getCompanyName()) |
600
|
|
|
->setTel01($CustomerAddress->getTel01()) |
601
|
|
|
->setTel02($CustomerAddress->getTel02()) |
602
|
|
|
->setTel03($CustomerAddress->getTel03()) |
603
|
|
|
->setFax01($CustomerAddress->getFax01()) |
604
|
|
|
->setFax02($CustomerAddress->getFax02()) |
605
|
|
|
->setFax03($CustomerAddress->getFax03()) |
606
|
|
|
->setZip01($CustomerAddress->getZip01()) |
607
|
|
|
->setZip02($CustomerAddress->getZip02()) |
608
|
|
|
->setZipCode($CustomerAddress->getZip01().$CustomerAddress->getZip02()) |
609
|
|
|
->setPref($CustomerAddress->getPref()) |
610
|
|
|
->setAddr01($CustomerAddress->getAddr01()) |
611
|
|
|
->setAddr02($CustomerAddress->getAddr02()); |
612
|
|
|
} else { |
613
|
|
|
$Shipping |
614
|
|
|
->setName01($Customer->getName01()) |
615
|
|
|
->setName02($Customer->getName02()) |
616
|
|
|
->setKana01($Customer->getKana01()) |
617
|
|
|
->setKana02($Customer->getKana02()) |
618
|
|
|
->setCompanyName($Customer->getCompanyName()) |
619
|
|
|
->setTel01($Customer->getTel01()) |
620
|
|
|
->setTel02($Customer->getTel02()) |
621
|
|
|
->setTel03($Customer->getTel03()) |
622
|
|
|
->setFax01($Customer->getFax01()) |
623
|
|
|
->setFax02($Customer->getFax02()) |
624
|
|
|
->setFax03($Customer->getFax03()) |
625
|
|
|
->setZip01($Customer->getZip01()) |
626
|
|
|
->setZip02($Customer->getZip02()) |
627
|
|
|
->setZipCode($Customer->getZip01().$Customer->getZip02()) |
628
|
|
|
->setPref($Customer->getPref()) |
629
|
|
|
->setAddr01($Customer->getAddr01()) |
630
|
|
|
->setAddr02($Customer->getAddr02()); |
631
|
|
|
} |
632
|
|
|
|
633
|
|
|
return $Shipping; |
634
|
|
|
} |
635
|
|
|
|
636
|
|
|
/** |
637
|
|
|
* 受注明細情報、配送商品情報を作成 |
638
|
|
|
* |
639
|
|
|
* @param Order $Order |
640
|
|
|
* |
641
|
|
|
* @return Order |
642
|
|
|
*/ |
643
|
|
|
public function getNewDetails(Order $Order) |
644
|
|
|
{ |
645
|
|
|
// 受注詳細, 配送商品 |
646
|
|
|
foreach ($this->cartService->getCart()->getCartItems() as $item) { |
647
|
|
|
/* @var $ProductClass \Eccube\Entity\ProductClass */ |
648
|
|
|
$ProductClass = $item->getProductClass(); |
649
|
|
|
/* @var $Product \Eccube\Entity\Product */ |
650
|
|
|
$Product = $ProductClass->getProduct(); |
651
|
|
|
|
652
|
|
|
$quantity = $item->getQuantity(); |
653
|
|
|
|
654
|
|
|
// 配送商品情報を作成 |
655
|
|
|
$this->getNewOrderItem($Order, $Product, $ProductClass, $quantity); |
656
|
|
|
} |
657
|
|
|
|
658
|
|
|
return $Order; |
659
|
|
|
} |
660
|
|
|
|
661
|
|
|
/** |
|
|
|
|
662
|
|
|
* 配送商品情報を作成 |
663
|
|
|
* |
664
|
|
|
* @param Order $Order |
|
|
|
|
665
|
|
|
* @param Product $Product |
|
|
|
|
666
|
|
|
* @param ProductClass $ProductClass |
667
|
|
|
* @param $quantity |
|
|
|
|
668
|
|
|
* |
669
|
|
|
* @return \Eccube\Entity\OrderItem |
670
|
|
|
*/ |
671
|
|
|
public function getNewOrderItem(Order $Order, Product $Product, ProductClass $ProductClass, $quantity) |
672
|
|
|
{ |
673
|
|
|
$OrderItem = new OrderItem(); |
674
|
|
|
$shippings = $Order->getShippings(); |
675
|
|
|
|
676
|
|
|
// 選択された商品がどのお届け先情報と関連するかチェック |
677
|
|
|
$Shipping = null; |
678
|
|
|
foreach ($shippings as $s) { |
679
|
|
|
if ($s->getDelivery()->getSaleType()->getId() == $ProductClass->getSaleType()->getId()) { |
680
|
|
|
// 販売種別が同一のお届け先情報と関連させる |
681
|
|
|
$Shipping = $s; |
682
|
|
|
break; |
683
|
|
|
} |
684
|
|
|
} |
685
|
|
|
|
686
|
|
|
if (is_null($Shipping)) { |
687
|
|
|
// お届け先情報と関連していない場合、エラー |
688
|
|
|
throw new CartException('shopping.delivery.not.saletype'); |
689
|
|
|
} |
690
|
|
|
|
691
|
|
|
// 商品ごとの配送料合計 |
692
|
|
|
$productDeliveryFeeTotal = 0; |
693
|
|
|
if ($this->BaseInfo->isOptionProductDeliveryFee()) { |
694
|
|
|
$productDeliveryFeeTotal = $ProductClass->getDeliveryFee() * $quantity; |
695
|
|
|
} |
696
|
|
|
|
697
|
|
|
$Shipping->setShippingDeliveryFee($Shipping->getShippingDeliveryFee() + $productDeliveryFeeTotal); |
698
|
|
|
|
699
|
|
|
$OrderItem->setShipping($Shipping) |
700
|
|
|
->setOrder($Order) |
701
|
|
|
->setProductClass($ProductClass) |
702
|
|
|
->setProduct($Product) |
703
|
|
|
->setProductName($Product->getName()) |
704
|
|
|
->setProductCode($ProductClass->getCode()) |
705
|
|
|
->setPrice($ProductClass->getPrice02()) |
706
|
|
|
->setQuantity($quantity); |
707
|
|
|
|
708
|
|
|
$ClassCategory1 = $ProductClass->getClassCategory1(); |
709
|
|
|
if (!is_null($ClassCategory1)) { |
710
|
|
|
$OrderItem->setClasscategoryName1($ClassCategory1->getName()); |
711
|
|
|
$OrderItem->setClassName1($ClassCategory1->getClassName()->getName()); |
712
|
|
|
} |
713
|
|
|
$ClassCategory2 = $ProductClass->getClassCategory2(); |
714
|
|
|
if (!is_null($ClassCategory2)) { |
715
|
|
|
$OrderItem->setClasscategoryName2($ClassCategory2->getName()); |
716
|
|
|
$OrderItem->setClassName2($ClassCategory2->getClassName()->getName()); |
717
|
|
|
} |
718
|
|
|
$Shipping->addOrderItem($OrderItem); |
719
|
|
|
$this->entityManager->persist($OrderItem); |
720
|
|
|
|
721
|
|
|
return $OrderItem; |
722
|
|
|
} |
723
|
|
|
|
724
|
|
|
/** |
|
|
|
|
725
|
|
|
* お届け先ごとの送料合計を取得 |
726
|
|
|
* |
727
|
|
|
* @param $shippings |
|
|
|
|
728
|
|
|
* |
729
|
|
|
* @return int |
730
|
|
|
*/ |
731
|
|
|
public function getShippingDeliveryFeeTotal($shippings) |
732
|
|
|
{ |
733
|
|
|
$deliveryFeeTotal = 0; |
734
|
|
|
foreach ($shippings as $Shipping) { |
735
|
|
|
$deliveryFeeTotal += $Shipping->getShippingDeliveryFee(); |
736
|
|
|
} |
737
|
|
|
|
738
|
|
|
return $deliveryFeeTotal; |
739
|
|
|
} |
740
|
|
|
|
741
|
|
|
/** |
742
|
|
|
* 商品ごとの配送料を取得 |
743
|
|
|
* |
744
|
|
|
* @param Shipping $Shipping |
745
|
|
|
* |
746
|
|
|
* @return int |
747
|
|
|
*/ |
748
|
|
|
public function getProductDeliveryFee(Shipping $Shipping) |
749
|
|
|
{ |
750
|
|
|
$productDeliveryFeeTotal = 0; |
751
|
|
|
$OrderItems = $Shipping->getOrderItems(); |
752
|
|
|
foreach ($OrderItems as $OrderItem) { |
753
|
|
|
$productDeliveryFeeTotal += $OrderItem->getProductClass()->getDeliveryFee() * $OrderItem->getQuantity(); |
754
|
|
|
} |
755
|
|
|
|
756
|
|
|
return $productDeliveryFeeTotal; |
757
|
|
|
} |
758
|
|
|
|
759
|
|
|
/** |
760
|
|
|
* 住所などの情報が変更された時に金額の再計算を行う |
761
|
|
|
* |
762
|
|
|
* @deprecated PurchaseFlowで行う |
763
|
|
|
* |
764
|
|
|
* @param Order $Order |
765
|
|
|
* |
766
|
|
|
* @return Order |
767
|
|
|
*/ |
768
|
|
|
public function getAmount(Order $Order) |
769
|
|
|
{ |
770
|
|
|
// 初期選択の配送業者をセット |
771
|
|
|
$shippings = $Order->getShippings(); |
|
|
|
|
772
|
|
|
|
773
|
|
|
// 配送料合計金額 |
774
|
|
|
// TODO CalculateDeliveryFeeStrategy でセットする |
775
|
|
|
// $Order->setDeliveryFeeTotal($this->getShippingDeliveryFeeTotal($shippings)); |
|
|
|
|
776
|
|
|
|
777
|
|
|
// 配送料無料条件(合計金額) |
778
|
|
|
$this->setDeliveryFreeAmount($Order); |
779
|
|
|
|
780
|
|
|
// 配送料無料条件(合計数量) |
781
|
|
|
$this->setDeliveryFreeQuantity($Order); |
782
|
|
|
|
783
|
|
|
// 合計金額の計算 |
784
|
|
|
$this->calculatePrice($Order); |
785
|
|
|
|
786
|
|
|
return $Order; |
787
|
|
|
} |
788
|
|
|
|
789
|
|
|
/** |
790
|
|
|
* 配送料金の設定 |
791
|
|
|
* |
792
|
|
|
* @param Shipping $Shipping |
|
|
|
|
793
|
|
|
* @param Delivery|null $Delivery |
794
|
|
|
*/ |
795
|
|
|
public function setShippingDeliveryFee(Shipping $Shipping, Delivery $Delivery = null) |
796
|
|
|
{ |
797
|
|
|
// 配送料金の設定 |
798
|
|
|
if (is_null($Delivery)) { |
799
|
|
|
$Delivery = $Shipping->getDelivery(); |
800
|
|
|
} |
801
|
|
|
$deliveryFee = $this->deliveryFeeRepository->findOneBy(['Delivery' => $Delivery, 'Pref' => $Shipping->getPref()]); |
802
|
|
|
if ($deliveryFee) { |
803
|
|
|
$Shipping->setFeeId($deliveryFee->getId()); |
804
|
|
|
} |
805
|
|
|
$Shipping->setDelivery($Delivery); |
806
|
|
|
|
807
|
|
|
// 商品ごとの配送料合計 |
808
|
|
|
$productDeliveryFeeTotal = 0; |
809
|
|
|
if ($this->BaseInfo->isOptionProductDeliveryFee()) { |
810
|
|
|
$productDeliveryFeeTotal += $this->getProductDeliveryFee($Shipping); |
811
|
|
|
} |
812
|
|
|
|
813
|
|
|
$Shipping->setShippingDeliveryFee($deliveryFee->getFee() + $productDeliveryFeeTotal); |
814
|
|
|
$Shipping->setShippingDeliveryName($Delivery->getName()); |
815
|
|
|
} |
816
|
|
|
|
817
|
|
|
/** |
818
|
|
|
* 配送料無料条件(合計金額)の条件を満たしていれば配送料金を0に設定 |
819
|
|
|
* |
820
|
|
|
* @param Order $Order |
821
|
|
|
*/ |
822
|
2 |
View Code Duplication |
public function setDeliveryFreeAmount(Order $Order) |
|
|
|
|
823
|
|
|
{ |
824
|
|
|
// 配送料無料条件(合計金額) |
825
|
2 |
|
$deliveryFreeAmount = $this->BaseInfo->getDeliveryFreeAmount(); |
826
|
2 |
|
if (!is_null($deliveryFreeAmount)) { |
827
|
|
|
// 合計金額が設定金額以上であれば送料無料 |
828
|
|
|
if ($Order->getSubTotal() >= $deliveryFreeAmount) { |
829
|
|
|
$Order->setDeliveryFeeTotal(0); |
830
|
|
|
// お届け先情報の配送料も0にセット |
831
|
|
|
$shippings = $Order->getShippings(); |
832
|
|
|
foreach ($shippings as $Shipping) { |
833
|
|
|
$Shipping->setShippingDeliveryFee(0); |
834
|
|
|
} |
835
|
|
|
} |
836
|
|
|
} |
837
|
|
|
} |
838
|
|
|
|
839
|
|
|
/** |
840
|
|
|
* 配送料無料条件(合計数量)の条件を満たしていれば配送料金を0に設定 |
841
|
|
|
* |
842
|
|
|
* @param Order $Order |
843
|
|
|
*/ |
844
|
2 |
View Code Duplication |
public function setDeliveryFreeQuantity(Order $Order) |
|
|
|
|
845
|
|
|
{ |
846
|
|
|
// 配送料無料条件(合計数量) |
847
|
2 |
|
$deliveryFreeQuantity = $this->BaseInfo->getDeliveryFreeQuantity(); |
848
|
2 |
|
if (!is_null($deliveryFreeQuantity)) { |
849
|
|
|
// 合計数量が設定数量以上であれば送料無料 |
850
|
|
|
if ($this->orderService->getTotalQuantity($Order) >= $deliveryFreeQuantity) { |
|
|
|
|
851
|
|
|
$Order->setDeliveryFeeTotal(0); |
852
|
|
|
// お届け先情報の配送料も0にセット |
853
|
|
|
$shippings = $Order->getShippings(); |
854
|
|
|
foreach ($shippings as $Shipping) { |
855
|
|
|
$Shipping->setShippingDeliveryFee(0); |
856
|
|
|
} |
857
|
|
|
} |
858
|
|
|
} |
859
|
|
|
} |
860
|
|
|
|
861
|
|
|
/** |
|
|
|
|
862
|
|
|
* 受注情報、お届け先情報の更新 |
863
|
|
|
* |
864
|
|
|
* @param Order $Order 受注情報 |
|
|
|
|
865
|
|
|
* @param $data フォームデータ |
|
|
|
|
866
|
|
|
* |
867
|
|
|
* @deprecated since 3.0.5, to be removed in 3.1 |
868
|
|
|
*/ |
869
|
|
|
public function setOrderUpdate(Order $Order, $data) |
870
|
|
|
{ |
871
|
|
|
// 受注情報を更新 |
872
|
|
|
$Order->setOrderDate(new \DateTime()); |
873
|
|
|
$Order->setOrderStatus($this->orderStatusRepository->find(OrderStatus::NEW)); |
874
|
|
|
$Order->setMessage($data['message']); |
875
|
|
|
// お届け先情報を更新 |
876
|
|
|
$shippings = $data['shippings']; |
877
|
|
|
foreach ($shippings as $Shipping) { |
878
|
|
|
$Delivery = $Shipping->getDelivery(); |
879
|
|
|
$deliveryFee = $this->deliveryFeeRepository->findOneBy([ |
880
|
|
|
'Delivery' => $Delivery, |
881
|
|
|
'Pref' => $Shipping->getPref(), |
882
|
|
|
]); |
883
|
|
|
$deliveryTime = $Shipping->getDeliveryTime(); |
884
|
|
|
if (!empty($deliveryTime)) { |
885
|
|
|
$Shipping->setShippingDeliveryTime($deliveryTime->getDeliveryTime()); |
886
|
|
|
$Shipping->setTimeId($deliveryTime->getId()); |
887
|
|
|
} |
888
|
|
|
$Shipping->setDeliveryFee($deliveryFee); |
889
|
|
|
// 商品ごとの配送料合計 |
890
|
|
|
$productDeliveryFeeTotal = 0; |
891
|
|
|
if ($this->BaseInfo->isOptionProductDeliveryFee()) { |
892
|
|
|
$productDeliveryFeeTotal += $this->getProductDeliveryFee($Shipping); |
893
|
|
|
} |
894
|
|
|
$Shipping->setShippingDeliveryFee($deliveryFee->getFee() + $productDeliveryFeeTotal); |
895
|
|
|
$Shipping->setShippingDeliveryName($Delivery->getName()); |
896
|
|
|
} |
897
|
|
|
// 配送料無料条件(合計金額) |
898
|
|
|
$this->setDeliveryFreeAmount($Order); |
899
|
|
|
// 配送料無料条件(合計数量) |
900
|
|
|
$this->setDeliveryFreeQuantity($Order); |
901
|
|
|
} |
902
|
|
|
|
903
|
|
|
/** |
904
|
|
|
* 受注情報の更新 |
905
|
|
|
* |
906
|
|
|
* @param Order $Order 受注情報 |
907
|
|
|
*/ |
908
|
2 |
|
public function setOrderUpdateData(Order $Order) |
909
|
|
|
{ |
910
|
|
|
// 受注情報を更新 |
911
|
2 |
|
$Order->setOrderDate(new \DateTime()); // XXX 後続の setOrderStatus でも時刻を更新している |
912
|
2 |
|
$OrderStatus = $this->orderStatusRepository->find(OrderStatus::NEW); |
913
|
2 |
|
$this->setOrderStatus($Order, $OrderStatus); |
914
|
|
|
} |
915
|
|
|
|
916
|
|
|
/** |
917
|
|
|
* 会員情報の更新 |
918
|
|
|
* |
919
|
|
|
* @param Order $Order 受注情報 |
|
|
|
|
920
|
|
|
* @param Customer $user ログインユーザ |
|
|
|
|
921
|
|
|
*/ |
922
|
1 |
|
public function setCustomerUpdate(Order $Order, Customer $user) |
923
|
|
|
{ |
924
|
|
|
// 顧客情報を更新 |
925
|
1 |
|
$now = new \DateTime(); |
926
|
1 |
|
$firstBuyDate = $user->getFirstBuyDate(); |
927
|
1 |
|
if (empty($firstBuyDate)) { |
928
|
1 |
|
$user->setFirstBuyDate($now); |
929
|
|
|
} |
930
|
1 |
|
$user->setLastBuyDate($now); |
931
|
|
|
|
932
|
1 |
|
$user->setBuyTimes($user->getBuyTimes() + 1); |
933
|
1 |
|
$user->setBuyTotal($user->getBuyTotal() + $Order->getTotal()); |
934
|
|
|
} |
935
|
|
|
|
936
|
|
|
/** |
|
|
|
|
937
|
|
|
* 支払方法選択の表示設定 |
938
|
|
|
* |
939
|
|
|
* @param $payments 支払選択肢情報 |
|
|
|
|
940
|
|
|
* @param $subTotal 小計 |
|
|
|
|
941
|
|
|
* |
942
|
|
|
* @return array |
943
|
|
|
*/ |
944
|
|
|
public function getPayments($payments, $subTotal) |
945
|
|
|
{ |
946
|
|
|
$pays = []; |
947
|
|
|
foreach ($payments as $payment) { |
948
|
|
|
// 支払方法の制限値内であれば表示 |
949
|
|
|
if (!is_null($payment)) { |
950
|
|
|
$pay = $this->paymentRepository->find($payment['id']); |
951
|
|
|
if (intval($pay->getRuleMin()) <= $subTotal) { |
952
|
|
|
if (is_null($pay->getRuleMax()) || $pay->getRuleMax() >= $subTotal) { |
953
|
|
|
$pays[] = $pay; |
954
|
|
|
} |
955
|
|
|
} |
956
|
|
|
} |
957
|
|
|
} |
958
|
|
|
|
959
|
|
|
return $pays; |
960
|
|
|
} |
961
|
|
|
|
962
|
|
|
/** |
963
|
|
|
* お届け日を取得 |
964
|
|
|
* |
965
|
|
|
* @param Order $Order |
966
|
|
|
* |
967
|
|
|
* @return array |
968
|
|
|
*/ |
969
|
|
|
public function getFormDeliveryDurations(Order $Order) |
970
|
|
|
{ |
971
|
|
|
// お届け日の設定 |
972
|
|
|
$minDate = 0; |
973
|
|
|
$deliveryDurationFlag = false; |
974
|
|
|
|
975
|
|
|
// 配送時に最大となる商品日数を取得 |
976
|
|
View Code Duplication |
foreach ($Order->getOrderItems() as $item) { |
|
|
|
|
977
|
|
|
if (!$item->isProduct()) { |
978
|
|
|
continue; |
979
|
|
|
} |
980
|
|
|
$ProductClass = $item->getProductClass(); |
981
|
|
|
$deliveryDuration = $ProductClass->getDeliveryDuration(); |
982
|
|
|
if (!is_null($deliveryDuration)) { |
983
|
|
|
if ($deliveryDuration->getDuration() < 0) { |
984
|
|
|
// 配送日数がマイナスの場合はお取り寄せなのでスキップする |
985
|
|
|
$deliveryDurationFlag = false; |
986
|
|
|
break; |
987
|
|
|
} |
988
|
|
|
|
989
|
|
|
if ($minDate < $deliveryDuration->getDuration()) { |
990
|
|
|
$minDate = $deliveryDuration->getDuration(); |
991
|
|
|
} |
992
|
|
|
// 配送日数が設定されている |
993
|
|
|
$deliveryDurationFlag = true; |
994
|
|
|
} |
995
|
|
|
} |
996
|
|
|
|
997
|
|
|
// 配達最大日数期間を設定 |
998
|
|
|
$deliveryDurations = []; |
999
|
|
|
|
1000
|
|
|
// 配送日数が設定されている |
1001
|
|
View Code Duplication |
if ($deliveryDurationFlag) { |
|
|
|
|
1002
|
|
|
$period = new \DatePeriod( |
1003
|
|
|
new \DateTime($minDate.' day'), |
1004
|
|
|
new \DateInterval('P1D'), |
1005
|
|
|
new \DateTime($minDate + $this->eccubeConfig['eccube_deliv_date_end_max'].' day') |
1006
|
|
|
); |
1007
|
|
|
|
1008
|
|
|
foreach ($period as $day) { |
1009
|
|
|
$deliveryDurations[$day->format('Y/m/d')] = $day->format('Y/m/d'); |
1010
|
|
|
} |
1011
|
|
|
} |
1012
|
|
|
|
1013
|
|
|
return $deliveryDurations; |
1014
|
|
|
} |
1015
|
|
|
|
1016
|
|
|
/** |
|
|
|
|
1017
|
|
|
* 支払方法を取得 |
1018
|
|
|
* |
1019
|
|
|
* @param $deliveries |
|
|
|
|
1020
|
|
|
* @param Order $Order |
|
|
|
|
1021
|
|
|
* |
1022
|
|
|
* @return array |
1023
|
|
|
*/ |
1024
|
|
|
public function getFormPayments($deliveries, Order $Order) |
1025
|
|
|
{ |
1026
|
|
|
$saleTypes = $this->orderService->getSaleTypes($Order); |
|
|
|
|
1027
|
|
|
if ($this->BaseInfo->isOptionMultipleShipping() && count($saleTypes) > 1) { |
1028
|
|
|
// 複数配送時の支払方法 |
1029
|
|
|
|
1030
|
|
|
$payments = $this->paymentRepository->findAllowedPayments($deliveries); |
1031
|
|
|
} else { |
1032
|
|
|
// 配送業者をセット |
1033
|
|
|
$shippings = $Order->getShippings(); |
1034
|
|
|
$Shipping = $shippings[0]; |
1035
|
|
|
$payments = $this->paymentRepository->findPayments($Shipping->getDelivery(), true); |
1036
|
|
|
} |
1037
|
|
|
$payments = $this->getPayments($payments, $Order->getSubTotal()); |
1038
|
|
|
|
1039
|
|
|
return $payments; |
1040
|
|
|
} |
1041
|
|
|
|
1042
|
|
|
/** |
1043
|
|
|
* お届け先ごとにFormを作成 |
1044
|
|
|
* |
1045
|
|
|
* @param Order $Order |
1046
|
|
|
* |
1047
|
|
|
* @return \Symfony\Component\Form\Form |
1048
|
|
|
* |
1049
|
|
|
* @deprecated since 3.0, to be removed in 3.1 |
1050
|
|
|
*/ |
1051
|
|
View Code Duplication |
public function getShippingForm(Order $Order) |
|
|
|
|
1052
|
|
|
{ |
1053
|
|
|
$message = $Order->getMessage(); |
1054
|
|
|
|
1055
|
|
|
$deliveries = $this->getDeliveriesOrder($Order); |
1056
|
|
|
|
1057
|
|
|
// 配送業者の支払方法を取得 |
1058
|
|
|
$payments = $this->getFormPayments($deliveries, $Order); |
1059
|
|
|
|
1060
|
|
|
$builder = $this->formFactory->createBuilder('shopping', null, [ |
1061
|
|
|
'payments' => $payments, |
1062
|
|
|
'payment' => $Order->getPayment(), |
1063
|
|
|
'message' => $message, |
1064
|
|
|
]); |
1065
|
|
|
|
1066
|
|
|
$builder |
1067
|
|
|
->add('shippings', CollectionType::class, [ |
1068
|
|
|
'entry_type' => ShippingItemType::class, |
1069
|
|
|
'data' => $Order->getShippings(), |
1070
|
|
|
]); |
1071
|
|
|
|
1072
|
|
|
$form = $builder->getForm(); |
1073
|
|
|
|
1074
|
|
|
return $form; |
1075
|
|
|
} |
1076
|
|
|
|
1077
|
|
|
/** |
1078
|
|
|
* お届け先ごとにFormBuilderを作成 |
1079
|
|
|
* |
1080
|
|
|
* @param Order $Order |
1081
|
|
|
* |
1082
|
|
|
* @return \Symfony\Component\Form\FormBuilderInterface |
1083
|
|
|
* |
1084
|
|
|
* @deprecated 利用している箇所なし |
1085
|
|
|
*/ |
1086
|
|
View Code Duplication |
public function getShippingFormBuilder(Order $Order) |
|
|
|
|
1087
|
|
|
{ |
1088
|
|
|
$message = $Order->getMessage(); |
1089
|
|
|
|
1090
|
|
|
$deliveries = $this->getDeliveriesOrder($Order); |
1091
|
|
|
|
1092
|
|
|
// 配送業者の支払方法を取得 |
1093
|
|
|
$payments = $this->getFormPayments($deliveries, $Order); |
1094
|
|
|
|
1095
|
|
|
$builder = $this->formFactory->createBuilder('shopping', null, [ |
1096
|
|
|
'payments' => $payments, |
1097
|
|
|
'payment' => $Order->getPayment(), |
1098
|
|
|
'message' => $message, |
1099
|
|
|
]); |
1100
|
|
|
|
1101
|
|
|
$builder |
1102
|
|
|
->add('shippings', CollectionType::class, [ |
1103
|
|
|
'entry_type' => ShippingItemType::class, |
1104
|
|
|
'data' => $Order->getShippings(), |
1105
|
|
|
]); |
1106
|
|
|
|
1107
|
|
|
return $builder; |
1108
|
|
|
} |
1109
|
|
|
|
1110
|
|
|
/** |
1111
|
|
|
* フォームデータを更新 |
1112
|
|
|
* |
1113
|
|
|
* @param Order $Order |
1114
|
|
|
* @param array $data |
1115
|
|
|
* |
1116
|
|
|
* @deprecated |
1117
|
|
|
*/ |
1118
|
|
|
public function setFormData(Order $Order, array $data) |
1119
|
|
|
{ |
1120
|
|
|
// お問い合わせ |
1121
|
|
|
$Order->setMessage($data['message']); |
1122
|
|
|
|
1123
|
|
|
// お届け先情報を更新 |
1124
|
|
|
$shippings = $data['shippings']; |
1125
|
|
|
foreach ($shippings as $Shipping) { |
1126
|
|
|
$timeId = $Shipping->getTimeId(); |
1127
|
|
|
$deliveryTime = null; |
1128
|
|
|
if ($timeId) { |
1129
|
|
|
$deliveryTime = $this->deliveryTimeRepository->find($timeId); |
1130
|
|
|
} |
1131
|
|
|
if ($deliveryTime) { |
1132
|
|
|
$Shipping->setShippingDeliveryTime($deliveryTime->getDeliveryTime()); |
1133
|
|
|
$Shipping->setTimeId($timeId); |
1134
|
|
|
} |
1135
|
|
|
} |
1136
|
|
|
} |
1137
|
|
|
|
1138
|
|
|
/** |
1139
|
|
|
* 配送料の合計金額を計算 |
1140
|
|
|
* |
1141
|
|
|
* @param Order $Order |
1142
|
|
|
* |
1143
|
|
|
* @return Order |
1144
|
|
|
*/ |
1145
|
2 |
|
public function calculateDeliveryFee(Order $Order) |
1146
|
|
|
{ |
1147
|
|
|
// 配送業者を取得 |
1148
|
2 |
|
$shippings = $Order->getShippings(); |
|
|
|
|
1149
|
|
|
|
1150
|
|
|
// 配送料合計金額 |
1151
|
|
|
// TODO CalculateDeliveryFeeStrategy でセットする |
1152
|
|
|
// $Order->setDeliveryFeeTotal($this->getShippingDeliveryFeeTotal($shippings)); |
|
|
|
|
1153
|
|
|
|
1154
|
|
|
// 配送料無料条件(合計金額) |
1155
|
2 |
|
$this->setDeliveryFreeAmount($Order); |
1156
|
|
|
|
1157
|
|
|
// 配送料無料条件(合計数量) |
1158
|
2 |
|
$this->setDeliveryFreeQuantity($Order); |
1159
|
|
|
|
1160
|
2 |
|
return $Order; |
1161
|
|
|
} |
1162
|
|
|
|
1163
|
|
|
/** |
1164
|
|
|
* 購入処理を行う |
1165
|
|
|
* |
1166
|
|
|
* @param Order $Order |
1167
|
|
|
* |
1168
|
|
|
* @deprecated PurchaseFlow::purchase() を使用してください |
1169
|
|
|
*/ |
1170
|
2 |
|
public function processPurchase(Order $Order) |
1171
|
|
|
{ |
1172
|
|
|
// 受注情報、配送情報を更新 |
1173
|
2 |
|
$Order = $this->calculateDeliveryFee($Order); |
1174
|
2 |
|
$this->setOrderUpdateData($Order); |
1175
|
|
|
|
1176
|
2 |
|
if ($this->authorizationChecker->isGranted('ROLE_USER')) { |
1177
|
1 |
|
$this->setCustomerUpdate($Order, $Order->getCustomer()); |
1178
|
|
|
} |
1179
|
|
|
} |
1180
|
|
|
|
1181
|
|
|
/** |
|
|
|
|
1182
|
|
|
* 値引き可能かチェック |
1183
|
|
|
* |
1184
|
|
|
* @param Order $Order |
|
|
|
|
1185
|
|
|
* @param $discount |
|
|
|
|
1186
|
|
|
* |
1187
|
|
|
* @return bool |
1188
|
|
|
*/ |
1189
|
|
|
public function isDiscount(Order $Order, $discount) |
1190
|
|
|
{ |
1191
|
|
|
if ($Order->getTotal() < $discount) { |
1192
|
|
|
return false; |
1193
|
|
|
} |
1194
|
|
|
|
1195
|
|
|
return true; |
1196
|
|
|
} |
1197
|
|
|
|
1198
|
|
|
/** |
|
|
|
|
1199
|
|
|
* 値引き金額をセット |
1200
|
|
|
* |
1201
|
|
|
* @param Order $Order |
|
|
|
|
1202
|
|
|
* @param $discount |
|
|
|
|
1203
|
|
|
*/ |
1204
|
|
|
public function setDiscount(Order $Order, $discount) |
1205
|
|
|
{ |
1206
|
|
|
$Order->setDiscount($Order->getDiscount() + $discount); |
1207
|
|
|
} |
1208
|
|
|
|
1209
|
|
|
/** |
1210
|
|
|
* 合計金額を計算 |
1211
|
|
|
* |
1212
|
|
|
* @param Order $Order |
1213
|
|
|
* |
1214
|
|
|
* @return Order |
1215
|
|
|
*/ |
1216
|
|
|
public function calculatePrice(Order $Order) |
1217
|
|
|
{ |
1218
|
|
|
$total = $Order->getTotalPrice(); |
1219
|
|
|
|
1220
|
|
|
if ($total < 0) { |
1221
|
|
|
// 合計金額がマイナスの場合、0を設定し、discountは値引きされた額のみセット |
1222
|
|
|
$total = 0; |
1223
|
|
|
} |
1224
|
|
|
|
1225
|
|
|
$Order->setTotal($total); |
1226
|
|
|
$Order->setPaymentTotal($total); |
1227
|
|
|
|
1228
|
|
|
return $Order; |
1229
|
|
|
} |
1230
|
|
|
|
1231
|
|
|
/** |
|
|
|
|
1232
|
|
|
* 受注ステータスをセット |
1233
|
|
|
* |
1234
|
|
|
* @param Order $Order |
|
|
|
|
1235
|
|
|
* @param $status |
|
|
|
|
1236
|
|
|
* |
1237
|
|
|
* @return Order |
1238
|
|
|
*/ |
1239
|
2 |
|
public function setOrderStatus(Order $Order, $status) |
1240
|
|
|
{ |
1241
|
2 |
|
$Order->setOrderDate(new \DateTime()); |
1242
|
2 |
|
$Order->setOrderStatus($this->orderStatusRepository->find($status)); |
1243
|
|
|
|
1244
|
2 |
|
$event = new EventArgs( |
1245
|
|
|
[ |
1246
|
2 |
|
'Order' => $Order, |
1247
|
|
|
], |
1248
|
2 |
|
null |
1249
|
|
|
); |
1250
|
2 |
|
$this->eventDispatcher->dispatch(EccubeEvents::SERVICE_SHOPPING_ORDER_STATUS, $event); |
1251
|
|
|
|
1252
|
2 |
|
return $Order; |
1253
|
|
|
} |
1254
|
|
|
|
1255
|
|
|
/** |
1256
|
|
|
* 受注メール送信を行う |
1257
|
|
|
* |
1258
|
|
|
* @param Order $Order |
1259
|
|
|
* |
1260
|
|
|
* @return MailHistory |
1261
|
|
|
*/ |
1262
|
2 |
|
public function sendOrderMail(Order $Order) |
1263
|
|
|
{ |
1264
|
|
|
// メール送信 |
1265
|
2 |
|
$message = $this->mailService->sendOrderMail($Order); |
1266
|
|
|
|
1267
|
|
|
// 送信履歴を保存. |
1268
|
2 |
|
$MailHistory = new MailHistory(); |
1269
|
|
|
$MailHistory |
1270
|
2 |
|
->setMailSubject($message->getSubject()) |
1271
|
2 |
|
->setMailBody($message->getBody()) |
1272
|
2 |
|
->setSendDate(new \DateTime()) |
1273
|
2 |
|
->setOrder($Order); |
1274
|
|
|
|
1275
|
2 |
|
$this->entityManager->persist($MailHistory); |
1276
|
2 |
|
$this->entityManager->flush($MailHistory); |
1277
|
|
|
|
1278
|
2 |
|
return $MailHistory; |
1279
|
|
|
} |
1280
|
|
|
|
1281
|
|
|
/** |
1282
|
|
|
* 受注処理完了通知 |
1283
|
|
|
* |
1284
|
|
|
* @param Order $Order |
1285
|
|
|
*/ |
1286
|
|
|
public function notifyComplete(Order $Order) |
1287
|
|
|
{ |
1288
|
|
|
$event = new EventArgs( |
1289
|
|
|
[ |
1290
|
|
|
'Order' => $Order, |
1291
|
|
|
], |
1292
|
|
|
null |
1293
|
|
|
); |
1294
|
|
|
$this->eventDispatcher->dispatch(EccubeEvents::SERVICE_SHOPPING_NOTIFY_COMPLETE, $event); |
1295
|
|
|
} |
1296
|
|
|
} |
1297
|
|
|
|