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