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