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