Failed Conditions
Pull Request — experimental/3.1 (#2529)
by Kentaro
34:12
created

ShoppingService::processPurchase()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 2
nop 1
dl 0
loc 14
ccs 6
cts 6
cp 1
crap 2
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/*
3
 * This file is part of EC-CUBE
4
 *
5
 * Copyright(c) 2000-2015 LOCKON CO.,LTD. All Rights Reserved.
6
 *
7
 * http://www.lockon.co.jp/
8
 *
9
 * This program is free software; you can redistribute it and/or
10
 * modify it under the terms of the GNU General Public License
11
 * as published by the Free Software Foundation; either version 2
12
 * of the License, or (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU General Public License
20
 * along with this program; if not, write to the Free Software
21
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
 */
23
24
namespace Eccube\Service;
25
26
use Doctrine\DBAL\LockMode;
27
use Doctrine\ORM\EntityManager;
28
use Eccube\Annotation\Inject;
29
use Eccube\Annotation\Service;
30
use Eccube\Application;
31
use Eccube\Common\Constant;
32
use Eccube\Entity\BaseInfo;
33
use Eccube\Entity\Customer;
34
use Eccube\Entity\Delivery;
35
use Eccube\Entity\MailHistory;
36
use Eccube\Entity\Order;
37
use Eccube\Entity\Product;
38
use Eccube\Entity\ProductClass;
39
use Eccube\Entity\OrderItem;
40
use Eccube\Entity\Shipping;
41
use Eccube\Event\EccubeEvents;
42
use Eccube\Event\EventArgs;
43
use Eccube\Exception\CartException;
44
use Eccube\Exception\ShoppingException;
45
use Eccube\Form\Type\ShippingItemType;
46
use Eccube\Repository\CustomerAddressRepository;
47
use Eccube\Repository\DeliveryFeeRepository;
48
use Eccube\Repository\DeliveryRepository;
49
use Eccube\Repository\MailTemplateRepository;
50
use Eccube\Repository\Master\DeviceTypeRepository;
51
use Eccube\Repository\Master\OrderStatusRepository;
52
use Eccube\Repository\Master\PrefRepository;
53
use Eccube\Repository\OrderRepository;
54
use Eccube\Repository\PaymentRepository;
55
use Eccube\Repository\TaxRuleRepository;
56
use Eccube\Util\Str;
57
use Symfony\Component\EventDispatcher\EventDispatcher;
58
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
59
use Symfony\Component\Form\FormFactory;
60
use Symfony\Component\HttpFoundation\Session\Session;
61
62
/**
63
 * @Service
64
 */
65
class ShoppingService
66
{
67
    /**
68
     * @Inject(MailTemplateRepository::class)
69
     * @var MailTemplateRepository
70
     */
71
    protected $mailTemplateRepository;
72
73
    /**
74
     * @Inject(MailService::class)
75
     * @var MailService
76
     */
77
    protected $mailService;
78
79
    /**
80
     * @Inject("eccube.event.dispatcher")
81
     * @var EventDispatcher
82
     */
83
    protected $eventDispatcher;
84
85
    /**
86
     * @Inject("form.factory")
87
     * @var FormFactory
88
     */
89
    protected $formFactory;
90
91
    /**
92
     * @Inject(DeliveryFeeRepository::class)
93
     * @var DeliveryFeeRepository
94
     */
95
    protected $deliveryFeeRepository;
96
97
    /**
98
     * @Inject(TaxRuleRepository::class)
99
     * @var TaxRuleRepository
100
     */
101
    protected $taxRuleRepository;
102
103
    /**
104
     * @Inject(CustomerAddressRepository::class)
105
     * @var CustomerAddressRepository
106
     */
107
    protected $customerAddressRepository;
108
109
    /**
110
     * @Inject(DeliveryRepository::class)
111
     * @var DeliveryRepository
112
     */
113
    protected $deliveryRepository;
114
115
    /**
116
     * @Inject(OrderStatusRepository::class)
117
     * @var OrderStatusRepository
118
     */
119
    protected $orderStatusRepository;
120
121
    /**
122
     * @Inject(PaymentRepository::class)
123
     * @var PaymentRepository
124
     */
125
    protected $paymentRepository;
126
127
    /**
128
     * @Inject(DeviceTypeRepository::class)
129
     * @var DeviceTypeRepository
130
     */
131
    protected $deviceTypeRepository;
132
133
    /**
134
     * @Inject("orm.em")
135
     * @var EntityManager
136
     */
137
    protected $entityManager;
138
139
    /**
140
     * @Inject("config")
141
     * @var array
142
     */
143
    protected $appConfig;
144
145
    /**
146
     * @Inject(PrefRepository::class)
147
     * @var PrefRepository
148
     */
149
    protected $prefRepository;
150
151
    /**
152
     * @Inject("session")
153
     * @var Session
154
     */
155
    protected $session;
156
157
    /**
158
     * @Inject(OrderRepository::class)
159
     * @var OrderRepository
160
     */
161
    protected $orderRepository;
162
163
    /**
164
     * @Inject(BaseInfo::class)
165
     * @var BaseInfo
166
     */
167
    protected $BaseInfo;
168
169
    /**
170
     * @Inject(Application::class)
171
     * @var \Eccube\Application
172
     */
173
    public $app;
174
175
    /**
176
     * @Inject(CartService::class)
177
     * @var \Eccube\Service\CartService
178
     */
179
    protected $cartService;
180
181
    /**
182
     * @var \Eccube\Service\OrderService
183
     *
184
     * @deprecated
185
     */
186
    protected $orderService;
187
188
    /**
189
     * セッションにセットされた受注情報を取得
190
     *
191
     * @param null $status
192
     * @return null|object
193
     */
194 11
    public function getOrder($status = null)
195
    {
196
197
        // 受注データを取得
198 11
        $preOrderId = $this->cartService->getPreOrderId();
199 11
        if (!$preOrderId) {
200 11
            return null;
201
        }
202
203
        $condition = array(
204 7
            'pre_order_id' => $preOrderId,
205
        );
206
207 7
        if (!is_null($status)) {
208
            $condition += array(
209 7
                'OrderStatus' => $status,
210
            );
211
        }
212
213 7
        $Order = $this->orderRepository->findOneBy($condition);
214
215 7
        return $Order;
216
217
    }
218
219
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$sesisonKey" missing
Loading history...
220
     * 非会員情報を取得
221
     *
222
     * @param $sesisonKey
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
223
     * @return $Customer|null
0 ignored issues
show
Documentation introduced by
The doc-type $Customer|null could not be parsed: Unknown type name "$Customer" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
224
     */
225 4
    public function getNonMember($sesisonKey)
226
    {
227
228
        // 非会員でも一度会員登録されていればショッピング画面へ遷移
229 4
        $nonMember = $this->session->get($sesisonKey);
230 4
        if (is_null($nonMember)) {
231 1
            return null;
232
        }
233 3
        if (!array_key_exists('customer', $nonMember) || !array_key_exists('pref', $nonMember)) {
234
            return null;
235
        }
236
237 3
        $Customer = $nonMember['customer'];
238 3
        $Customer->setPref($this->prefRepository->find($nonMember['pref']));
239
240 3
        foreach ($Customer->getCustomerAddresses() as $CustomerAddress) {
241 3
            $Pref = $CustomerAddress->getPref();
242 3
            if ($Pref) {
243 3
                $CustomerAddress->setPref($this->prefRepository->find($Pref->getId()));
244
            }
245
        }
246
247 3
        return $Customer;
248
249
    }
250
251
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$Customer" missing
Loading history...
252
     * 受注情報を作成
253
     *
254
     * @param $Customer
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
255
     * @return \Eccube\Entity\Order
256
     */
257
    public function createOrder($Customer)
258
    {
259
        // ランダムなpre_order_idを作成
260 View Code Duplication
        do {
261
            $preOrderId = sha1(Str::random(32));
262
            $Order = $this->orderRepository->findOneBy(array(
263
                'pre_order_id' => $preOrderId,
264
                'OrderStatus' => $this->appConfig['order_processing'],
265
            ));
266
        } while ($Order);
267
268
        // 受注情報、受注明細情報、お届け先情報、配送商品情報を作成
269
        $Order = $this->registerPreOrder(
270
            $Customer,
271
            $preOrderId);
272
273
        $this->cartService->setPreOrderId($preOrderId);
274
        $this->cartService->save();
275
276
        return $Order;
277
    }
278
279
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$Customer" missing
Loading history...
introduced by
Doc comment for parameter "$preOrderId" missing
Loading history...
280
     * 仮受注情報作成
281
     *
282
     * @param $Customer
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
283
     * @param $preOrderId
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
284
     * @return mixed
285
     * @throws \Doctrine\ORM\NoResultException
286
     * @throws \Doctrine\ORM\NonUniqueResultException
287
     */
288
    public function registerPreOrder(Customer $Customer, $preOrderId)
289
    {
290
291
        $this->em = $this->entityManager;
292
293
        // 受注情報を作成
294
        $Order = $this->getNewOrder($Customer);
295
        $Order->setPreOrderId($preOrderId);
296
297
        $DeviceType = $this->deviceTypeRepository->find($this->app['mobile_detect.device_type']);
298
        $Order->setDeviceType($DeviceType);
299
300
        $this->entityManager->persist($Order);
301
302
        // 配送業者情報を取得
303
        $deliveries = $this->getDeliveriesCart();
304
305
        // お届け先情報を作成
306
        $Order = $this->getNewShipping($Order, $Customer, $deliveries);
307
308
        // 受注明細情報、配送商品情報を作成
309
        $Order = $this->getNewDetails($Order);
310
311
        // 小計
312
        $subTotal = $this->orderService->getSubTotal($Order);
0 ignored issues
show
Bug introduced by
The method getSubTotal() does not seem to exist on object<Eccube\Service\OrderService>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Deprecated Code introduced by
The property Eccube\Service\ShoppingService::$orderService has been deprecated.

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
313
314
        // 消費税のみの小計
315
        $tax = $this->orderService->getTotalTax($Order);
0 ignored issues
show
Bug introduced by
The method getTotalTax() does not seem to exist on object<Eccube\Service\OrderService>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Deprecated Code introduced by
The property Eccube\Service\ShoppingService::$orderService has been deprecated.

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
316
317
        // 配送料合計金額
318
        // TODO CalculateDeliveryFeeStrategy でセットする
319
        // $Order->setDeliveryFeeTotal($this->getShippingDeliveryFeeTotal($Order->getShippings()));
320
321
        // 小計
322
        $Order->setSubTotal($subTotal);
323
324
        // 配送料無料条件(合計金額)
325
        $this->setDeliveryFreeAmount($Order);
326
327
        // 配送料無料条件(合計数量)
328
        $this->setDeliveryFreeQuantity($Order);
329
330
        // 初期選択の支払い方法をセット
331
        $payments = $this->paymentRepository->findAllowedPayments($deliveries);
332
        $payments = $this->getPayments($payments, $subTotal);
333
334
        if (count($payments) > 0) {
335
            $payment = $payments[0];
336
            $Order->setPayment($payment);
337
            $Order->setPaymentMethod($payment->getMethod());
338
            $Order->setCharge($payment->getCharge());
339
        } else {
340
            $Order->setCharge(0);
341
        }
342
343
        $Order->setTax($tax);
344
345
        // 合計金額の計算
346
        $this->calculatePrice($Order);
347
348
        $this->entityManager->flush();
349
350
        return $Order;
351
352
    }
353
354
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$Customer" missing
Loading history...
355
     * 受注情報を作成
356
     *
357
     * @param $Customer
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
358
     * @return \Eccube\Entity\Order
359
     */
360
    public function getNewOrder(Customer $Customer)
361
    {
362
        $Order = $this->newOrder();
363
        $this->copyToOrderFromCustomer($Order, $Customer);
364
365
        return $Order;
366
    }
367
368
369
    /**
370
     * 受注情報を作成
371
     *
372
     * @return \Eccube\Entity\Order
373
     */
374
    public function newOrder()
375
    {
376
        $OrderStatus = $this->orderStatusRepository->find($this->appConfig['order_processing']);
377
        $Order = new \Eccube\Entity\Order($OrderStatus);
378
379
        return $Order;
380
    }
381
382
    /**
383
     * 受注情報を作成
384
     *
385
     * @param \Eccube\Entity\Order $Order
0 ignored issues
show
introduced by
Expected 9 spaces after parameter type; 1 found
Loading history...
386
     * @param \Eccube\Entity\Customer|null $Customer
387
     * @return \Eccube\Entity\Order
388
     */
389
    public function copyToOrderFromCustomer(Order $Order, Customer $Customer = null)
390
    {
391
        if (is_null($Customer)) {
392
            return $Order;
393
        }
394
395
        if ($Customer->getId()) {
396
            $Order->setCustomer($Customer);
397
        }
398
        $Order
399
            ->setName01($Customer->getName01())
400
            ->setName02($Customer->getName02())
401
            ->setKana01($Customer->getKana01())
402
            ->setKana02($Customer->getKana02())
403
            ->setCompanyName($Customer->getCompanyName())
404
            ->setEmail($Customer->getEmail())
405
            ->setTel01($Customer->getTel01())
406
            ->setTel02($Customer->getTel02())
407
            ->setTel03($Customer->getTel03())
408
            ->setFax01($Customer->getFax01())
409
            ->setFax02($Customer->getFax02())
410
            ->setFax03($Customer->getFax03())
411
            ->setZip01($Customer->getZip01())
412
            ->setZip02($Customer->getZip02())
413
            ->setZipCode($Customer->getZip01().$Customer->getZip02())
414
            ->setPref($Customer->getPref())
415
            ->setAddr01($Customer->getAddr01())
416
            ->setAddr02($Customer->getAddr02())
417
            ->setSex($Customer->getSex())
418
            ->setBirth($Customer->getBirth())
419
            ->setJob($Customer->getJob());
420
421
        return $Order;
422
    }
423
424
425
    /**
426
     * 配送業者情報を取得
427
     *
428
     * @return array
429
     */
430
    public function getDeliveriesCart()
431
    {
432
433
        // カートに保持されている商品種別を取得
434
        $productTypes = $this->cartService->getProductTypes();
0 ignored issues
show
Bug introduced by
The method getProductTypes() does not seem to exist on object<Eccube\Service\CartService>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
435
436
        return $this->getDeliveries($productTypes);
437
438
    }
439
440
    /**
441
     * 配送業者情報を取得
442
     *
443
     * @param Order $Order
444
     * @return array
445
     */
446
    public function getDeliveriesOrder(Order $Order)
447
    {
448
449
        // 受注情報から商品種別を取得
450
        $productTypes = $this->orderService->getProductTypes($Order);
0 ignored issues
show
Deprecated Code introduced by
The property Eccube\Service\ShoppingService::$orderService has been deprecated.

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
Deprecated Code introduced by
The method Eccube\Service\OrderService::getProductTypes() has been deprecated with message: since 3.0.0, to be removed in 3.1

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
451
452
        return $this->getDeliveries($productTypes);
453
454
    }
455
456
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$productTypes" missing
Loading history...
457
     * 配送業者情報を取得
458
     *
459
     * @param $productTypes
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
460
     * @return array
461
     */
462 3
    public function getDeliveries($productTypes)
463
    {
464
465
        // 商品種別に紐づく配送業者を取得
466 3
        $deliveries = $this->deliveryRepository->getDeliveries($productTypes);
467
468 3
        if ($this->BaseInfo->getOptionMultipleShipping() == Constant::ENABLED) {
469
            // 複数配送対応
470
471
            // 支払方法を取得
472 1
            $payments = $this->paymentRepository->findAllowedPayments($deliveries);
473
474 1
            if (count($productTypes) > 1) {
475
                // 商品種別が複数ある場合、配送対象となる配送業者を取得
476 1
                $deliveries = $this->deliveryRepository->findAllowedDeliveries($productTypes, $payments);
477
            }
478
0 ignored issues
show
Coding Style introduced by
Blank line found at end of control structure
Loading history...
479
        }
480
481 3
        return $deliveries;
482
483
    }
484
485
486
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$deliveries" missing
Loading history...
487
     * お届け先情報を作成
488
     *
489
     * @param Order $Order
0 ignored issues
show
introduced by
Expected 6 spaces after parameter type; 1 found
Loading history...
490
     * @param Customer $Customer
0 ignored issues
show
introduced by
Expected 3 spaces after parameter type; 1 found
Loading history...
491
     * @param $deliveries
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
492
     * @return Order
493
     */
494
    public function getNewShipping(Order $Order, Customer $Customer, $deliveries)
495
    {
496
        $productTypes = array();
497
        foreach ($deliveries as $Delivery) {
498
            if (!in_array($Delivery->getProductType()->getId(), $productTypes)) {
499
                $Shipping = new Shipping();
500
501
                $this->copyToShippingFromCustomer($Shipping, $Customer)
502
                    ->setOrder($Order)
503
                    ->setDelFlg(Constant::DISABLED);
504
505
                // 配送料金の設定
506
                $this->setShippingDeliveryFee($Shipping, $Delivery);
507
508
                $this->entityManager->persist($Shipping);
509
510
                $Order->addShipping($Shipping);
511
512
                $productTypes[] = $Delivery->getProductType()->getId();
513
            }
514
        }
515
516
        return $Order;
517
    }
518
519
    /**
520
     * お届け先情報を作成
521
     *
522
     * @param \Eccube\Entity\Shipping $Shipping
0 ignored issues
show
introduced by
Expected 6 spaces after parameter type; 1 found
Loading history...
523
     * @param \Eccube\Entity\Customer|null $Customer
524
     * @return \Eccube\Entity\Shipping
525
     */
526 1
    public function copyToShippingFromCustomer(Shipping $Shipping, Customer $Customer = null)
527
    {
528 1
        if (is_null($Customer)) {
529 1
            return $Shipping;
530
        }
531
532
        $CustomerAddress = $this->customerAddressRepository->findOneBy(
533
            array('Customer' => $Customer),
534
            array('id' => 'ASC')
535
        );
536
537
        if (!is_null($CustomerAddress)) {
538
            $Shipping
539
                ->setName01($CustomerAddress->getName01())
540
                ->setName02($CustomerAddress->getName02())
541
                ->setKana01($CustomerAddress->getKana01())
542
                ->setKana02($CustomerAddress->getKana02())
543
                ->setCompanyName($CustomerAddress->getCompanyName())
544
                ->setTel01($CustomerAddress->getTel01())
545
                ->setTel02($CustomerAddress->getTel02())
546
                ->setTel03($CustomerAddress->getTel03())
547
                ->setFax01($CustomerAddress->getFax01())
548
                ->setFax02($CustomerAddress->getFax02())
549
                ->setFax03($CustomerAddress->getFax03())
550
                ->setZip01($CustomerAddress->getZip01())
551
                ->setZip02($CustomerAddress->getZip02())
552
                ->setZipCode($CustomerAddress->getZip01().$CustomerAddress->getZip02())
553
                ->setPref($CustomerAddress->getPref())
554
                ->setAddr01($CustomerAddress->getAddr01())
555
                ->setAddr02($CustomerAddress->getAddr02());
556
        } else {
557
            $Shipping
558
                ->setName01($Customer->getName01())
559
                ->setName02($Customer->getName02())
560
                ->setKana01($Customer->getKana01())
561
                ->setKana02($Customer->getKana02())
562
                ->setCompanyName($Customer->getCompanyName())
563
                ->setTel01($Customer->getTel01())
564
                ->setTel02($Customer->getTel02())
565
                ->setTel03($Customer->getTel03())
566
                ->setFax01($Customer->getFax01())
567
                ->setFax02($Customer->getFax02())
568
                ->setFax03($Customer->getFax03())
569
                ->setZip01($Customer->getZip01())
570
                ->setZip02($Customer->getZip02())
571
                ->setZipCode($Customer->getZip01().$Customer->getZip02())
572
                ->setPref($Customer->getPref())
573
                ->setAddr01($Customer->getAddr01())
574
                ->setAddr02($Customer->getAddr02());
575
        }
576
577
        return $Shipping;
578
    }
579
580
581
    /**
582
     * 受注明細情報、配送商品情報を作成
583
     *
584
     * @param Order $Order
585
     * @return Order
586
     */
587
    public function getNewDetails(Order $Order)
588
    {
589
590
        // 受注詳細, 配送商品
591
        foreach ($this->cartService->getCart()->getCartItems() as $item) {
592
            /* @var $ProductClass \Eccube\Entity\ProductClass */
593
            $ProductClass = $item->getObject();
594
            /* @var $Product \Eccube\Entity\Product */
595
            $Product = $ProductClass->getProduct();
596
597
            $quantity = $item->getQuantity();
598
599
            // 配送商品情報を作成
600
            $this->getNewOrderItem($Order, $Product, $ProductClass, $quantity);
601
        }
602
603
        return $Order;
604
605
    }
606
607
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$quantity" missing
Loading history...
608
     * 配送商品情報を作成
609
     *
610
     * @param Order $Order
0 ignored issues
show
introduced by
Expected 8 spaces after parameter type; 1 found
Loading history...
611
     * @param Product $Product
0 ignored issues
show
introduced by
Expected 6 spaces after parameter type; 1 found
Loading history...
612
     * @param ProductClass $ProductClass
613
     * @param $quantity
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
614
     * @return \Eccube\Entity\OrderItem
615
     */
616
    public function getNewOrderItem(Order $Order, Product $Product, ProductClass $ProductClass, $quantity)
617
    {
618
619
        $OrderItem = new OrderItem();
620
        $shippings = $Order->getShippings();
621
622
        // 選択された商品がどのお届け先情報と関連するかチェック
623
        $Shipping = null;
624
        foreach ($shippings as $s) {
625
            if ($s->getDelivery()->getProductType()->getId() == $ProductClass->getProductType()->getId()) {
626
                // 商品種別が同一のお届け先情報と関連させる
627
                $Shipping = $s;
628
                break;
629
            }
630
        }
631
632
        if (is_null($Shipping)) {
633
            // お届け先情報と関連していない場合、エラー
634
            throw new CartException('shopping.delivery.not.producttype');
635
        }
636
637
        // 商品ごとの配送料合計
638
        $productDeliveryFeeTotal = 0;
639
        if (!is_null($this->BaseInfo->getOptionProductDeliveryFee())) {
640
            $productDeliveryFeeTotal = $ProductClass->getDeliveryFee() * $quantity;
641
        }
642
643
        $Shipping->setShippingDeliveryFee($Shipping->getShippingDeliveryFee() + $productDeliveryFeeTotal);
644
645
        $OrderItem->setShipping($Shipping)
646
            ->setOrder($Order)
647
            ->setProductClass($ProductClass)
648
            ->setProduct($Product)
649
            ->setProductName($Product->getName())
650
            ->setProductCode($ProductClass->getCode())
651
            ->setPrice($ProductClass->getPrice02())
652
            ->setQuantity($quantity);
653
654
        $ClassCategory1 = $ProductClass->getClassCategory1();
655
        if (!is_null($ClassCategory1)) {
656
            $OrderItem->setClasscategoryName1($ClassCategory1->getName());
657
            $OrderItem->setClassName1($ClassCategory1->getClassName()->getName());
658
        }
659
        $ClassCategory2 = $ProductClass->getClassCategory2();
660
        if (!is_null($ClassCategory2)) {
661
            $OrderItem->setClasscategoryName2($ClassCategory2->getName());
662
            $OrderItem->setClassName2($ClassCategory2->getClassName()->getName());
663
        }
664
        $Shipping->addOrderItem($OrderItem);
665
        $this->entityManager->persist($OrderItem);
666
667
        return $OrderItem;
668
669
    }
670
671
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$shippings" missing
Loading history...
672
     * お届け先ごとの送料合計を取得
673
     *
674
     * @param $shippings
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
675
     * @return int
676
     */
677
    public function getShippingDeliveryFeeTotal($shippings)
678
    {
679
        $deliveryFeeTotal = 0;
680
        foreach ($shippings as $Shipping) {
681
            $deliveryFeeTotal += $Shipping->getShippingDeliveryFee();
682
        }
683
684
        return $deliveryFeeTotal;
685
686
    }
687
688
    /**
689
     * 商品ごとの配送料を取得
690
     *
691
     * @param Shipping $Shipping
692
     * @return int
693
     */
694
    public function getProductDeliveryFee(Shipping $Shipping)
695
    {
696
        $productDeliveryFeeTotal = 0;
697
        $OrderItems = $Shipping->getOrderItems();
698
        foreach ($OrderItems as $OrderItem) {
699
            $productDeliveryFeeTotal += $OrderItem->getProductClass()->getDeliveryFee() * $OrderItem->getQuantity();
700
        }
701
702
        return $productDeliveryFeeTotal;
703
    }
704
705
    /**
706
     * 住所などの情報が変更された時に金額の再計算を行う
707
     * @deprecated PurchaseFlowで行う
708
     * @param Order $Order
709
     * @return Order
710
     */
711 1
    public function getAmount(Order $Order)
712
    {
713
714
        // 初期選択の配送業者をセット
715 1
        $shippings = $Order->getShippings();
0 ignored issues
show
Unused Code introduced by
$shippings is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
716
717
        // 配送料合計金額
718
        // TODO CalculateDeliveryFeeStrategy でセットする
719
        // $Order->setDeliveryFeeTotal($this->getShippingDeliveryFeeTotal($shippings));
720
721
        // 配送料無料条件(合計金額)
722 1
        $this->setDeliveryFreeAmount($Order);
723
724
        // 配送料無料条件(合計数量)
725 1
        $this->setDeliveryFreeQuantity($Order);
726
727
        // 合計金額の計算
728 1
        $this->calculatePrice($Order);
729
730 1
        return $Order;
731
732
    }
733
734
    /**
735
     * 配送料金の設定
736
     *
737
     * @param Shipping $Shipping
0 ignored issues
show
introduced by
Expected 6 spaces after parameter type; 1 found
Loading history...
738
     * @param Delivery|null $Delivery
739
     */
740
    public function setShippingDeliveryFee(Shipping $Shipping, Delivery $Delivery = null)
741
    {
742
        // 配送料金の設定
743
        if (is_null($Delivery)) {
744
            $Delivery = $Shipping->getDelivery();
745
        }
746
        $deliveryFee = $this->deliveryFeeRepository->findOneBy(array('Delivery' => $Delivery, 'Pref' => $Shipping->getPref()));
747
        if ($deliveryFee) {
748
            $Shipping->setDeliveryFee($deliveryFee);
749
            $Shipping->setFeeId($deliveryFee->getId());
750
        }
751
        $Shipping->setDelivery($Delivery);
752
753
        // 商品ごとの配送料合計
754
        $productDeliveryFeeTotal = 0;
755
        if (!is_null($this->BaseInfo->getOptionProductDeliveryFee())) {
756
            $productDeliveryFeeTotal += $this->getProductDeliveryFee($Shipping);
757
        }
758
759
        $Shipping->setShippingDeliveryFee($deliveryFee->getFee() + $productDeliveryFeeTotal);
760
        $Shipping->setShippingDeliveryName($Delivery->getName());
761
    }
762
763
    /**
764
     * 配送料無料条件(合計金額)の条件を満たしていれば配送料金を0に設定
765
     *
766
     * @param Order $Order
767
     */
768 4 View Code Duplication
    public function setDeliveryFreeAmount(Order $Order)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
769
    {
770
        // 配送料無料条件(合計金額)
771 4
        $deliveryFreeAmount = $this->BaseInfo->getDeliveryFreeAmount();
772 4
        if (!is_null($deliveryFreeAmount)) {
773
            // 合計金額が設定金額以上であれば送料無料
774 1
            if ($Order->getSubTotal() >= $deliveryFreeAmount) {
775 1
                $Order->setDeliveryFeeTotal(0);
776
                // お届け先情報の配送料も0にセット
777 1
                $shippings = $Order->getShippings();
778 1
                foreach ($shippings as $Shipping) {
779 1
                    $Shipping->setShippingDeliveryFee(0);
780
                }
781
            }
782
        }
783
    }
784
785
    /**
786
     * 配送料無料条件(合計数量)の条件を満たしていれば配送料金を0に設定
787
     *
788
     * @param Order $Order
789
     */
790 3 View Code Duplication
    public function setDeliveryFreeQuantity(Order $Order)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
791
    {
792
        // 配送料無料条件(合計数量)
793 3
        $deliveryFreeQuantity = $this->BaseInfo->getDeliveryFreeQuantity();
794 3
        if (!is_null($deliveryFreeQuantity)) {
795
            // 合計数量が設定数量以上であれば送料無料
796
            if ($this->orderService->getTotalQuantity($Order) >= $deliveryFreeQuantity) {
0 ignored issues
show
Bug introduced by
The method getTotalQuantity() does not seem to exist on object<Eccube\Service\OrderService>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Deprecated Code introduced by
The property Eccube\Service\ShoppingService::$orderService has been deprecated.

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
797
                $Order->setDeliveryFeeTotal(0);
798
                // お届け先情報の配送料も0にセット
799
                $shippings = $Order->getShippings();
800
                foreach ($shippings as $Shipping) {
801
                    $Shipping->setShippingDeliveryFee(0);
802
                }
803
            }
804
        }
805
    }
806
807
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$data" missing
Loading history...
808
     * 受注情報、お届け先情報の更新
809
     *
810
     * @param Order $Order 受注情報
0 ignored issues
show
introduced by
Expected 22 spaces after parameter type; 1 found
Loading history...
811
     * @param $data フォームデータ
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
812
     *
813
     * @deprecated since 3.0.5, to be removed in 3.1
814
     */
815
    public function setOrderUpdate(Order $Order, $data)
816
    {
817
        // 受注情報を更新
818
        $Order->setOrderDate(new \DateTime());
819
        $Order->setOrderStatus($this->orderStatusRepository->find($this->appConfig['order_new']));
820
        $Order->setMessage($data['message']);
821
        // お届け先情報を更新
822
        $shippings = $data['shippings'];
823
        foreach ($shippings as $Shipping) {
824
            $Delivery = $Shipping->getDelivery();
825
            $deliveryFee = $this->deliveryFeeRepository->findOneBy(array(
0 ignored issues
show
introduced by
Add a comma after each item in a multi-line array
Loading history...
826
                'Delivery' => $Delivery,
827
                'Pref' => $Shipping->getPref()
828
            ));
829
            $deliveryTime = $Shipping->getDeliveryTime();
830
            if (!empty($deliveryTime)) {
831
                $Shipping->setShippingDeliveryTime($deliveryTime->getDeliveryTime());
832
                $Shipping->setTimeId($deliveryTime->getId());
833
            }
834
            $Shipping->setDeliveryFee($deliveryFee);
835
            // 商品ごとの配送料合計
836
            $productDeliveryFeeTotal = 0;
837
            if (!is_null($this->BaseInfo->getOptionProductDeliveryFee())) {
838
                $productDeliveryFeeTotal += $this->getProductDeliveryFee($Shipping);
839
            }
840
            $Shipping->setShippingDeliveryFee($deliveryFee->getFee() + $productDeliveryFeeTotal);
841
            $Shipping->setShippingDeliveryName($Delivery->getName());
842
        }
843
        // 配送料無料条件(合計金額)
844
        $this->setDeliveryFreeAmount($Order);
845
        // 配送料無料条件(合計数量)
846
        $this->setDeliveryFreeQuantity($Order);
847
    }
848
849
850
    /**
851
     * 受注情報の更新
852
     *
853
     * @param Order $Order 受注情報
854
     */
855 3
    public function setOrderUpdateData(Order $Order)
856
    {
857
        // 受注情報を更新
858 3
        $Order->setOrderDate(new \DateTime()); // XXX 後続の setOrderStatus でも時刻を更新している
859 3
        $OrderStatus = $this->orderStatusRepository->find($this->appConfig['order_new']);
860 3
        $this->setOrderStatus($Order, $OrderStatus);
861
862
    }
863
864
865
    /**
866
     * 会員情報の更新
867
     *
868
     * @param Order $Order 受注情報
0 ignored issues
show
introduced by
Expected 4 spaces after parameter type; 1 found
Loading history...
869
     * @param Customer $user ログインユーザ
0 ignored issues
show
introduced by
Expected 2 spaces after parameter name; 1 found
Loading history...
870
     */
871 2
    public function setCustomerUpdate(Order $Order, Customer $user)
872
    {
873
        // 顧客情報を更新
874 2
        $now = new \DateTime();
875 2
        $firstBuyDate = $user->getFirstBuyDate();
876 2
        if (empty($firstBuyDate)) {
877 2
            $user->setFirstBuyDate($now);
878
        }
879 2
        $user->setLastBuyDate($now);
880
881 2
        $user->setBuyTimes($user->getBuyTimes() + 1);
882 2
        $user->setBuyTotal($user->getBuyTotal() + $Order->getTotal());
883
    }
884
885
886
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$payments" missing
Loading history...
introduced by
Doc comment for parameter "$subTotal" missing
Loading history...
887
     * 支払方法選択の表示設定
888
     *
889
     * @param $payments 支払選択肢情報
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
890
     * @param $subTotal 小計
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
891
     * @return array
892
     */
893 1
    public function getPayments($payments, $subTotal)
894
    {
895 1
        $pays = array();
896 1
        foreach ($payments as $payment) {
897
            // 支払方法の制限値内であれば表示
898 1
            if (!is_null($payment)) {
899 1
                $pay = $this->paymentRepository->find($payment['id']);
900 1
                if (intval($pay->getRuleMin()) <= $subTotal) {
901 1
                    if (is_null($pay->getRuleMax()) || $pay->getRuleMax() >= $subTotal) {
902 1
                        $pays[] = $pay;
903
                    }
904
                }
905
            }
906
        }
907
908 1
        return $pays;
909
910
    }
911
912
    /**
913
     * お届け日を取得
914
     *
915
     * @param Order $Order
916
     * @return array
917
     */
918 2
    public function getFormDeliveryDates(Order $Order)
919
    {
920
921
        // お届け日の設定
922 2
        $minDate = 0;
923 2
        $deliveryDateFlag = false;
924
925
        // 配送時に最大となる商品日数を取得
926 2 View Code Duplication
        foreach ($Order->getOrderItems() as $item) {
927 2
            if (!$item->isProduct()) {
928 1
                continue;
929
            }
930 2
            $ProductClass = $item->getProductClass();
931 2
            $deliveryDate = $ProductClass->getDeliveryDate();
932 2
            if (!is_null($deliveryDate)) {
933 2
                if ($deliveryDate->getValue() < 0) {
934
                    // 配送日数がマイナスの場合はお取り寄せなのでスキップする
935 1
                    $deliveryDateFlag = false;
936 1
                    break;
937
                }
938
939 1
                if ($minDate < $deliveryDate->getValue()) {
940
                    $minDate = $deliveryDate->getValue();
941
                }
942
                // 配送日数が設定されている
943 1
                $deliveryDateFlag = true;
944
            }
945
        }
946
947
        // 配達最大日数期間を設定
948 2
        $deliveryDates = array();
949
950
        // 配送日数が設定されている
951 2 View Code Duplication
        if ($deliveryDateFlag) {
952 1
            $period = new \DatePeriod (
0 ignored issues
show
introduced by
Use parentheses when instantiating classes
Loading history...
Coding Style introduced by
Space before opening parenthesis of function call prohibited
Loading history...
953 1
                new \DateTime($minDate.' day'),
954 1
                new \DateInterval('P1D'),
955 1
                new \DateTime($minDate + $this->appConfig['deliv_date_end_max'].' day')
956
            );
957
958 1
            foreach ($period as $day) {
959 1
                $deliveryDates[$day->format('Y/m/d')] = $day->format('Y/m/d');
960
            }
961
        }
962
963 2
        return $deliveryDates;
964
    }
965
966
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$deliveries" missing
Loading history...
967
     * 支払方法を取得
968
     *
969
     * @param $deliveries
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
970
     * @param Order $Order
0 ignored issues
show
introduced by
Expected 6 spaces after parameter type; 1 found
Loading history...
971
     * @return array
972
     */
973
    public function getFormPayments($deliveries, Order $Order)
974
    {
975
976
        $productTypes = $this->orderService->getProductTypes($Order);
0 ignored issues
show
Deprecated Code introduced by
The property Eccube\Service\ShoppingService::$orderService has been deprecated.

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
Deprecated Code introduced by
The method Eccube\Service\OrderService::getProductTypes() has been deprecated with message: since 3.0.0, to be removed in 3.1

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
977
        if ($this->BaseInfo->getOptionMultipleShipping() == Constant::ENABLED && count($productTypes) > 1) {
978
            // 複数配送時の支払方法
979
980
            $payments = $this->paymentRepository->findAllowedPayments($deliveries);
981
        } else {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
982
983
            // 配送業者をセット
984
            $shippings = $Order->getShippings();
985
            $Shipping = $shippings[0];
986
            $payments = $this->paymentRepository->findPayments($Shipping->getDelivery(), true);
987
0 ignored issues
show
Coding Style introduced by
Blank line found at end of control structure
Loading history...
988
        }
989
        $payments = $this->getPayments($payments, $Order->getSubTotal());
990
991
        return $payments;
992
993
    }
994
995
    /**
996
     * お届け先ごとにFormを作成
997
     *
998
     * @param Order $Order
999
     * @return \Symfony\Component\Form\Form
1000
     * @deprecated since 3.0, to be removed in 3.1
1001
     */
1002 View Code Duplication
    public function getShippingForm(Order $Order)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1003
    {
1004
        $message = $Order->getMessage();
1005
1006
        $deliveries = $this->getDeliveriesOrder($Order);
1007
1008
        // 配送業者の支払方法を取得
1009
        $payments = $this->getFormPayments($deliveries, $Order);
1010
1011
        $builder = $this->formFactory->createBuilder('shopping', null, array(
1012
            'payments' => $payments,
1013
            'payment' => $Order->getPayment(),
1014
            'message' => $message,
1015
        ));
1016
1017
        $builder
1018
            ->add('shippings', CollectionType::class, array(
1019
                'entry_type' => ShippingItemType::class,
1020
                'data' => $Order->getShippings(),
1021
            ));
1022
1023
        $form = $builder->getForm();
1024
1025
        return $form;
1026
1027
    }
1028
1029
    /**
1030
     * お届け先ごとにFormBuilderを作成
1031
     *
1032
     * @param Order $Order
1033
     * @return \Symfony\Component\Form\FormBuilderInterface
1034
     *
1035
     * @deprecated 利用している箇所なし
1036
     */
1037 View Code Duplication
    public function getShippingFormBuilder(Order $Order)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1038
    {
1039
        $message = $Order->getMessage();
1040
1041
        $deliveries = $this->getDeliveriesOrder($Order);
1042
1043
        // 配送業者の支払方法を取得
1044
        $payments = $this->getFormPayments($deliveries, $Order);
1045
1046
        $builder = $this->formFactory->createBuilder('shopping', null, array(
1047
            'payments' => $payments,
1048
            'payment' => $Order->getPayment(),
1049
            'message' => $message,
1050
        ));
1051
1052
        $builder
1053
            ->add('shippings', CollectionType::class, array(
1054
                'entry_type' => ShippingItemType::class,
1055
                'data' => $Order->getShippings(),
1056
            ));
1057
1058
        return $builder;
1059
1060
    }
1061
1062
1063
    /**
1064
     * フォームデータを更新
1065
     *
1066
     * @param Order $Order
1067
     * @param array $data
1068
     *
1069
     * @deprecated
1070
     */
1071 1
    public function setFormData(Order $Order, array $data)
1072
    {
1073
1074
        // お問い合わせ
1075 1
        $Order->setMessage($data['message']);
1076
1077
        // お届け先情報を更新
1078 1
        $shippings = $data['shippings'];
1079 1
        foreach ($shippings as $Shipping) {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
1080
1081 1
            $deliveryTime = $Shipping->getDeliveryTime();
1082 1
            if (!empty($deliveryTime)) {
1083
                $Shipping->setShippingDeliveryTime($deliveryTime->getDeliveryTime());
1084 1
                $Shipping->setTimeId($deliveryTime->getId());
1085
            }
1086
0 ignored issues
show
Coding Style introduced by
Blank line found at end of control structure
Loading history...
1087
        }
1088
1089
    }
1090
1091
    /**
1092
     * 配送料の合計金額を計算
1093
     *
1094
     * @param Order $Order
1095
     * @return Order
1096
     */
1097 2
    public function calculateDeliveryFee(Order $Order)
1098
    {
1099
1100
        // 配送業者を取得
1101 2
        $shippings = $Order->getShippings();
0 ignored issues
show
Unused Code introduced by
$shippings is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1102
1103
        // 配送料合計金額
1104
        // TODO CalculateDeliveryFeeStrategy でセットする
1105
        // $Order->setDeliveryFeeTotal($this->getShippingDeliveryFeeTotal($shippings));
1106
1107
        // 配送料無料条件(合計金額)
1108 2
        $this->setDeliveryFreeAmount($Order);
1109
1110
        // 配送料無料条件(合計数量)
1111 2
        $this->setDeliveryFreeQuantity($Order);
1112
1113 2
        return $Order;
1114
1115
    }
1116
1117
1118
    /**
1119
     * 購入処理を行う
1120
     *
1121
     * @param Order $Order
1122
     * @throws ShoppingException
1123
     */
1124 2
    public function processPurchase(Order $Order)
1125
    {
1126
1127 2
        $em = $this->entityManager;
0 ignored issues
show
Unused Code introduced by
$em is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1128
1129
        // 受注情報、配送情報を更新
1130 2
        $Order = $this->calculateDeliveryFee($Order);
1131 2
        $this->setOrderUpdateData($Order);
1132
1133 2
        if ($this->app->isGranted('ROLE_USER')) {
1134
            // 会員の場合、購入金額を更新
1135 1
            $this->setCustomerUpdate($Order, $this->app->user());
1136
        }
1137
    }
1138
1139
1140
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$discount" missing
Loading history...
1141
     * 値引き可能かチェック
1142
     *
1143
     * @param Order $Order
0 ignored issues
show
introduced by
Expected 4 spaces after parameter type; 1 found
Loading history...
1144
     * @param       $discount
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
1145
     * @return bool
1146
     */
1147
    public function isDiscount(Order $Order, $discount)
1148
    {
1149
1150
        if ($Order->getTotal() < $discount) {
1151
            return false;
1152
        }
1153
1154
        return true;
1155
    }
1156
1157
1158
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$discount" missing
Loading history...
1159
     * 値引き金額をセット
1160
     *
1161
     * @param Order $Order
0 ignored issues
show
introduced by
Expected 4 spaces after parameter type; 1 found
Loading history...
1162
     * @param $discount
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
1163
     */
1164
    public function setDiscount(Order $Order, $discount)
1165
    {
1166
1167
        $Order->setDiscount($Order->getDiscount() + $discount);
1168
1169
    }
1170
1171
1172
    /**
1173
     * 合計金額を計算
1174
     *
1175
     * @param Order $Order
1176
     * @return Order
1177
     */
1178 1
    public function calculatePrice(Order $Order)
1179
    {
1180
1181 1
        $total = $Order->getTotalPrice();
1182
1183 1
        if ($total < 0) {
1184
            // 合計金額がマイナスの場合、0を設定し、discountは値引きされた額のみセット
1185
            $total = 0;
1186
        }
1187
1188 1
        $Order->setTotal($total);
1189 1
        $Order->setPaymentTotal($total);
1190
1191 1
        return $Order;
1192
1193
    }
1194
1195
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$status" missing
Loading history...
1196
     * 受注ステータスをセット
1197
     *
1198
     * @param Order $Order
0 ignored issues
show
introduced by
Expected 2 spaces after parameter type; 1 found
Loading history...
1199
     * @param $status
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
1200
     * @return Order
1201
     */
1202 3
    public function setOrderStatus(Order $Order, $status)
1203
    {
1204
1205 3
        $Order->setOrderDate(new \DateTime());
1206 3
        $Order->setOrderStatus($this->orderStatusRepository->find($status));
1207
1208 3
        $event = new EventArgs(
1209
            array(
1210 3
                'Order' => $Order,
1211
            ),
1212 3
            null
1213
        );
1214 3
        $this->eventDispatcher->dispatch(EccubeEvents::SERVICE_SHOPPING_ORDER_STATUS, $event);
1215
1216 3
        return $Order;
1217
1218
    }
1219
1220
    /**
1221
     * 受注メール送信を行う
1222
     *
1223
     * @param Order $Order
1224
     * @return MailHistory
1225
     */
1226 2
    public function sendOrderMail(Order $Order)
1227
    {
1228
1229
        // メール送信
1230 2
        $message = $this->mailService->sendOrderMail($Order);
1231
1232
        // 送信履歴を保存.
1233 2
        $MailHistory = new MailHistory();
1234
        $MailHistory
1235 2
            ->setSubject($message->getSubject())
1236 2
            ->setMailBody($message->getBody())
1237 2
            ->setSendDate(new \DateTime())
1238 2
            ->setOrder($Order);
1239
1240 2
        $this->entityManager->persist($MailHistory);
1241 2
        $this->entityManager->flush($MailHistory);
1242
1243 2
        return $MailHistory;
1244
1245
    }
1246
1247
1248
    /**
1249
     * 受注処理完了通知
1250
     *
1251
     * @param Order $Order
1252
     */
1253
    public function notifyComplete(Order $Order)
1254
    {
1255
1256
        $event = new EventArgs(
1257
            array(
1258
                'Order' => $Order,
1259
            ),
1260
            null
1261
        );
1262
        $this->eventDispatcher->dispatch(EccubeEvents::SERVICE_SHOPPING_NOTIFY_COMPLETE, $event);
1263
1264
    }
1265
1266
1267
}
1268