Completed
Pull Request — experimental/sf (#3293)
by
unknown
135:44 queued 125:34
created

ShoppingService::getNewDetails()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 18
rs 9.6666
c 0
b 0
f 0
ccs 0
cts 8
cp 0
crap 6
1
<?php
2
3
/*
4
 * This file is part of EC-CUBE
5
 *
6
 * Copyright(c) LOCKON CO.,LTD. All Rights Reserved.
7
 *
8
 * http://www.lockon.co.jp/
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Eccube\Service;
15
16
use Doctrine\ORM\EntityManager;
17
use Doctrine\ORM\EntityManagerInterface;
18
use Eccube\Common\EccubeConfig;
19
use Eccube\Entity\BaseInfo;
20
use Eccube\Entity\Customer;
21
use Eccube\Entity\CustomerAddress;
22
use Eccube\Entity\Delivery;
23
use Eccube\Entity\MailHistory;
24
use Eccube\Entity\Master\DeviceType;
25
use Eccube\Entity\Master\OrderStatus;
26
use Eccube\Entity\Order;
27
use Eccube\Entity\OrderItem;
28
use Eccube\Entity\Product;
29
use Eccube\Entity\ProductClass;
30
use Eccube\Entity\Shipping;
31
use Eccube\Event\EccubeEvents;
32
use Eccube\Event\EventArgs;
33
use Eccube\Exception\CartException;
34
use Eccube\Form\Type\ShippingItemType;
35
use Eccube\Repository\CustomerAddressRepository;
36
use Eccube\Repository\DeliveryFeeRepository;
37
use Eccube\Repository\DeliveryRepository;
38
use Eccube\Repository\DeliveryTimeRepository;
39
use Eccube\Repository\MailTemplateRepository;
40
use Eccube\Repository\Master\DeviceTypeRepository;
41
use Eccube\Repository\Master\OrderStatusRepository;
42
use Eccube\Repository\Master\PrefRepository;
43
use Eccube\Repository\OrderRepository;
44
use Eccube\Repository\PaymentRepository;
45
use Eccube\Repository\TaxRuleRepository;
46
use Eccube\Util\StringUtil;
47
use Symfony\Component\EventDispatcher\EventDispatcher;
48
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
49
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
50
use Symfony\Component\Form\FormFactory;
51
use Symfony\Component\Form\FormFactoryInterface;
52
use Symfony\Component\HttpFoundation\Session\Session;
53
use Symfony\Component\HttpFoundation\Session\SessionInterface;
54
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
55
56
class ShoppingService
0 ignored issues
show
introduced by
Missing class doc comment
Loading history...
57
{
58
    /**
59
     * @var MailTemplateRepository
60
     */
61
    protected $mailTemplateRepository;
62
63
    /**
64
     * @var MailService
65
     */
66
    protected $mailService;
67
68
    /**
69
     * @var EventDispatcher
70
     */
71
    protected $eventDispatcher;
72
73
    /**
74
     * @var FormFactory
75
     */
76
    protected $formFactory;
77
78
    /**
79
     * @var DeliveryFeeRepository
80
     */
81
    protected $deliveryFeeRepository;
82
83
    /**
84
     * @var TaxRuleRepository
85
     */
86
    protected $taxRuleRepository;
87
88
    /**
89
     * @var CustomerAddressRepository
90
     */
91
    protected $customerAddressRepository;
92
93
    /**
94
     * @var DeliveryRepository
95
     */
96
    protected $deliveryRepository;
97
98
    /**
99
     * @var DeliveryTimeRepository
100
     */
101
    protected $deliveryTimeRepository;
102
103
    /**
104
     * @var OrderStatusRepository
105
     */
106
    protected $orderStatusRepository;
107
108
    /**
109
     * @var PaymentRepository
110
     */
111
    protected $paymentRepository;
112
113
    /**
114
     * @var DeviceTypeRepository
115
     */
116
    protected $deviceTypeRepository;
117
118
    /**
119
     * @var EntityManager
120
     */
121
    protected $entityManager;
122
123
    /**
124
     * @var EccubeConfig
125
     */
126
    protected $eccubeConfig;
127
128
    /**
129
     * @var PrefRepository
130
     */
131
    protected $prefRepository;
132
133
    /**
134
     * @var Session
135
     */
136
    protected $session;
137
138
    /**
139
     * @var OrderRepository
140
     */
141
    protected $orderRepository;
142
143
    /**
144
     * @var BaseInfo
145
     */
146
    protected $BaseInfo;
147
148
    /**
149
     * @var \Eccube\Service\CartService
150
     */
151
    protected $cartService;
152
153
    /**
154
     * @var \Eccube\Service\OrderService
155
     *
156
     * @deprecated
157
     */
158
    protected $orderService;
159
160
    /**
161
     * @var AuthorizationCheckerInterface
162
     */
163
    protected $authorizationChecker;
164
165
    /**
166
     * @var \Mobile_Detect
167
     */
168
    protected $mobileDetect;
169
170
    /**
171
     * ShoppingService constructor.
172
     *
173
     * @param MailTemplateRepository $mailTemplateRepository
0 ignored issues
show
introduced by
Expected 8 spaces after parameter type; 1 found
Loading history...
174
     * @param MailService $mailService
0 ignored issues
show
introduced by
Expected 19 spaces after parameter type; 1 found
Loading history...
175
     * @param EventDispatcher $eventDispatcher
0 ignored issues
show
introduced by
Expected 15 spaces after parameter type; 1 found
Loading history...
176
     * @param FormFactory $formFactory
0 ignored issues
show
introduced by
Expected 19 spaces after parameter type; 1 found
Loading history...
177
     * @param DeliveryFeeRepository $deliveryFeeRepository
0 ignored issues
show
introduced by
Expected 9 spaces after parameter type; 1 found
Loading history...
178
     * @param TaxRuleRepository $taxRuleRepository
0 ignored issues
show
introduced by
Expected 13 spaces after parameter type; 1 found
Loading history...
179
     * @param CustomerAddressRepository $customerAddressRepository
0 ignored issues
show
introduced by
Expected 5 spaces after parameter type; 1 found
Loading history...
180
     * @param DeliveryRepository $deliveryRepository
0 ignored issues
show
introduced by
Expected 12 spaces after parameter type; 1 found
Loading history...
181
     * @param DeliveryTimeRepository $deliveryTimeRepository
0 ignored issues
show
introduced by
Expected 8 spaces after parameter type; 1 found
Loading history...
182
     * @param OrderStatusRepository $orderStatusRepository
0 ignored issues
show
introduced by
Expected 9 spaces after parameter type; 1 found
Loading history...
183
     * @param PaymentRepository $paymentRepository
0 ignored issues
show
introduced by
Expected 13 spaces after parameter type; 1 found
Loading history...
184
     * @param DeviceTypeRepository $deviceTypeRepository
0 ignored issues
show
introduced by
Expected 10 spaces after parameter type; 1 found
Loading history...
185
     * @param EntityManager $entityManager
0 ignored issues
show
introduced by
Expected 17 spaces after parameter type; 1 found
Loading history...
186
     * @param EccubeConfig $eccubeConfig
0 ignored issues
show
introduced by
Expected 18 spaces after parameter type; 1 found
Loading history...
187
     * @param PrefRepository $prefRepository
0 ignored issues
show
introduced by
Expected 16 spaces after parameter type; 1 found
Loading history...
188
     * @param Session $session
0 ignored issues
show
introduced by
Expected 23 spaces after parameter type; 1 found
Loading history...
189
     * @param OrderRepository $orderRepository
0 ignored issues
show
introduced by
Expected 15 spaces after parameter type; 1 found
Loading history...
190
     * @param CartService $cartService
0 ignored issues
show
introduced by
Expected 19 spaces after parameter type; 1 found
Loading history...
191
     * @param OrderService $orderService
0 ignored issues
show
introduced by
Expected 18 spaces after parameter type; 1 found
Loading history...
192
     * @param BaseInfo $BaseInfo
0 ignored issues
show
introduced by
Expected 22 spaces after parameter type; 1 found
Loading history...
193
     * @param AuthorizationCheckerInterface $authorizationChecker
194
     * @param \Mobile_Detect $mobileDetect
0 ignored issues
show
introduced by
Expected 16 spaces after parameter type; 1 found
Loading history...
195
     */
196 59
    public function __construct(
197
        MailTemplateRepository $mailTemplateRepository,
198
        MailService $mailService,
199
        EventDispatcherInterface $eventDispatcher,
200
        FormFactoryInterface $formFactory,
201
        DeliveryFeeRepository $deliveryFeeRepository,
202
        TaxRuleRepository $taxRuleRepository,
203
        CustomerAddressRepository $customerAddressRepository,
204
        DeliveryRepository $deliveryRepository,
205
        DeliveryTimeRepository $deliveryTimeRepository,
206
        OrderStatusRepository $orderStatusRepository,
207
        PaymentRepository $paymentRepository,
208
        DeviceTypeRepository $deviceTypeRepository,
209
        EntityManagerInterface $entityManager,
210
        EccubeConfig $eccubeConfig,
211
        PrefRepository $prefRepository,
212
        SessionInterface $session,
213
        OrderRepository $orderRepository,
214
        CartService $cartService,
215
        OrderService $orderService,
216
        BaseInfo $BaseInfo,
217
        AuthorizationCheckerInterface $authorizationChecker,
218
        \Mobile_Detect $mobileDetect
219
    ) {
220 59
        $this->mailTemplateRepository = $mailTemplateRepository;
221 59
        $this->mailService = $mailService;
222 59
        $this->eventDispatcher = $eventDispatcher;
0 ignored issues
show
Documentation Bug introduced by
$eventDispatcher is of type object<Symfony\Component...entDispatcherInterface>, but the property $eventDispatcher was declared to be of type object<Symfony\Component...atcher\EventDispatcher>. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
223 59
        $this->formFactory = $formFactory;
0 ignored issues
show
Documentation Bug introduced by
$formFactory is of type object<Symfony\Component...m\FormFactoryInterface>, but the property $formFactory was declared to be of type object<Symfony\Component\Form\FormFactory>. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
224 59
        $this->deliveryFeeRepository = $deliveryFeeRepository;
225 59
        $this->taxRuleRepository = $taxRuleRepository;
226 59
        $this->customerAddressRepository = $customerAddressRepository;
227 59
        $this->deliveryRepository = $deliveryRepository;
228 59
        $this->deliveryTimeRepository = $deliveryTimeRepository;
229 59
        $this->orderStatusRepository = $orderStatusRepository;
230 59
        $this->paymentRepository = $paymentRepository;
231 59
        $this->deviceTypeRepository = $deviceTypeRepository;
232 59
        $this->entityManager = $entityManager;
0 ignored issues
show
Documentation Bug introduced by
$entityManager is of type object<Doctrine\ORM\EntityManagerInterface>, but the property $entityManager was declared to be of type object<Doctrine\ORM\EntityManager>. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
233 59
        $this->eccubeConfig = $eccubeConfig;
234 59
        $this->prefRepository = $prefRepository;
235 59
        $this->session = $session;
0 ignored issues
show
Documentation Bug introduced by
$session is of type object<Symfony\Component...ssion\SessionInterface>, but the property $session was declared to be of type object<Symfony\Component...dation\Session\Session>. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
236 59
        $this->orderRepository = $orderRepository;
237 59
        $this->cartService = $cartService;
238 59
        $this->orderService = $orderService;
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...
239 59
        $this->BaseInfo = $BaseInfo;
240 59
        $this->authorizationChecker = $authorizationChecker;
241 59
        $this->mobileDetect = $mobileDetect;
242
    }
243
244
    /**
245
     * セッションにセットされた受注情報を取得
246
     *
247
     * @param null $status
248
     *
249
     * @return null|object
250
     */
251 51
    public function getOrder($status = null)
252
    {
253
        // 受注データを取得
254 51
        $preOrderId = $this->cartService->getPreOrderId();
255 51
        if (!$preOrderId) {
256 51
            return null;
257
        }
258
259
        $condition = [
260 40
            'pre_order_id' => $preOrderId,
261
        ];
262
263 40
        if (!is_null($status)) {
264
            $condition += [
265 40
                'OrderStatus' => $status,
266
            ];
267
        }
268
269 40
        $Order = $this->orderRepository->findOneBy($condition);
270
271 40
        return $Order;
272
    }
273
274
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$sesisonKey" missing
Loading history...
275
     * 非会員情報を取得
276
     *
277
     * @param $sesisonKey
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
278
     *
279
     * @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...
280
     */
281
    public function getNonMember($sesisonKey)
282
    {
283
        if ($NonMember = $this->session->get($sesisonKey)) {
284
            $Pref = $this->prefRepository->find($NonMember->getPref()->getId());
285
            $NonMember->setPref($Pref);
286
287
            return $NonMember;
288
        }
289
    }
290
291
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$Customer" missing
Loading history...
292
     * 受注情報を作成
293
     *
294
     * @param $Customer
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
295
     *
296
     * @return \Eccube\Entity\Order
297
     */
298
    public function createOrder($Customer)
299
    {
300
        // ランダムなpre_order_idを作成
301 View Code Duplication
        do {
302
            $preOrderId = sha1(StringUtil::random(32));
303
            $Order = $this->orderRepository->findOneBy([
304
                'pre_order_id' => $preOrderId,
305
                'OrderStatus' => OrderStatus::PROCESSING,
306
            ]);
307
        } while ($Order);
308
309
        // 受注情報、受注明細情報、お届け先情報、配送商品情報を作成
310
        $Order = $this->registerPreOrder(
311
            $Customer,
312
            $preOrderId);
313
314
        $this->cartService->setPreOrderId($preOrderId);
315
        $this->cartService->save();
316
317
        return $Order;
318
    }
319
320
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$Customer" missing
Loading history...
introduced by
Doc comment for parameter "$preOrderId" missing
Loading history...
321
     * 仮受注情報作成
322
     *
323
     * @param $Customer
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
324
     * @param $preOrderId
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
325
     *
326
     * @return mixed
327
     *
328
     * @throws \Doctrine\ORM\NoResultException
329
     * @throws \Doctrine\ORM\NonUniqueResultException
330
     */
331
    public function registerPreOrder(Customer $Customer, $preOrderId)
332
    {
333
        $this->em = $this->entityManager;
334
335
        // 受注情報を作成
336
        $Order = $this->getNewOrder($Customer);
337
        $Order->setPreOrderId($preOrderId);
338
339
        $DeviceType = $this->deviceTypeRepository->find($this->mobileDetect->isMobile() ? DeviceType::DEVICE_TYPE_SP : DeviceType::DEVICE_TYPE_PC);
340
        $Order->setDeviceType($DeviceType);
341
342
        $this->entityManager->persist($Order);
343
344
        // 配送業者情報を取得
345
        $deliveries = $this->getDeliveriesCart();
346
347
        // お届け先情報を作成
348
        $Order = $this->getNewShipping($Order, $Customer, $deliveries);
349
350
        // 受注明細情報、配送商品情報を作成
351
        $Order = $this->getNewDetails($Order);
352
353
        // 小計
354
        $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...
355
356
        // 消費税のみの小計
357
        $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...
358
359
        // 配送料合計金額
360
        // TODO CalculateDeliveryFeeStrategy でセットする
361
        // $Order->setDeliveryFeeTotal($this->getShippingDeliveryFeeTotal($Order->getShippings()));
362
363
        // 小計
364
        $Order->setSubTotal($subTotal);
365
366
        // 配送料無料条件(合計金額)
367
        $this->setDeliveryFreeAmount($Order);
368
369
        // 配送料無料条件(合計数量)
370
        $this->setDeliveryFreeQuantity($Order);
371
372
        // 初期選択の支払い方法をセット
373
        $payments = $this->paymentRepository->findAllowedPayments($deliveries, true, $Order);
374
375
        if (count($payments) > 0) {
376
            $payment = $payments[0];
377
            $Order->setPayment($payment);
378
            $Order->setPaymentMethod($payment->getMethod());
379
            $Order->setCharge($payment->getCharge());
380
        } else {
381
            $Order->setCharge(0);
382
        }
383
384
        $Order->setTax($tax);
385
386
        // 合計金額の計算
387
        $this->calculatePrice($Order);
388
389
        $this->entityManager->flush();
390
391
        return $Order;
392
    }
393
394
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$Customer" missing
Loading history...
395
     * 受注情報を作成
396
     *
397
     * @param $Customer
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
398
     *
399
     * @return \Eccube\Entity\Order
400
     */
401
    public function getNewOrder(Customer $Customer)
402
    {
403
        $Order = $this->newOrder();
404
        $this->copyToOrderFromCustomer($Order, $Customer);
405
406
        return $Order;
407
    }
408
409
    /**
410
     * 受注情報を作成
411
     *
412
     * @return \Eccube\Entity\Order
413
     */
414
    public function newOrder()
415
    {
416
        $OrderStatus = $this->orderStatusRepository->find(OrderStatus::PROCESSING);
417
        $Order = new \Eccube\Entity\Order($OrderStatus);
418
419
        return $Order;
420
    }
421
422
    /**
423
     * 受注情報を作成
424
     *
425
     * @param \Eccube\Entity\Order $Order
0 ignored issues
show
introduced by
Expected 9 spaces after parameter type; 1 found
Loading history...
426
     * @param \Eccube\Entity\Customer|null $Customer
427
     *
428
     * @return \Eccube\Entity\Order
429
     */
430
    public function copyToOrderFromCustomer(Order $Order, Customer $Customer = null)
431
    {
432
        if (is_null($Customer)) {
433
            return $Order;
434
        }
435
436
        if ($Customer->getId()) {
437
            $Order->setCustomer($Customer);
438
        }
439
        $Order
440
            ->setName01($Customer->getName01())
441
            ->setName02($Customer->getName02())
442
            ->setKana01($Customer->getKana01())
443
            ->setKana02($Customer->getKana02())
444
            ->setCompanyName($Customer->getCompanyName())
445
            ->setEmail($Customer->getEmail())
446
            ->setPhoneNumber($Customer->getPhoneNumber())
447
            ->setPostalCode($Customer->getPostalCode())
448
            ->setPref($Customer->getPref())
449
            ->setAddr01($Customer->getAddr01())
450
            ->setAddr02($Customer->getAddr02())
451
            ->setSex($Customer->getSex())
452
            ->setBirth($Customer->getBirth())
453
            ->setJob($Customer->getJob());
454
455
        return $Order;
456
    }
457
458
    /**
459
     * 配送業者情報を取得
460
     *
461
     * @return array
462
     */
463
    public function getDeliveriesCart()
464
    {
465
        // カートに保持されている販売種別を取得
466
        $saleTypes = $this->cartService->getSaleTypes();
0 ignored issues
show
Bug introduced by
The method getSaleTypes() 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...
467
468
        return $this->getDeliveries($saleTypes);
469
    }
470
471
    /**
472
     * 配送業者情報を取得
473
     *
474
     * @param Order $Order
475
     *
476
     * @return array
477
     */
478
    public function getDeliveriesOrder(Order $Order)
479
    {
480
        // 受注情報から販売種別を取得
481
        $saleTypes = $this->orderService->getSaleTypes($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::getSaleTypes() 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...
482
483
        return $this->getDeliveries($saleTypes, $Order);
484
    }
485
486
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$saleTypes" missing
Loading history...
introduced by
Doc comment for parameter "$Order" missing
Loading history...
487
     * 配送業者情報を取得
488
     *
489
     * @param $saleTypes
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
490
     * @param $Order
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
491
     *
492
     * @return array
493
     */
494
    public function getDeliveries($saleTypes, Order $Order = null)
495
    {
496
        // 販売種別に紐づく配送業者を取得
497
        $deliveries = $this->deliveryRepository->getDeliveries($saleTypes);
498
        $deliveries = $this->filterDeliveries($deliveries, $Order);
499
500
        return $deliveries;
501
    }
502
503
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$deliveries" missing
Loading history...
504
     * お届け先情報を作成
505
     *
506
     * @param Order $Order
0 ignored issues
show
introduced by
Expected 6 spaces after parameter type; 1 found
Loading history...
507
     * @param Customer $Customer
0 ignored issues
show
introduced by
Expected 3 spaces after parameter type; 1 found
Loading history...
508
     * @param $deliveries
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
509
     *
510
     * @return Order
511
     */
512
    public function getNewShipping(Order $Order, Customer $Customer, $deliveries)
513
    {
514
        $saleTypes = [];
515
        foreach ($deliveries as $Delivery) {
516
            if (!in_array($Delivery->getSaleType()
517
                ->getId(), $saleTypes)) {
0 ignored issues
show
Coding Style introduced by
This line of the multi-line function call does not seem to be indented correctly. Expected 12 spaces, but found 16.
Loading history...
518
                $Shipping = new Shipping();
519
520
                $this->copyToShippingFromCustomer($Shipping, $Customer)
521
                    ->setOrder($Order);
522
523
                // 配送料金の設定
524
                $this->setShippingDeliveryFee($Shipping, $Delivery);
525
526
                $this->entityManager->persist($Shipping);
527
528
                $Order->addShipping($Shipping);
529
530
                $saleTypes[] = $Delivery->getProductType()
531
                    ->getId();
532
            }
533
        }
534
535
        return $Order;
536
    }
537
538
    /**
539
     * お届け先情報を作成
540
     *
541
     * @param \Eccube\Entity\Shipping $Shipping
0 ignored issues
show
introduced by
Expected 6 spaces after parameter type; 1 found
Loading history...
542
     * @param \Eccube\Entity\Customer|null $Customer
543
     *
544
     * @return \Eccube\Entity\Shipping
545
     */
546
    public function copyToShippingFromCustomer(Shipping $Shipping, Customer $Customer = null)
547
    {
548
        if (is_null($Customer)) {
549
            return $Shipping;
550
        }
551
552
        /** @var CustomerAddress $CustomerAddress */
553
        $CustomerAddress = $this->customerAddressRepository->findOneBy(
554
            ['Customer' => $Customer],
555
            ['id' => 'ASC']
556
        );
557
558
        if (!is_null($CustomerAddress)) {
559
            $Shipping
560
                ->setName01($CustomerAddress->getName01())
561
                ->setName02($CustomerAddress->getName02())
562
                ->setKana01($CustomerAddress->getKana01())
563
                ->setKana02($CustomerAddress->getKana02())
564
                ->setCompanyName($CustomerAddress->getCompanyName())
565
                ->setPhoneNumber($CustomerAddress->getPhoneNumber())
566
                ->setPostalCode($CustomerAddress->getPostalCode())
567
                ->setPref($CustomerAddress->getPref())
568
                ->setAddr01($CustomerAddress->getAddr01())
569
                ->setAddr02($CustomerAddress->getAddr02());
570
        } else {
571
            $Shipping
572
                ->setName01($Customer->getName01())
573
                ->setName02($Customer->getName02())
574
                ->setKana01($Customer->getKana01())
575
                ->setKana02($Customer->getKana02())
576
                ->setCompanyName($Customer->getCompanyName())
577
                ->setPhoneNumber($Customer->getPhoneNumber())
578
                ->setPostalCode($Customer->getPostalCode())
579
                ->setPref($Customer->getPref())
580
                ->setAddr01($Customer->getAddr01())
581
                ->setAddr02($Customer->getAddr02());
582
        }
583
584
        return $Shipping;
585
    }
586
587
    /**
588
     * 受注明細情報、配送商品情報を作成
589
     *
590
     * @param Order $Order
591
     *
592
     * @return Order
593
     */
594
    public function getNewDetails(Order $Order)
595
    {
596
        // 受注詳細, 配送商品
597
        foreach ($this->cartService->getCart()
598
                     ->getCartItems() as $item) {
599
            /* @var $ProductClass \Eccube\Entity\ProductClass */
600
            $ProductClass = $item->getProductClass();
601
            /* @var $Product \Eccube\Entity\Product */
602
            $Product = $ProductClass->getProduct();
603
604
            $quantity = $item->getQuantity();
605
606
            // 配送商品情報を作成
607
            $this->getNewOrderItem($Order, $Product, $ProductClass, $quantity);
608
        }
609
610
        return $Order;
611
    }
612
613
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$quantity" missing
Loading history...
614
     * 配送商品情報を作成
615
     *
616
     * @param Order $Order
0 ignored issues
show
introduced by
Expected 8 spaces after parameter type; 1 found
Loading history...
617
     * @param Product $Product
0 ignored issues
show
introduced by
Expected 6 spaces after parameter type; 1 found
Loading history...
618
     * @param ProductClass $ProductClass
619
     * @param $quantity
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
620
     *
621
     * @return \Eccube\Entity\OrderItem
622
     */
623
    public function getNewOrderItem(Order $Order, Product $Product, ProductClass $ProductClass, $quantity)
624
    {
625
        $OrderItem = new OrderItem();
626
        $shippings = $Order->getShippings();
627
628
        // 選択された商品がどのお届け先情報と関連するかチェック
629
        $Shipping = null;
630
        foreach ($shippings as $s) {
631
            if ($s->getDelivery()
632
                    ->getSaleType()
633
                    ->getId() == $ProductClass->getSaleType()
634
                    ->getId()) {
635
                // 販売種別が同一のお届け先情報と関連させる
636
                $Shipping = $s;
637
                break;
638
            }
639
        }
640
641
        if (is_null($Shipping)) {
642
            // お届け先情報と関連していない場合、エラー
643
            throw new CartException('shopping.delivery.not.saletype');
644
        }
645
646
        // 商品ごとの配送料合計
647
        $productDeliveryFeeTotal = 0;
648
        if ($this->BaseInfo->isOptionProductDeliveryFee()) {
649
            $productDeliveryFeeTotal = $ProductClass->getDeliveryFee() * $quantity;
650
        }
651
652
        $Shipping->setShippingDeliveryFee($Shipping->getShippingDeliveryFee() + $productDeliveryFeeTotal);
653
654
        $OrderItem->setShipping($Shipping)
655
            ->setOrder($Order)
656
            ->setProductClass($ProductClass)
657
            ->setProduct($Product)
658
            ->setProductName($Product->getName())
659
            ->setProductCode($ProductClass->getCode())
660
            ->setPrice($ProductClass->getPrice02())
661
            ->setQuantity($quantity);
662
663
        $ClassCategory1 = $ProductClass->getClassCategory1();
664
        if (!is_null($ClassCategory1)) {
665
            $OrderItem->setClasscategoryName1($ClassCategory1->getName());
666
            $OrderItem->setClassName1($ClassCategory1->getClassName()
667
                ->getName());
0 ignored issues
show
Coding Style introduced by
This line of the multi-line function call does not seem to be indented correctly. Expected 12 spaces, but found 16.
Loading history...
668
        }
669
        $ClassCategory2 = $ProductClass->getClassCategory2();
670
        if (!is_null($ClassCategory2)) {
671
            $OrderItem->setClasscategoryName2($ClassCategory2->getName());
672
            $OrderItem->setClassName2($ClassCategory2->getClassName()
673
                ->getName());
0 ignored issues
show
Coding Style introduced by
This line of the multi-line function call does not seem to be indented correctly. Expected 12 spaces, but found 16.
Loading history...
674
        }
675
        $Shipping->addOrderItem($OrderItem);
676
        $this->entityManager->persist($OrderItem);
677
678
        return $OrderItem;
679
    }
680
681
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$shippings" missing
Loading history...
682
     * お届け先ごとの送料合計を取得
683
     *
684
     * @param $shippings
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
685
     *
686
     * @return int
687
     */
688
    public function getShippingDeliveryFeeTotal($shippings)
689
    {
690
        $deliveryFeeTotal = 0;
691
        foreach ($shippings as $Shipping) {
692
            $deliveryFeeTotal += $Shipping->getShippingDeliveryFee();
693
        }
694
695
        return $deliveryFeeTotal;
696
    }
697
698
    /**
699
     * 商品ごとの配送料を取得
700
     *
701
     * @param Shipping $Shipping
702
     *
703
     * @return int
704
     */
705
    public function getProductDeliveryFee(Shipping $Shipping)
706
    {
707
        $productDeliveryFeeTotal = 0;
708
        $OrderItems = $Shipping->getOrderItems();
709
        foreach ($OrderItems as $OrderItem) {
710
            $productDeliveryFeeTotal += $OrderItem->getProductClass()
711
                    ->getDeliveryFee() * $OrderItem->getQuantity();
712
        }
713
714
        return $productDeliveryFeeTotal;
715
    }
716
717
    /**
718
     * 住所などの情報が変更された時に金額の再計算を行う
719
     *
720
     * @deprecated PurchaseFlowで行う
721
     *
722
     * @param Order $Order
723
     *
724
     * @return Order
725
     */
726
    public function getAmount(Order $Order)
727
    {
728
        // 初期選択の配送業者をセット
729
        $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...
730
731
        // 配送料合計金額
732
        // TODO CalculateDeliveryFeeStrategy でセットする
733
        // $Order->setDeliveryFeeTotal($this->getShippingDeliveryFeeTotal($shippings));
734
735
        // 配送料無料条件(合計金額)
736
        $this->setDeliveryFreeAmount($Order);
737
738
        // 配送料無料条件(合計数量)
739
        $this->setDeliveryFreeQuantity($Order);
740
741
        // 合計金額の計算
742
        $this->calculatePrice($Order);
743
744
        return $Order;
745
    }
746
747
    /**
748
     * 配送料金の設定
749
     *
750
     * @param Shipping $Shipping
0 ignored issues
show
introduced by
Expected 6 spaces after parameter type; 1 found
Loading history...
751
     * @param Delivery|null $Delivery
752
     */
753
    public function setShippingDeliveryFee(Shipping $Shipping, Delivery $Delivery = null)
754
    {
755
        // 配送料金の設定
756
        if (is_null($Delivery)) {
757
            $Delivery = $Shipping->getDelivery();
758
        }
759
        $deliveryFee = $this->deliveryFeeRepository->findOneBy(['Delivery' => $Delivery, 'Pref' => $Shipping->getPref()]);
760
        if ($deliveryFee) {
761
            $Shipping->setFeeId($deliveryFee->getId());
762
        }
763
        $Shipping->setDelivery($Delivery);
764
765
        // 商品ごとの配送料合計
766
        $productDeliveryFeeTotal = 0;
767
        if ($this->BaseInfo->isOptionProductDeliveryFee()) {
768
            $productDeliveryFeeTotal += $this->getProductDeliveryFee($Shipping);
769
        }
770
771
        $Shipping->setShippingDeliveryFee($deliveryFee->getFee() + $productDeliveryFeeTotal);
772
        $Shipping->setShippingDeliveryName($Delivery->getName());
773
    }
774
775
    /**
776
     * 配送料無料条件(合計金額)の条件を満たしていれば配送料金を0に設定
777
     *
778
     * @param Order $Order
779
     */
780 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...
781
    {
782
        // 配送料無料条件(合計金額)
783
        $deliveryFreeAmount = $this->BaseInfo->getDeliveryFreeAmount();
784
        if (!is_null($deliveryFreeAmount)) {
785
            // 合計金額が設定金額以上であれば送料無料
786
            if ($Order->getSubTotal() >= $deliveryFreeAmount) {
787
                $Order->setDeliveryFeeTotal(0);
788
                // お届け先情報の配送料も0にセット
789
                $shippings = $Order->getShippings();
790
                foreach ($shippings as $Shipping) {
791
                    $Shipping->setShippingDeliveryFee(0);
792
                }
793
            }
794
        }
795
    }
796
797
    /**
798
     * 配送料無料条件(合計数量)の条件を満たしていれば配送料金を0に設定
799
     *
800
     * @param Order $Order
801
     */
802 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...
803
    {
804
        // 配送料無料条件(合計数量)
805
        $deliveryFreeQuantity = $this->BaseInfo->getDeliveryFreeQuantity();
806
        if (!is_null($deliveryFreeQuantity)) {
807
            // 合計数量が設定数量以上であれば送料無料
808
            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...
809
                $Order->setDeliveryFeeTotal(0);
810
                // お届け先情報の配送料も0にセット
811
                $shippings = $Order->getShippings();
812
                foreach ($shippings as $Shipping) {
813
                    $Shipping->setShippingDeliveryFee(0);
814
                }
815
            }
816
        }
817
    }
818
819
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$data" missing
Loading history...
820
     * 受注情報、お届け先情報の更新
821
     *
822
     * @param Order $Order 受注情報
0 ignored issues
show
introduced by
Expected 22 spaces after parameter type; 1 found
Loading history...
823
     * @param $data フォームデータ
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
824
     *
825
     * @deprecated since 3.0.5, to be removed in 3.1
826
     */
827
    public function setOrderUpdate(Order $Order, $data)
828
    {
829
        // 受注情報を更新
830
        $Order->setOrderDate(new \DateTime());
831
        $Order->setOrderStatus($this->orderStatusRepository->find(OrderStatus::NEW));
832
        $Order->setMessage($data['message']);
833
        // お届け先情報を更新
834
        $shippings = $data['shippings'];
835
        foreach ($shippings as $Shipping) {
836
            $Delivery = $Shipping->getDelivery();
837
            $deliveryFee = $this->deliveryFeeRepository->findOneBy([
838
                'Delivery' => $Delivery,
839
                'Pref' => $Shipping->getPref(),
840
            ]);
841
            $deliveryTime = $Shipping->getDeliveryTime();
842
            if (!empty($deliveryTime)) {
843
                $Shipping->setShippingDeliveryTime($deliveryTime->getDeliveryTime());
844
                $Shipping->setTimeId($deliveryTime->getId());
845
            }
846
            $Shipping->setDeliveryFee($deliveryFee);
847
            // 商品ごとの配送料合計
848
            $productDeliveryFeeTotal = 0;
849
            if ($this->BaseInfo->isOptionProductDeliveryFee()) {
850
                $productDeliveryFeeTotal += $this->getProductDeliveryFee($Shipping);
851
            }
852
            $Shipping->setShippingDeliveryFee($deliveryFee->getFee() + $productDeliveryFeeTotal);
853
            $Shipping->setShippingDeliveryName($Delivery->getName());
854
        }
855
        // 配送料無料条件(合計金額)
856
        $this->setDeliveryFreeAmount($Order);
857
        // 配送料無料条件(合計数量)
858
        $this->setDeliveryFreeQuantity($Order);
859
    }
860
861
    /**
862
     * 受注情報の更新
863
     *
864
     * @param Order $Order 受注情報
865
     */
866 6
    public function setOrderUpdateData(Order $Order)
867
    {
868
        // 受注情報を更新
869 6
        $Order->setOrderDate(new \DateTime()); // XXX 後続の setOrderStatus でも時刻を更新している
870 6
        $OrderStatus = $this->orderStatusRepository->find(OrderStatus::NEW);
871 6
        $this->setOrderStatus($Order, $OrderStatus);
872
    }
873
874
    /**
875
     * 会員情報の更新
876
     *
877
     * @param Order $Order 受注情報
0 ignored issues
show
introduced by
Expected 4 spaces after parameter type; 1 found
Loading history...
878
     * @param Customer $user ログインユーザ
0 ignored issues
show
introduced by
Expected 2 spaces after parameter name; 1 found
Loading history...
879
     */
880
    public function setCustomerUpdate(Order $Order, Customer $user)
881
    {
882
        // 顧客情報を更新
883
        $now = new \DateTime();
884
        $firstBuyDate = $user->getFirstBuyDate();
885
        if (empty($firstBuyDate)) {
886
            $user->setFirstBuyDate($now);
887
        }
888
        $user->setLastBuyDate($now);
889
890
        $user->setBuyTimes($user->getBuyTimes() + 1);
891
        $user->setBuyTotal($user->getBuyTotal() + $Order->getTotal());
892
    }
893
894
    /**
895
     * お届け日を取得
896
     *
897
     * @param Order $Order
898
     *
899
     * @return array
900
     */
901
    public function getFormDeliveryDurations(Order $Order)
902
    {
903
        // お届け日の設定
904
        $minDate = 0;
905
        $deliveryDurationFlag = false;
906
907
        // 配送時に最大となる商品日数を取得
908 View Code Duplication
        foreach ($Order->getOrderItems() as $item) {
909
            if (!$item->isProduct()) {
910
                continue;
911
            }
912
            $ProductClass = $item->getProductClass();
913
            $deliveryDuration = $ProductClass->getDeliveryDuration();
914
            if (!is_null($deliveryDuration)) {
915
                if ($deliveryDuration->getDuration() < 0) {
916
                    // 配送日数がマイナスの場合はお取り寄せなのでスキップする
917
                    $deliveryDurationFlag = false;
918
                    break;
919
                }
920
921
                if ($minDate < $deliveryDuration->getDuration()) {
922
                    $minDate = $deliveryDuration->getDuration();
923
                }
924
                // 配送日数が設定されている
925
                $deliveryDurationFlag = true;
926
            }
927
        }
928
929
        // 配達最大日数期間を設定
930
        $deliveryDurations = [];
931
932
        // 配送日数が設定されている
933 View Code Duplication
        if ($deliveryDurationFlag) {
934
            $period = new \DatePeriod(
935
                new \DateTime($minDate.' day'),
936
                new \DateInterval('P1D'),
937
                new \DateTime($minDate + $this->eccubeConfig['eccube_deliv_date_end_max'].' day')
938
            );
939
940
            foreach ($period as $day) {
941
                $deliveryDurations[$day->format('Y/m/d')] = $day->format('Y/m/d');
942
            }
943
        }
944
945
        return $deliveryDurations;
946
    }
947
948
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$deliveries" missing
Loading history...
949
     * 支払方法を取得
950
     *
951
     * @param $deliveries
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
952
     * @param Order $Order
0 ignored issues
show
introduced by
Expected 6 spaces after parameter type; 1 found
Loading history...
953
     *
954
     * @return array
955
     */
956
    public function getFormPayments($deliveries, Order $Order)
957
    {
958
        $payments = $this->paymentRepository->findAllowedPayments($deliveries, true, $Order);
959
960
        return $payments;
961
    }
962
963
    /**
964
     * お届け先ごとにFormを作成
965
     *
966
     * @param Order $Order
967
     *
968
     * @return \Symfony\Component\Form\Form
969
     *
970
     * @deprecated since 3.0, to be removed in 3.1
971
     */
972 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...
973
    {
974
        $message = $Order->getMessage();
975
976
        $deliveries = $this->getDeliveriesOrder($Order);
977
978
        // 配送業者の支払方法を取得
979
        $payments = $this->getFormPayments($deliveries, $Order);
980
981
        $builder = $this->formFactory->createBuilder('shopping', null, [
982
            'payments' => $payments,
983
            'payment' => $Order->getPayment(),
984
            'message' => $message,
985
        ]);
986
987
        $builder
988
            ->add('shippings', CollectionType::class, [
989
                'entry_type' => ShippingItemType::class,
990
                'data' => $Order->getShippings(),
991
            ]);
992
993
        $form = $builder->getForm();
994
995
        return $form;
996
    }
997
998
    /**
999
     * お届け先ごとにFormBuilderを作成
1000
     *
1001
     * @param Order $Order
1002
     *
1003
     * @return \Symfony\Component\Form\FormBuilderInterface
1004
     *
1005
     * @deprecated 利用している箇所なし
1006
     */
1007 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...
1008
    {
1009
        $message = $Order->getMessage();
1010
1011
        $deliveries = $this->getDeliveriesOrder($Order);
1012
1013
        // 配送業者の支払方法を取得
1014
        $payments = $this->getFormPayments($deliveries, $Order);
1015
1016
        $builder = $this->formFactory->createBuilder('shopping', null, [
1017
            'payments' => $payments,
1018
            'payment' => $Order->getPayment(),
1019
            'message' => $message,
1020
        ]);
1021
1022
        $builder
1023
            ->add('shippings', CollectionType::class, [
1024
                'entry_type' => ShippingItemType::class,
1025
                'data' => $Order->getShippings(),
1026
            ]);
1027
1028
        return $builder;
1029
    }
1030
1031
    /**
1032
     * フォームデータを更新
1033
     *
1034
     * @param Order $Order
1035
     * @param array $data
1036
     *
1037
     * @deprecated
1038
     */
1039
    public function setFormData(Order $Order, array $data)
1040
    {
1041
        // お問い合わせ
1042
        $Order->setMessage($data['message']);
1043
1044
        // お届け先情報を更新
1045
        $shippings = $data['shippings'];
1046
        foreach ($shippings as $Shipping) {
1047
            $timeId = $Shipping->getTimeId();
1048
            $deliveryTime = null;
1049
            if ($timeId) {
1050
                $deliveryTime = $this->deliveryTimeRepository->find($timeId);
1051
            }
1052
            if ($deliveryTime) {
1053
                $Shipping->setShippingDeliveryTime($deliveryTime->getDeliveryTime());
1054
                $Shipping->setTimeId($timeId);
1055
            }
1056
        }
1057
    }
1058
1059
    /**
1060
     * 配送料の合計金額を計算
1061
     *
1062
     * @param Order $Order
1063
     *
1064
     * @return Order
1065
     */
1066
    public function calculateDeliveryFee(Order $Order)
1067
    {
1068
        // 配送業者を取得
1069
        $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...
1070
1071
        // 配送料合計金額
1072
        // TODO CalculateDeliveryFeeStrategy でセットする
1073
        // $Order->setDeliveryFeeTotal($this->getShippingDeliveryFeeTotal($shippings));
1074
1075
        // 配送料無料条件(合計金額)
1076
        $this->setDeliveryFreeAmount($Order);
1077
1078
        // 配送料無料条件(合計数量)
1079
        $this->setDeliveryFreeQuantity($Order);
1080
1081
        return $Order;
1082
    }
1083
1084
    /**
1085
     * 購入処理を行う
1086
     *
1087
     * @param Order $Order
1088
     *
1089
     * @deprecated PurchaseFlow::purchase() を使用してください
1090
     */
1091
    public function processPurchase(Order $Order)
1092
    {
1093
        // 受注情報、配送情報を更新
1094
        $Order = $this->calculateDeliveryFee($Order);
1095
        $this->setOrderUpdateData($Order);
1096
1097
        if ($this->authorizationChecker->isGranted('ROLE_USER')) {
1098
            $this->setCustomerUpdate($Order, $Order->getCustomer());
1099
        }
1100
    }
1101
1102
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$discount" missing
Loading history...
1103
     * 値引き可能かチェック
1104
     *
1105
     * @param Order $Order
0 ignored issues
show
introduced by
Expected 4 spaces after parameter type; 1 found
Loading history...
1106
     * @param       $discount
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
1107
     *
1108
     * @return bool
1109
     */
1110
    public function isDiscount(Order $Order, $discount)
1111
    {
1112
        if ($Order->getTotal() < $discount) {
1113
            return false;
1114
        }
1115
1116
        return true;
1117
    }
1118
1119
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$discount" missing
Loading history...
1120
     * 値引き金額をセット
1121
     *
1122
     * @param Order $Order
0 ignored issues
show
introduced by
Expected 4 spaces after parameter type; 1 found
Loading history...
1123
     * @param $discount
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
1124
     */
1125
    public function setDiscount(Order $Order, $discount)
1126
    {
1127
        $Order->setDiscount($Order->getDiscount() + $discount);
1128
    }
1129
1130
    /**
1131
     * 合計金額を計算
1132
     *
1133
     * @param Order $Order
1134
     *
1135
     * @return Order
1136
     */
1137
    public function calculatePrice(Order $Order)
1138
    {
1139
        $total = $Order->getTotalPrice();
1140
1141
        if ($total < 0) {
1142
            // 合計金額がマイナスの場合、0を設定し、discountは値引きされた額のみセット
1143
            $total = 0;
1144
        }
1145
1146
        $Order->setTotal($total);
1147
        $Order->setPaymentTotal($total);
1148
1149
        return $Order;
1150
    }
1151
1152
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$status" missing
Loading history...
1153
     * 受注ステータスをセット
1154
     *
1155
     * @param Order $Order
0 ignored issues
show
introduced by
Expected 2 spaces after parameter type; 1 found
Loading history...
1156
     * @param $status
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
1157
     *
1158
     * @return Order
1159
     */
1160 6
    public function setOrderStatus(Order $Order, $status)
1161
    {
1162 6
        $Order->setOrderDate(new \DateTime());
1163 6
        $Order->setOrderStatus($this->orderStatusRepository->find($status));
1164
1165 6
        $event = new EventArgs(
1166
            [
1167 6
                'Order' => $Order,
1168
            ],
1169 6
            null
1170
        );
1171 6
        $this->eventDispatcher->dispatch(EccubeEvents::SERVICE_SHOPPING_ORDER_STATUS, $event);
1172
1173 6
        return $Order;
1174
    }
1175
1176
    /**
1177
     * 受注メール送信を行う
1178
     *
1179
     * @param Order $Order
1180
     *
1181
     * @return MailHistory
1182
     */
1183 6
    public function sendOrderMail(Order $Order)
1184
    {
1185
        // メール送信
1186 6
        $message = $this->mailService->sendOrderMail($Order);
1187
1188
        // 送信履歴を保存.
1189 6
        $MailHistory = new MailHistory();
1190
        $MailHistory
1191 6
            ->setMailSubject($message->getSubject())
1192 6
            ->setMailBody($message->getBody())
1193 6
            ->setSendDate(new \DateTime())
1194 6
            ->setOrder($Order);
1195
1196 6
        $this->entityManager->persist($MailHistory);
1197 6
        $this->entityManager->flush($MailHistory);
1198
1199 6
        return $MailHistory;
1200
    }
1201
1202
    /**
1203
     * 受注処理完了通知
1204
     *
1205
     * @param Order $Order
1206
     */
1207
    public function notifyComplete(Order $Order)
1208
    {
1209
        $event = new EventArgs(
1210
            [
1211
                'Order' => $Order,
1212
            ],
1213
            null
1214
        );
1215
        $this->eventDispatcher->dispatch(EccubeEvents::SERVICE_SHOPPING_NOTIFY_COMPLETE, $event);
1216
    }
1217
1218
    /**
1219
     * Filter deliveries match to multi shipping
1220
     *
1221
     * @param array $Deliveries
1222
     * @param Order $Order
1223
     *
1224
     * @return array
1225
     */
1226 50
    public function filterDeliveries(array $Deliveries, Order $Order = null)
1227
    {
1228 50
        if (empty($Deliveries)) {
1229
            return [];
1230
        }
1231
1232 50
        $Payments = $this->paymentRepository->findAllowedPayments($Deliveries, true, $Order);
1233
1234 50
        if (count($Payments) == 0) {
1235
            array_pop($Deliveries);
1236
1237
            return $this->filterDeliveries($Deliveries, $Order);
1238
        }
1239
1240 50
        return $Deliveries;
1241
    }
1242
}
1243