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