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