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