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