Failed Conditions
Pull Request — experimental/sf (#3241)
by k-yamamura
43:19 queued 23:09
created

ShoppingService   F

Complexity

Total Complexity 92

Size/Duplication

Total Lines 1197
Duplicated Lines 10.03 %

Coupling/Cohesion

Components 4
Dependencies 23

Test Coverage

Coverage 18.92%

Importance

Changes 0
Metric Value
dl 120
loc 1197
rs 0.812
c 0
b 0
f 0
ccs 77
cts 407
cp 0.1892
wmc 92
lcom 4
cbo 23

38 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 45 1
A getOrder() 0 22 3
A getNonMember() 0 9 2
A createOrder() 7 21 2
B registerPreOrder() 0 64 3
A getNewOrder() 0 7 1
A newOrder() 0 7 1
A copyToOrderFromCustomer() 0 27 3
A getDeliveriesCart() 0 7 1
A getDeliveriesOrder() 0 7 1
A getDeliveries() 0 15 2
A getNewShipping() 0 25 3
A copyToShippingFromCustomer() 0 40 3
A getNewDetails() 0 18 2
B getNewOrderItem() 0 57 7
A getShippingDeliveryFeeTotal() 0 9 2
A getProductDeliveryFee() 0 11 2
A getAmount() 0 20 1
A setShippingDeliveryFee() 0 21 4
A setDeliveryFreeAmount() 16 16 4
A setDeliveryFreeQuantity() 16 16 4
A setOrderUpdate() 0 33 4
A setOrderUpdateData() 0 7 1
A setCustomerUpdate() 0 13 2
A getPayments() 0 17 6
B getFormDeliveryDurations() 31 46 8
A getFormPayments() 0 15 2
A getShippingForm() 25 25 1
A getShippingFormBuilder() 23 23 1
A setFormData() 0 19 4
A calculateDeliveryFee() 0 17 1
A processPurchase() 0 10 2
A isDiscount() 0 8 2
A setDiscount() 0 4 1
A calculatePrice() 0 14 2
A setOrderStatus() 0 15 1
A sendOrderMail() 0 18 1
A notifyComplete() 0 10 1

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like ShoppingService often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use ShoppingService, and based on these observations, apply Extract Interface, too.

1
<?php
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
     * ShoppingService constructor.
167
     *
168
     * @param MailTemplateRepository $mailTemplateRepository
0 ignored issues
show
introduced by
Expected 8 spaces after parameter type; 1 found
Loading history...
169
     * @param MailService $mailService
0 ignored issues
show
introduced by
Expected 19 spaces after parameter type; 1 found
Loading history...
170
     * @param EventDispatcher $eventDispatcher
0 ignored issues
show
introduced by
Expected 15 spaces after parameter type; 1 found
Loading history...
171
     * @param FormFactory $formFactory
0 ignored issues
show
introduced by
Expected 19 spaces after parameter type; 1 found
Loading history...
172
     * @param DeliveryFeeRepository $deliveryFeeRepository
0 ignored issues
show
introduced by
Expected 9 spaces after parameter type; 1 found
Loading history...
173
     * @param TaxRuleRepository $taxRuleRepository
0 ignored issues
show
introduced by
Expected 13 spaces after parameter type; 1 found
Loading history...
174
     * @param CustomerAddressRepository $customerAddressRepository
0 ignored issues
show
introduced by
Expected 5 spaces after parameter type; 1 found
Loading history...
175
     * @param DeliveryRepository $deliveryRepository
0 ignored issues
show
introduced by
Expected 12 spaces after parameter type; 1 found
Loading history...
176
     * @param DeliveryTimeRepository $deliveryTimeRepository
0 ignored issues
show
introduced by
Expected 8 spaces after parameter type; 1 found
Loading history...
177
     * @param OrderStatusRepository $orderStatusRepository
0 ignored issues
show
introduced by
Expected 9 spaces after parameter type; 1 found
Loading history...
178
     * @param PaymentRepository $paymentRepository
0 ignored issues
show
introduced by
Expected 13 spaces after parameter type; 1 found
Loading history...
179
     * @param DeviceTypeRepository $deviceTypeRepository
0 ignored issues
show
introduced by
Expected 10 spaces after parameter type; 1 found
Loading history...
180
     * @param EntityManager $entityManager
0 ignored issues
show
introduced by
Expected 17 spaces after parameter type; 1 found
Loading history...
181
     * @param EccubeConfig $eccubeConfig
0 ignored issues
show
introduced by
Expected 18 spaces after parameter type; 1 found
Loading history...
182
     * @param PrefRepository $prefRepository
0 ignored issues
show
introduced by
Expected 16 spaces after parameter type; 1 found
Loading history...
183
     * @param Session $session
0 ignored issues
show
introduced by
Expected 23 spaces after parameter type; 1 found
Loading history...
184
     * @param OrderRepository $orderRepository
0 ignored issues
show
introduced by
Expected 15 spaces after parameter type; 1 found
Loading history...
185
     * @param CartService $cartService
0 ignored issues
show
introduced by
Expected 19 spaces after parameter type; 1 found
Loading history...
186
     * @param OrderService $orderService
0 ignored issues
show
introduced by
Expected 18 spaces after parameter type; 1 found
Loading history...
187
     * @param BaseInfo $BaseInfo
0 ignored issues
show
introduced by
Expected 22 spaces after parameter type; 1 found
Loading history...
188
     * @param AuthorizationCheckerInterface $authorizationChecker
189
     */
190 59
    public function __construct(
191
        MailTemplateRepository $mailTemplateRepository,
192
        MailService $mailService,
193
        EventDispatcherInterface $eventDispatcher,
194
        FormFactoryInterface $formFactory,
195
        DeliveryFeeRepository $deliveryFeeRepository,
196
        TaxRuleRepository $taxRuleRepository,
197
        CustomerAddressRepository $customerAddressRepository,
198
        DeliveryRepository $deliveryRepository,
199
        DeliveryTimeRepository $deliveryTimeRepository,
200
        OrderStatusRepository $orderStatusRepository,
201
        PaymentRepository $paymentRepository,
202
        DeviceTypeRepository $deviceTypeRepository,
203
        EntityManagerInterface $entityManager,
204
        EccubeConfig $eccubeConfig,
205
        PrefRepository $prefRepository,
206
        SessionInterface $session,
207
        OrderRepository $orderRepository,
208
        CartService $cartService,
209
        OrderService $orderService,
210
        BaseInfo $BaseInfo,
211
        AuthorizationCheckerInterface $authorizationChecker
212
    ) {
213 59
        $this->mailTemplateRepository = $mailTemplateRepository;
214 59
        $this->mailService = $mailService;
215 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...
216 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...
217 59
        $this->deliveryFeeRepository = $deliveryFeeRepository;
218 59
        $this->taxRuleRepository = $taxRuleRepository;
219 59
        $this->customerAddressRepository = $customerAddressRepository;
220 59
        $this->deliveryRepository = $deliveryRepository;
221 59
        $this->deliveryTimeRepository = $deliveryTimeRepository;
222 59
        $this->orderStatusRepository = $orderStatusRepository;
223 59
        $this->paymentRepository = $paymentRepository;
224 59
        $this->deviceTypeRepository = $deviceTypeRepository;
225 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...
226 59
        $this->eccubeConfig = $eccubeConfig;
227 59
        $this->prefRepository = $prefRepository;
228 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...
229 59
        $this->orderRepository = $orderRepository;
230 59
        $this->cartService = $cartService;
231 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...
232 59
        $this->BaseInfo = $BaseInfo;
233 59
        $this->authorizationChecker = $authorizationChecker;
234
    }
235
236
    /**
237
     * セッションにセットされた受注情報を取得
238
     *
239
     * @param null $status
240
     *
241
     * @return null|object
242
     */
243 51
    public function getOrder($status = null)
244
    {
245
        // 受注データを取得
246 51
        $preOrderId = $this->cartService->getPreOrderId();
247 51
        if (!$preOrderId) {
248 51
            return null;
249
        }
250
251
        $condition = [
252 40
            'pre_order_id' => $preOrderId,
253
        ];
254
255 40
        if (!is_null($status)) {
256
            $condition += [
257 40
                'OrderStatus' => $status,
258
            ];
259
        }
260
261 40
        $Order = $this->orderRepository->findOneBy($condition);
262
263 40
        return $Order;
264
    }
265
266
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$sesisonKey" missing
Loading history...
267
     * 非会員情報を取得
268
     *
269
     * @param $sesisonKey
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
270
     *
271
     * @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...
272
     */
273
    public function getNonMember($sesisonKey)
274
    {
275
        if ($NonMember = $this->session->get($sesisonKey)) {
276
            $Pref = $this->prefRepository->find($NonMember->getPref()->getId());
277
            $NonMember->setPref($Pref);
278
279
            return $NonMember;
280
        }
281
    }
282
283
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$Customer" missing
Loading history...
284
     * 受注情報を作成
285
     *
286
     * @param $Customer
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
287
     *
288
     * @return \Eccube\Entity\Order
289
     */
290
    public function createOrder($Customer)
291
    {
292
        // ランダムなpre_order_idを作成
293 View Code Duplication
        do {
294
            $preOrderId = sha1(StringUtil::random(32));
295
            $Order = $this->orderRepository->findOneBy([
296
                'pre_order_id' => $preOrderId,
297
                'OrderStatus' => OrderStatus::PROCESSING,
298
            ]);
299
        } while ($Order);
300
301
        // 受注情報、受注明細情報、お届け先情報、配送商品情報を作成
302
        $Order = $this->registerPreOrder(
303
            $Customer,
304
            $preOrderId);
305
306
        $this->cartService->setPreOrderId($preOrderId);
307
        $this->cartService->save();
308
309
        return $Order;
310
    }
311
312
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$Customer" missing
Loading history...
introduced by
Doc comment for parameter "$preOrderId" missing
Loading history...
313
     * 仮受注情報作成
314
     *
315
     * @param $Customer
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
316
     * @param $preOrderId
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
317
     *
318
     * @return mixed
319
     *
320
     * @throws \Doctrine\ORM\NoResultException
321
     * @throws \Doctrine\ORM\NonUniqueResultException
322
     */
323
    public function registerPreOrder(Customer $Customer, $preOrderId)
324
    {
325
        $this->em = $this->entityManager;
326
327
        // 受注情報を作成
328
        $Order = $this->getNewOrder($Customer);
329
        $Order->setPreOrderId($preOrderId);
330
331
        $mobileDetect = new \Mobile_Detect();
332
        $DeviceType = $this->deviceTypeRepository->find($mobileDetect->isMobile() ? DeviceType::DEVICE_TYPE_SP : DeviceType::DEVICE_TYPE_PC);
333
        $Order->setDeviceType($DeviceType);
334
335
        $this->entityManager->persist($Order);
336
337
        // 配送業者情報を取得
338
        $deliveries = $this->getDeliveriesCart();
339
340
        // お届け先情報を作成
341
        $Order = $this->getNewShipping($Order, $Customer, $deliveries);
342
343
        // 受注明細情報、配送商品情報を作成
344
        $Order = $this->getNewDetails($Order);
345
346
        // 小計
347
        $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...
348
349
        // 消費税のみの小計
350
        $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...
351
352
        // 配送料合計金額
353
        // TODO CalculateDeliveryFeeStrategy でセットする
354
        // $Order->setDeliveryFeeTotal($this->getShippingDeliveryFeeTotal($Order->getShippings()));
355
356
        // 小計
357
        $Order->setSubTotal($subTotal);
358
359
        // 配送料無料条件(合計金額)
360
        $this->setDeliveryFreeAmount($Order);
361
362
        // 配送料無料条件(合計数量)
363
        $this->setDeliveryFreeQuantity($Order);
364
365
        // 初期選択の支払い方法をセット
366
        $payments = $this->paymentRepository->findAllowedPayments($deliveries);
367
        $payments = $this->getPayments($payments, $subTotal);
368
369
        if (count($payments) > 0) {
370
            $payment = $payments[0];
371
            $Order->setPayment($payment);
372
            $Order->setPaymentMethod($payment->getMethod());
373
            $Order->setCharge($payment->getCharge());
374
        } else {
375
            $Order->setCharge(0);
376
        }
377
378
        $Order->setTax($tax);
379
380
        // 合計金額の計算
381
        $this->calculatePrice($Order);
382
383
        $this->entityManager->flush();
384
385
        return $Order;
386
    }
387
388
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$Customer" missing
Loading history...
389
     * 受注情報を作成
390
     *
391
     * @param $Customer
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
392
     *
393
     * @return \Eccube\Entity\Order
394
     */
395
    public function getNewOrder(Customer $Customer)
396
    {
397
        $Order = $this->newOrder();
398
        $this->copyToOrderFromCustomer($Order, $Customer);
399
400
        return $Order;
401
    }
402
403
    /**
404
     * 受注情報を作成
405
     *
406
     * @return \Eccube\Entity\Order
407
     */
408
    public function newOrder()
409
    {
410
        $OrderStatus = $this->orderStatusRepository->find(OrderStatus::PROCESSING);
411
        $Order = new \Eccube\Entity\Order($OrderStatus);
412
413
        return $Order;
414
    }
415
416
    /**
417
     * 受注情報を作成
418
     *
419
     * @param \Eccube\Entity\Order $Order
0 ignored issues
show
introduced by
Expected 9 spaces after parameter type; 1 found
Loading history...
420
     * @param \Eccube\Entity\Customer|null $Customer
421
     *
422
     * @return \Eccube\Entity\Order
423
     */
424
    public function copyToOrderFromCustomer(Order $Order, Customer $Customer = null)
425
    {
426
        if (is_null($Customer)) {
427
            return $Order;
428
        }
429
430
        if ($Customer->getId()) {
431
            $Order->setCustomer($Customer);
432
        }
433
        $Order
434
            ->setName01($Customer->getName01())
435
            ->setName02($Customer->getName02())
436
            ->setKana01($Customer->getKana01())
437
            ->setKana02($Customer->getKana02())
438
            ->setCompanyName($Customer->getCompanyName())
439
            ->setEmail($Customer->getEmail())
440
            ->setPhoneNumber($Customer->getPhoneNumber())
441
            ->setPostalCode($Customer->getPostalCode())
442
            ->setPref($Customer->getPref())
443
            ->setAddr01($Customer->getAddr01())
444
            ->setAddr02($Customer->getAddr02())
445
            ->setSex($Customer->getSex())
446
            ->setBirth($Customer->getBirth())
447
            ->setJob($Customer->getJob());
448
449
        return $Order;
450
    }
451
452
    /**
453
     * 配送業者情報を取得
454
     *
455
     * @return array
456
     */
457
    public function getDeliveriesCart()
458
    {
459
        // カートに保持されている販売種別を取得
460
        $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...
461
462
        return $this->getDeliveries($saleTypes);
463
    }
464
465
    /**
466
     * 配送業者情報を取得
467
     *
468
     * @param Order $Order
469
     *
470
     * @return array
471
     */
472
    public function getDeliveriesOrder(Order $Order)
473
    {
474
        // 受注情報から販売種別を取得
475
        $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...
476
477
        return $this->getDeliveries($saleTypes);
478
    }
479
480
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$saleTypes" missing
Loading history...
481
     * 配送業者情報を取得
482
     *
483
     * @param $saleTypes
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
484
     *
485
     * @return array
486
     */
487
    public function getDeliveries($saleTypes)
488
    {
489
        // 販売種別に紐づく配送業者を取得
490
        $deliveries = $this->deliveryRepository->getDeliveries($saleTypes);
491
492
        // 支払方法を取得
493
        $payments = $this->paymentRepository->findAllowedPayments($deliveries);
494
495
        if (count($saleTypes) > 1) {
496
            // 販売種別が複数ある場合、配送対象となる配送業者を取得
497
            $deliveries = $this->deliveryRepository->findAllowedDeliveries($saleTypes, $payments);
498
        }
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 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...
781
    {
782
        // 配送料無料条件(合計金額)
783 6
        $deliveryFreeAmount = $this->BaseInfo->getDeliveryFreeAmount();
784 6
        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 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...
803
    {
804
        // 配送料無料条件(合計数量)
805 6
        $deliveryFreeQuantity = $this->BaseInfo->getDeliveryFreeQuantity();
806 6
        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 3
    public function setCustomerUpdate(Order $Order, Customer $user)
881
    {
882
        // 顧客情報を更新
883 3
        $now = new \DateTime();
884 3
        $firstBuyDate = $user->getFirstBuyDate();
885 3
        if (empty($firstBuyDate)) {
886 3
            $user->setFirstBuyDate($now);
887
        }
888 3
        $user->setLastBuyDate($now);
889
890 3
        $user->setBuyTimes($user->getBuyTimes() + 1);
891 3
        $user->setBuyTotal($user->getBuyTotal() + $Order->getTotal());
892
    }
893
894
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$payments" missing
Loading history...
introduced by
Doc comment for parameter "$subTotal" missing
Loading history...
895
     * 支払方法選択の表示設定
896
     *
897
     * @param $payments 支払選択肢情報
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
898
     * @param $subTotal 小計
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
899
     *
900
     * @return array
901
     */
902
    public function getPayments($payments, $subTotal)
903
    {
904
        $pays = [];
905
        foreach ($payments as $payment) {
906
            // 支払方法の制限値内であれば表示
907
            if (!is_null($payment)) {
908
                $pay = $this->paymentRepository->find($payment['id']);
909
                if (intval($pay->getRuleMin()) <= $subTotal) {
910
                    if (is_null($pay->getRuleMax()) || $pay->getRuleMax() >= $subTotal) {
911
                        $pays[] = $pay;
912
                    }
913
                }
914
            }
915
        }
916
917
        return $pays;
918
    }
919
920
    /**
921
     * お届け日を取得
922
     *
923
     * @param Order $Order
924
     *
925
     * @return array
926
     */
927
    public function getFormDeliveryDurations(Order $Order)
928
    {
929
        // お届け日の設定
930
        $minDate = 0;
931
        $deliveryDurationFlag = false;
932
933
        // 配送時に最大となる商品日数を取得
934 View Code Duplication
        foreach ($Order->getOrderItems() as $item) {
935
            if (!$item->isProduct()) {
936
                continue;
937
            }
938
            $ProductClass = $item->getProductClass();
939
            $deliveryDuration = $ProductClass->getDeliveryDuration();
940
            if (!is_null($deliveryDuration)) {
941
                if ($deliveryDuration->getDuration() < 0) {
942
                    // 配送日数がマイナスの場合はお取り寄せなのでスキップする
943
                    $deliveryDurationFlag = false;
944
                    break;
945
                }
946
947
                if ($minDate < $deliveryDuration->getDuration()) {
948
                    $minDate = $deliveryDuration->getDuration();
949
                }
950
                // 配送日数が設定されている
951
                $deliveryDurationFlag = true;
952
            }
953
        }
954
955
        // 配達最大日数期間を設定
956
        $deliveryDurations = [];
957
958
        // 配送日数が設定されている
959 View Code Duplication
        if ($deliveryDurationFlag) {
960
            $period = new \DatePeriod(
961
                new \DateTime($minDate.' day'),
962
                new \DateInterval('P1D'),
963
                new \DateTime($minDate + $this->eccubeConfig['eccube_deliv_date_end_max'].' day')
964
            );
965
966
            foreach ($period as $day) {
967
                $deliveryDurations[$day->format('Y/m/d')] = $day->format('Y/m/d');
968
            }
969
        }
970
971
        return $deliveryDurations;
972
    }
973
974
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$deliveries" missing
Loading history...
975
     * 支払方法を取得
976
     *
977
     * @param $deliveries
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
978
     * @param Order $Order
0 ignored issues
show
introduced by
Expected 6 spaces after parameter type; 1 found
Loading history...
979
     *
980
     * @return array
981
     */
982
    public function getFormPayments($deliveries, Order $Order)
983
    {
984
        $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...
985
        if (count($saleTypes) > 1) {
986
            $payments = $this->paymentRepository->findAllowedPayments($deliveries);
987
        } else {
988
            // 配送業者をセット
989
            $shippings = $Order->getShippings();
990
            $Shipping = $shippings[0];
991
            $payments = $this->paymentRepository->findPayments($Shipping->getDelivery(), true);
992
        }
993
        $payments = $this->getPayments($payments, $Order->getSubTotal());
994
995
        return $payments;
996
    }
997
998
    /**
999
     * お届け先ごとにFormを作成
1000
     *
1001
     * @param Order $Order
1002
     *
1003
     * @return \Symfony\Component\Form\Form
1004
     *
1005
     * @deprecated since 3.0, to be removed in 3.1
1006
     */
1007 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...
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
        $form = $builder->getForm();
1029
1030
        return $form;
1031
    }
1032
1033
    /**
1034
     * お届け先ごとにFormBuilderを作成
1035
     *
1036
     * @param Order $Order
1037
     *
1038
     * @return \Symfony\Component\Form\FormBuilderInterface
1039
     *
1040
     * @deprecated 利用している箇所なし
1041
     */
1042 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...
1043
    {
1044
        $message = $Order->getMessage();
1045
1046
        $deliveries = $this->getDeliveriesOrder($Order);
1047
1048
        // 配送業者の支払方法を取得
1049
        $payments = $this->getFormPayments($deliveries, $Order);
1050
1051
        $builder = $this->formFactory->createBuilder('shopping', null, [
1052
            'payments' => $payments,
1053
            'payment' => $Order->getPayment(),
1054
            'message' => $message,
1055
        ]);
1056
1057
        $builder
1058
            ->add('shippings', CollectionType::class, [
1059
                'entry_type' => ShippingItemType::class,
1060
                'data' => $Order->getShippings(),
1061
            ]);
1062
1063
        return $builder;
1064
    }
1065
1066
    /**
1067
     * フォームデータを更新
1068
     *
1069
     * @param Order $Order
1070
     * @param array $data
1071
     *
1072
     * @deprecated
1073
     */
1074
    public function setFormData(Order $Order, array $data)
1075
    {
1076
        // お問い合わせ
1077
        $Order->setMessage($data['message']);
1078
1079
        // お届け先情報を更新
1080
        $shippings = $data['shippings'];
1081
        foreach ($shippings as $Shipping) {
1082
            $timeId = $Shipping->getTimeId();
1083
            $deliveryTime = null;
1084
            if ($timeId) {
1085
                $deliveryTime = $this->deliveryTimeRepository->find($timeId);
1086
            }
1087
            if ($deliveryTime) {
1088
                $Shipping->setShippingDeliveryTime($deliveryTime->getDeliveryTime());
1089
                $Shipping->setTimeId($timeId);
1090
            }
1091
        }
1092
    }
1093
1094
    /**
1095
     * 配送料の合計金額を計算
1096
     *
1097
     * @param Order $Order
1098
     *
1099
     * @return Order
1100
     */
1101 6
    public function calculateDeliveryFee(Order $Order)
1102
    {
1103
        // 配送業者を取得
1104 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...
1105
1106
        // 配送料合計金額
1107
        // TODO CalculateDeliveryFeeStrategy でセットする
1108
        // $Order->setDeliveryFeeTotal($this->getShippingDeliveryFeeTotal($shippings));
1109
1110
        // 配送料無料条件(合計金額)
1111 6
        $this->setDeliveryFreeAmount($Order);
1112
1113
        // 配送料無料条件(合計数量)
1114 6
        $this->setDeliveryFreeQuantity($Order);
1115
1116 6
        return $Order;
1117
    }
1118
1119
    /**
1120
     * 購入処理を行う
1121
     *
1122
     * @param Order $Order
1123
     *
1124
     * @deprecated PurchaseFlow::purchase() を使用してください
1125
     */
1126 6
    public function processPurchase(Order $Order)
1127
    {
1128
        // 受注情報、配送情報を更新
1129 6
        $Order = $this->calculateDeliveryFee($Order);
1130 6
        $this->setOrderUpdateData($Order);
1131
1132 6
        if ($this->authorizationChecker->isGranted('ROLE_USER')) {
1133 3
            $this->setCustomerUpdate($Order, $Order->getCustomer());
1134
        }
1135
    }
1136
1137
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$discount" missing
Loading history...
1138
     * 値引き可能かチェック
1139
     *
1140
     * @param Order $Order
0 ignored issues
show
introduced by
Expected 4 spaces after parameter type; 1 found
Loading history...
1141
     * @param       $discount
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
1142
     *
1143
     * @return bool
1144
     */
1145
    public function isDiscount(Order $Order, $discount)
1146
    {
1147
        if ($Order->getTotal() < $discount) {
1148
            return false;
1149
        }
1150
1151
        return true;
1152
    }
1153
1154
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$discount" missing
Loading history...
1155
     * 値引き金額をセット
1156
     *
1157
     * @param Order $Order
0 ignored issues
show
introduced by
Expected 4 spaces after parameter type; 1 found
Loading history...
1158
     * @param $discount
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
1159
     */
1160
    public function setDiscount(Order $Order, $discount)
1161
    {
1162
        $Order->setDiscount($Order->getDiscount() + $discount);
1163
    }
1164
1165
    /**
1166
     * 合計金額を計算
1167
     *
1168
     * @param Order $Order
1169
     *
1170
     * @return Order
1171
     */
1172
    public function calculatePrice(Order $Order)
1173
    {
1174
        $total = $Order->getTotalPrice();
1175
1176
        if ($total < 0) {
1177
            // 合計金額がマイナスの場合、0を設定し、discountは値引きされた額のみセット
1178
            $total = 0;
1179
        }
1180
1181
        $Order->setTotal($total);
1182
        $Order->setPaymentTotal($total);
1183
1184
        return $Order;
1185
    }
1186
1187
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$status" missing
Loading history...
1188
     * 受注ステータスをセット
1189
     *
1190
     * @param Order $Order
0 ignored issues
show
introduced by
Expected 2 spaces after parameter type; 1 found
Loading history...
1191
     * @param $status
0 ignored issues
show
introduced by
Missing parameter name
Loading history...
1192
     *
1193
     * @return Order
1194
     */
1195 6
    public function setOrderStatus(Order $Order, $status)
1196
    {
1197 6
        $Order->setOrderDate(new \DateTime());
1198 6
        $Order->setOrderStatus($this->orderStatusRepository->find($status));
1199
1200 6
        $event = new EventArgs(
1201
            [
1202 6
                'Order' => $Order,
1203
            ],
1204 6
            null
1205
        );
1206 6
        $this->eventDispatcher->dispatch(EccubeEvents::SERVICE_SHOPPING_ORDER_STATUS, $event);
1207
1208 6
        return $Order;
1209
    }
1210
1211
    /**
1212
     * 受注メール送信を行う
1213
     *
1214
     * @param Order $Order
1215
     *
1216
     * @return MailHistory
1217
     */
1218 6
    public function sendOrderMail(Order $Order)
1219
    {
1220
        // メール送信
1221 6
        $message = $this->mailService->sendOrderMail($Order);
1222
1223
        // 送信履歴を保存.
1224 6
        $MailHistory = new MailHistory();
1225
        $MailHistory
1226 6
            ->setMailSubject($message->getSubject())
1227 6
            ->setMailBody($message->getBody())
1228 6
            ->setSendDate(new \DateTime())
1229 6
            ->setOrder($Order);
1230
1231 6
        $this->entityManager->persist($MailHistory);
1232 6
        $this->entityManager->flush($MailHistory);
1233
1234 6
        return $MailHistory;
1235
    }
1236
1237
    /**
1238
     * 受注処理完了通知
1239
     *
1240
     * @param Order $Order
1241
     */
1242
    public function notifyComplete(Order $Order)
1243
    {
1244
        $event = new EventArgs(
1245
            [
1246
                'Order' => $Order,
1247
            ],
1248
            null
1249
        );
1250
        $this->eventDispatcher->dispatch(EccubeEvents::SERVICE_SHOPPING_NOTIFY_COMPLETE, $event);
1251
    }
1252
}
1253