Failed Conditions
Pull Request — experimental/sf (#3225)
by Kentaro
58:20 queued 49:13
created

ShoppingService::getNonMember()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

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