Failed Conditions
Pull Request — experimental/sf (#29)
by Kentaro
50:12 queued 39:05
created

Order::setPaymentDate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 6
rs 10
c 0
b 0
f 0
ccs 3
cts 3
cp 1
crap 1
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\Entity;
15
16
use Doctrine\Common\Collections\ArrayCollection;
17
use Doctrine\Common\Collections\Criteria;
18
use Doctrine\ORM\Mapping as ORM;
19
use Eccube\Service\Calculator\OrderItemCollection;
20
use Eccube\Service\PurchaseFlow\ItemCollection;
21
22
/**
23
 * Order
24
 *
25
 * @ORM\Table(name="dtb_order", indexes={
26
 *     @ORM\Index(name="dtb_order_pre_order_id_idx", columns={"pre_order_id"}),
27
 *     @ORM\Index(name="dtb_order_email_idx", columns={"email"}),
28
 *     @ORM\Index(name="dtb_order_order_date_idx", columns={"order_date"}),
29
 *     @ORM\Index(name="dtb_order_payment_date_idx", columns={"payment_date"}),
30
 *     @ORM\Index(name="dtb_order_update_date_idx", columns={"update_date"}),
31
 *     @ORM\Index(name="dtb_order_order_no_idx", columns={"order_no"})
32
 *  })
33
 * @ORM\InheritanceType("SINGLE_TABLE")
34
 * @ORM\DiscriminatorColumn(name="discriminator_type", type="string", length=255)
35
 * @ORM\HasLifecycleCallbacks()
36
 * @ORM\Entity(repositoryClass="Eccube\Repository\OrderRepository")
37
 */
38
class Order extends \Eccube\Entity\AbstractEntity implements PurchaseInterface, ItemHolderInterface
39
{
40
    use NameTrait, PointTrait;
41
42
    /**
43
     * 複数配送かどうかの判定を行う.
44
     *
45
     * @return boolean
46
     */
47 65
    public function isMultiple()
48
    {
49 65
        $Shippings = [];
50
        // クエリビルダ使用時に絞り込まれる場合があるため,
51
        // getShippingsではなくOrderItem経由でShippingを取得する.
52 65
        foreach ($this->getOrderItems() as $OrderItem) {
53 64
            if ($Shipping = $OrderItem->getShipping()) {
54 62
                $id = $Shipping->getId();
55 62
                if (isset($Shippings[$id])) {
56 62
                    continue;
57
                }
58 64
                $Shippings[$id] = $Shipping;
59
            }
60
        }
61
62 65
        return count($Shippings) > 1 ? true : false;
63
    }
64
65
    /**
66
     * 対象となるお届け先情報を取得
67
     *
68
     * @param integer $shippingId
69
     *
70
     * @return \Eccube\Entity\Shipping|null
71
     */
72
    public function findShipping($shippingId)
73
    {
74
        foreach ($this->getShippings() as $Shipping) {
75
            if ($Shipping->getId() == $shippingId) {
76
                return $Shipping;
77
            }
78
        }
79
80
        return null;
81
    }
82
83
    /**
84
     * この注文の保持する販売種別を取得します.
85
     *
86
     * @return \Eccube\Entity\Master\SaleType[] 一意な販売種別の配列
87
     */
88 1
    public function getSaleTypes()
89
    {
90 1
        $saleTypes = [];
91 1
        foreach ($this->getOrderItems() as $OrderItem) {
92
            /* @var $ProductClass \Eccube\Entity\ProductClass */
93 1
            $ProductClass = $OrderItem->getProductClass();
94 1
            if ($ProductClass) {
95 1
                $saleTypes[] = $ProductClass->getSaleType();
96
            }
97
        }
98
99 1
        return array_unique($saleTypes);
100
    }
101
102
    /**
103
     * 合計金額を計算
104
     *
105
     * @return string
106
     *
107
     * @deprecated
108
     */
109 1
    public function getTotalPrice()
110
    {
111 1
        @trigger_error('The '.__METHOD__.' method is deprecated.', E_USER_DEPRECATED);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
112
113 1
        return $this->getSubtotal() + $this->getCharge() + $this->getDeliveryFeeTotal() - $this->getDiscount();
114
//        return $this->getSubtotal() + $this->getCharge() - $this->getDiscount();
0 ignored issues
show
Unused Code Comprehensibility introduced by
57% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
115
    }
116
117
    /**
118
     * @var integer
119
     *
120
     * @ORM\Column(name="id", type="integer", options={"unsigned":true})
121
     * @ORM\Id
122
     * @ORM\GeneratedValue(strategy="IDENTITY")
123
     */
124
    private $id;
125
126
    /**
127
     * @var string|null
128
     *
129
     * @ORM\Column(name="pre_order_id", type="string", length=255, nullable=true)
130
     */
131
    private $pre_order_id;
132
133
    /**
134
     * @var string|null
135
     *
136
     * @ORM\Column(name="order_no", type="string", length=255, nullable=true)
137
     */
138
    private $order_no;
139
140
    /**
141
     * @var string|null
142
     *
143
     * @ORM\Column(name="message", type="string", length=4000, nullable=true)
144
     */
145
    private $message;
146
147
    /**
148
     * @var string|null
149
     *
150
     * @ORM\Column(name="name01", type="string", length=255, nullable=true)
151
     */
152
    private $name01;
153
154
    /**
155
     * @var string|null
156
     *
157
     * @ORM\Column(name="name02", type="string", length=255, nullable=true)
158
     */
159
    private $name02;
160
161
    /**
162
     * @var string|null
163
     *
164
     * @ORM\Column(name="kana01", type="string", length=255, nullable=true)
165
     */
166
    private $kana01;
167
168
    /**
169
     * @var string|null
170
     *
171
     * @ORM\Column(name="kana02", type="string", length=255, nullable=true)
172
     */
173
    private $kana02;
174
175
    /**
176
     * @var string|null
177
     *
178
     * @ORM\Column(name="company_name", type="string", length=255, nullable=true)
179
     */
180
    private $company_name;
181
182
    /**
183
     * @var string|null
184
     *
185
     * @ORM\Column(name="email", type="string", length=255, nullable=true)
186
     */
187
    private $email;
188
189
    /**
190
     * @var string|null
191
     *
192
     * @ORM\Column(name="phone_number", type="string", length=14, nullable=true)
193
     */
194
    private $phone_number;
195
196
    /**
197
     * @var string|null
198
     *
199
     * @ORM\Column(name="postal_code", type="string", length=8, nullable=true)
200
     */
201
    private $postal_code;
202
203
    /**
204
     * @var string|null
205
     *
206
     * @ORM\Column(name="addr01", type="string", length=255, nullable=true)
207
     */
208
    private $addr01;
209
210
    /**
211
     * @var string|null
212
     *
213
     * @ORM\Column(name="addr02", type="string", length=255, nullable=true)
214
     */
215
    private $addr02;
216
217
    /**
218
     * @var \DateTime|null
219
     *
220
     * @ORM\Column(name="birth", type="datetimetz", nullable=true)
221
     */
222
    private $birth;
223
224
    /**
225
     * @var string
226
     *
227
     * @ORM\Column(name="subtotal", type="decimal", precision=12, scale=2, options={"unsigned":true,"default":0})
228
     */
229
    private $subtotal = 0;
230
231
    /**
232
     * @var string
233
     *
234
     * @ORM\Column(name="discount", type="decimal", precision=12, scale=2, options={"unsigned":true,"default":0})
235
     */
236
    private $discount = 0;
237
238
    /**
239
     * @var string
240
     *
241
     * @ORM\Column(name="delivery_fee_total", type="decimal", precision=12, scale=2, options={"unsigned":true,"default":0})
242
     */
243
    private $delivery_fee_total = 0;
244
245
    /**
246
     * @var string
247
     *
248
     * @ORM\Column(name="charge", type="decimal", precision=12, scale=2, options={"unsigned":true,"default":0})
249
     */
250
    private $charge = 0;
251
252
    /**
253
     * @var string
254
     *
255
     * @ORM\Column(name="tax", type="decimal", precision=12, scale=2, options={"unsigned":true,"default":0})
256
     */
257
    private $tax = 0;
258
259
    /**
260
     * @var string
261
     *
262
     * @ORM\Column(name="total", type="decimal", precision=12, scale=2, options={"unsigned":true,"default":0})
263
     */
264
    private $total = 0;
265
266
    /**
267
     * @var string
268
     *
269
     * @ORM\Column(name="payment_total", type="decimal", precision=12, scale=2, options={"unsigned":true,"default":0})
270
     */
271
    private $payment_total = 0;
272
273
    /**
274
     * @var string|null
275
     *
276
     * @ORM\Column(name="payment_method", type="string", length=255, nullable=true)
277
     */
278
    private $payment_method;
279
280
    /**
281
     * @var string|null
282
     *
283
     * @ORM\Column(name="note", type="string", length=4000, nullable=true)
284
     */
285
    private $note;
286
287
    /**
288
     * @var \DateTime
289
     *
290
     * @ORM\Column(name="create_date", type="datetimetz")
291
     */
292
    private $create_date;
293
294
    /**
295
     * @var \DateTime
296
     *
297
     * @ORM\Column(name="update_date", type="datetimetz")
298
     */
299
    private $update_date;
300
301
    /**
302
     * @var \DateTime|null
303
     *
304
     * @ORM\Column(name="order_date", type="datetimetz", nullable=true)
305
     */
306
    private $order_date;
307
308
    /**
309
     * @var \DateTime|null
310
     *
311
     * @ORM\Column(name="payment_date", type="datetimetz", nullable=true)
312
     */
313
    private $payment_date;
314
315
    /**
316
     * @var string|null
317
     *
318
     * @ORM\Column(name="currency_code", type="string", nullable=true)
319
     */
320
    private $currency_code;
321
322
    /**
323
     * 注文完了画面に表示するメッセージ
324
     *
325
     * プラグインから注文完了時にメッセージを表示したい場合, このフィールドにセットすることで, 注文完了画面で表示されます。
326
     * 複数のプラグインから利用されるため, appendCompleteMesssage()で追加してください.
327
     * 表示する際にHTMLは利用可能です。
328
     *
329
     * @var string|null
330
     *
331
     * @ORM\Column(name="complete_message", type="text", nullable=true)
332
     */
333
    private $complete_message;
334
335
    /**
336
     * 注文完了メールに表示するメッセージ
337
     *
338
     * プラグインから注文完了メールにメッセージを表示したい場合, このフィールドにセットすることで, 注文完了メールで表示されます。
339
     * 複数のプラグインから利用されるため, appendCompleteMailMesssage()で追加してください.
340
     *
341
     * @var string|null
342
     *
343
     * @ORM\Column(name="complete_mail_message", type="text", nullable=true)
344
     */
345
    private $complete_mail_message;
346
347
    /**
348
     * @var \Doctrine\Common\Collections\Collection|OrderItem[]
349
     *
350
     * @ORM\OneToMany(targetEntity="Eccube\Entity\OrderItem", mappedBy="Order", cascade={"persist","remove"})
351
     */
352
    private $OrderItems;
353
354
    /**
355
     * @var \Doctrine\Common\Collections\Collection|Shipping[]
356
     *
357
     * @ORM\OneToMany(targetEntity="Eccube\Entity\Shipping", mappedBy="Order", cascade={"persist","remove"})
358
     */
359
    private $Shippings;
360
361
    /**
362
     * @var \Doctrine\Common\Collections\Collection
363
     *
364
     * @ORM\OneToMany(targetEntity="Eccube\Entity\MailHistory", mappedBy="Order", cascade={"remove"})
365
     * @ORM\OrderBy({
366
     *     "send_date"="DESC"
367
     * })
368
     */
369
    private $MailHistories;
370
371
    /**
372
     * @var \Eccube\Entity\Customer
373
     *
374
     * @ORM\ManyToOne(targetEntity="Eccube\Entity\Customer", inversedBy="Orders")
375
     * @ORM\JoinColumns({
376
     *   @ORM\JoinColumn(name="customer_id", referencedColumnName="id")
377
     * })
378
     */
379
    private $Customer;
380
381
    /**
382
     * @var \Eccube\Entity\Master\Country
383
     *
384
     * @ORM\ManyToOne(targetEntity="Eccube\Entity\Master\Country")
385
     * @ORM\JoinColumns({
386
     *   @ORM\JoinColumn(name="country_id", referencedColumnName="id")
387
     * })
388
     */
389
    private $Country;
390
391
    /**
392
     * @var \Eccube\Entity\Master\Pref
393
     *
394
     * @ORM\ManyToOne(targetEntity="Eccube\Entity\Master\Pref")
395
     * @ORM\JoinColumns({
396
     *   @ORM\JoinColumn(name="pref_id", referencedColumnName="id")
397
     * })
398
     */
399
    private $Pref;
400
401
    /**
402
     * @var \Eccube\Entity\Master\Sex
403
     *
404
     * @ORM\ManyToOne(targetEntity="Eccube\Entity\Master\Sex")
405
     * @ORM\JoinColumns({
406
     *   @ORM\JoinColumn(name="sex_id", referencedColumnName="id")
407
     * })
408
     */
409
    private $Sex;
410
411
    /**
412
     * @var \Eccube\Entity\Master\Job
413
     *
414
     * @ORM\ManyToOne(targetEntity="Eccube\Entity\Master\Job")
415
     * @ORM\JoinColumns({
416
     *   @ORM\JoinColumn(name="job_id", referencedColumnName="id")
417
     * })
418
     */
419
    private $Job;
420
421
    /**
422
     * @var \Eccube\Entity\Payment
423
     *
424
     * @ORM\ManyToOne(targetEntity="Eccube\Entity\Payment")
425
     * @ORM\JoinColumns({
426
     *   @ORM\JoinColumn(name="payment_id", referencedColumnName="id")
427
     * })
428
     */
429
    private $Payment;
430
431
    /**
432
     * @var \Eccube\Entity\Master\DeviceType
433
     *
434
     * @ORM\ManyToOne(targetEntity="Eccube\Entity\Master\DeviceType")
435
     * @ORM\JoinColumns({
436
     *   @ORM\JoinColumn(name="device_type_id", referencedColumnName="id")
437
     * })
438
     */
439
    private $DeviceType;
440
441
    /**
442
     * @var \Eccube\Entity\Master\CustomerOrderStatus
443
     *
444
     * @ORM\ManyToOne(targetEntity="Eccube\Entity\Master\CustomerOrderStatus")
445
     * @ORM\JoinColumns({
446
     *   @ORM\JoinColumn(name="order_status_id", referencedColumnName="id")
447
     * })
448
     */
449
    private $CustomerOrderStatus;
450
451
    /**
452
     * @var \Eccube\Entity\Master\OrderStatus
453
     *
454
     * @ORM\ManyToOne(targetEntity="Eccube\Entity\Master\OrderStatus")
455
     * @ORM\JoinColumns({
456
     *   @ORM\JoinColumn(name="order_status_id", referencedColumnName="id")
457
     * })
458
     */
459
    private $OrderStatus;
460
461
    /**
462
     * Constructor
463
     */
464 315
    public function __construct(\Eccube\Entity\Master\OrderStatus $orderStatus = null)
465
    {
466 315
        $this->setDiscount(0)
467 315
            ->setSubtotal(0)
468 315
            ->setTotal(0)
469 315
            ->setPaymentTotal(0)
470 315
            ->setCharge(0)
471 315
            ->setTax(0)
472 315
            ->setDeliveryFeeTotal(0)
473 315
            ->setOrderStatus($orderStatus)
474
        ;
475
476 315
        $this->OrderItems = new \Doctrine\Common\Collections\ArrayCollection();
477 315
        $this->Shippings = new \Doctrine\Common\Collections\ArrayCollection();
478 315
        $this->MailHistories = new \Doctrine\Common\Collections\ArrayCollection();
479
    }
480
481
    /**
482
     * Clone
483
     */
484 7
    public function __clone()
485
    {
486 7
        $OrderItems = new ArrayCollection();
487 7
        foreach ($this->OrderItems as $OrderItem) {
488 4
            $OrderItems->add(clone $OrderItem);
489
        }
490 7
        $this->OrderItems = $OrderItems;
491
    }
492
493
    /**
494
     * Get id.
495
     *
496
     * @return int
497
     */
498 123
    public function getId()
499
    {
500 123
        return $this->id;
501
    }
502
503
    /**
504
     * Set preOrderId.
505
     *
506
     * @param string|null $preOrderId
507
     *
508
     * @return Order
509
     */
510 208
    public function setPreOrderId($preOrderId = null)
511
    {
512 208
        $this->pre_order_id = $preOrderId;
513
514 208
        return $this;
515
    }
516
517
    /**
518
     * Get preOrderId.
519
     *
520
     * @return string|null
521
     */
522 53
    public function getPreOrderId()
523
    {
524 53
        return $this->pre_order_id;
525
    }
526
527
    /**
528
     * Set orderNo
529
     *
530
     * @param string|null $orderNo
531
     *
532
     * @return Order
533
     */
534 230
    public function setOrderNo($orderNo = null)
535
    {
536 230
        $this->order_no = $orderNo;
537
538 230
        return $this;
539
    }
540
541
    /**
542
     * Get orderNo
543
     *
544
     * @return string|null
545
     */
546 97
    public function getOrderNo()
547
    {
548 97
        return $this->order_no;
549
    }
550
551
    /**
552
     * Set message.
553
     *
554
     * @param string|null $message
555
     *
556
     * @return Order
557
     */
558 184
    public function setMessage($message = null)
559
    {
560 184
        $this->message = $message;
561
562 184
        return $this;
563
    }
564
565
    /**
566
     * Get message.
567
     *
568
     * @return string|null
569
     */
570 81
    public function getMessage()
571
    {
572 81
        return $this->message;
573
    }
574
575
    /**
576
     * Set name01.
577
     *
578
     * @param string|null $name01
579
     *
580
     * @return Order
581
     */
582 18
    public function setName01($name01 = null)
583
    {
584 18
        $this->name01 = $name01;
585
586 18
        return $this;
587
    }
588
589
    /**
590
     * Get name01.
591
     *
592
     * @return string|null
593
     */
594 80
    public function getName01()
595
    {
596 80
        return $this->name01;
597
    }
598
599
    /**
600
     * Set name02.
601
     *
602
     * @param string|null $name02
603
     *
604
     * @return Order
605
     */
606 18
    public function setName02($name02 = null)
607
    {
608 18
        $this->name02 = $name02;
609
610 18
        return $this;
611
    }
612
613
    /**
614
     * Get name02.
615
     *
616
     * @return string|null
617
     */
618 80
    public function getName02()
619
    {
620 80
        return $this->name02;
621
    }
622
623
    /**
624
     * Set kana01.
625
     *
626
     * @param string|null $kana01
627
     *
628
     * @return Order
629
     */
630 19
    public function setKana01($kana01 = null)
631
    {
632 19
        $this->kana01 = $kana01;
633
634 19
        return $this;
635
    }
636
637
    /**
638
     * Get kana01.
639
     *
640
     * @return string|null
641
     */
642 70
    public function getKana01()
643
    {
644 70
        return $this->kana01;
645
    }
646
647
    /**
648
     * Set kana02.
649
     *
650
     * @param string|null $kana02
651
     *
652
     * @return Order
653
     */
654 19
    public function setKana02($kana02 = null)
655
    {
656 19
        $this->kana02 = $kana02;
657
658 19
        return $this;
659
    }
660
661
    /**
662
     * Get kana02.
663
     *
664
     * @return string|null
665
     */
666 70
    public function getKana02()
667
    {
668 70
        return $this->kana02;
669
    }
670
671
    /**
672
     * Set companyName.
673
     *
674
     * @param string|null $companyName
675
     *
676
     * @return Order
677
     */
678 16
    public function setCompanyName($companyName = null)
679
    {
680 16
        $this->company_name = $companyName;
681
682 16
        return $this;
683
    }
684
685
    /**
686
     * Get companyName.
687
     *
688
     * @return string|null
689
     */
690 71
    public function getCompanyName()
691
    {
692 71
        return $this->company_name;
693
    }
694
695
    /**
696
     * Set email.
697
     *
698
     * @param string|null $email
699
     *
700
     * @return Order
701
     */
702 16
    public function setEmail($email = null)
703
    {
704 16
        $this->email = $email;
705
706 16
        return $this;
707
    }
708
709
    /**
710
     * Get email.
711
     *
712
     * @return string|null
713
     */
714 74
    public function getEmail()
715
    {
716 74
        return $this->email;
717
    }
718
719
    /**
720
     * Set phone_number.
721
     *
722
     * @param string|null $phone_number
723
     *
724
     * @return Order
725
     */
726 17
    public function setPhoneNumber($phone_number = null)
727
    {
728 17
        $this->phone_number = $phone_number;
729
730 17
        return $this;
731
    }
732
733
    /**
734
     * Get phone_number.
735
     *
736
     * @return string|null
737
     */
738 70
    public function getPhoneNumber()
739
    {
740 70
        return $this->phone_number;
741
    }
742
743
    /**
744
     * Set postal_code.
745
     *
746
     * @param string|null $postal_code
747
     *
748
     * @return Order
749
     */
750 16
    public function setPostalCode($postal_code = null)
751
    {
752 16
        $this->postal_code = $postal_code;
753
754 16
        return $this;
755
    }
756
757
    /**
758
     * Get postal_code.
759
     *
760
     * @return string|null
761
     */
762 70
    public function getPostalCode()
763
    {
764 70
        return $this->postal_code;
765
    }
766
767
    /**
768
     * Set addr01.
769
     *
770
     * @param string|null $addr01
771
     *
772
     * @return Order
773
     */
774 16
    public function setAddr01($addr01 = null)
775
    {
776 16
        $this->addr01 = $addr01;
777
778 16
        return $this;
779
    }
780
781
    /**
782
     * Get addr01.
783
     *
784
     * @return string|null
785
     */
786 73
    public function getAddr01()
787
    {
788 73
        return $this->addr01;
789
    }
790
791
    /**
792
     * Set addr02.
793
     *
794
     * @param string|null $addr02
795
     *
796
     * @return Order
797
     */
798 16
    public function setAddr02($addr02 = null)
799
    {
800 16
        $this->addr02 = $addr02;
801
802 16
        return $this;
803
    }
804
805
    /**
806
     * Get addr02.
807
     *
808
     * @return string|null
809
     */
810 73
    public function getAddr02()
811
    {
812 73
        return $this->addr02;
813
    }
814
815
    /**
816
     * Set birth.
817
     *
818
     * @param \DateTime|null $birth
819
     *
820
     * @return Order
821
     */
822 5
    public function setBirth($birth = null)
823
    {
824 5
        $this->birth = $birth;
825
826 5
        return $this;
827
    }
828
829
    /**
830
     * Get birth.
831
     *
832
     * @return \DateTime|null
833
     */
834 3
    public function getBirth()
835
    {
836 3
        return $this->birth;
837
    }
838
839
    /**
840
     * Set subtotal.
841
     *
842
     * @param string $subtotal
843
     *
844
     * @return Order
845
     */
846 315
    public function setSubtotal($subtotal)
847
    {
848 315
        $this->subtotal = $subtotal;
849
850 315
        return $this;
851
    }
852
853
    /**
854
     * Get subtotal.
855
     *
856
     * @return string
857
     */
858 60
    public function getSubtotal()
859
    {
860 60
        return $this->subtotal;
861
    }
862
863
    /**
864
     * Set discount.
865
     *
866
     * @param string $discount
867
     *
868
     * @return Order
869
     */
870 315
    public function setDiscount($discount)
871
    {
872 315
        $this->discount = $discount;
873
874 315
        return $this;
875
    }
876
877
    /**
878
     * Get discount.
879
     *
880
     * @return string
881
     */
882 215
    public function getDiscount()
883
    {
884 215
        return $this->discount;
885
    }
886
887
    /**
888
     * Set deliveryFeeTotal.
889
     *
890
     * @param string $deliveryFeeTotal
891
     *
892
     * @return Order
893
     */
894 315
    public function setDeliveryFeeTotal($deliveryFeeTotal)
895
    {
896 315
        $this->delivery_fee_total = $deliveryFeeTotal;
897
898 315
        return $this;
899
    }
900
901
    /**
902
     * Get deliveryFeeTotal.
903
     *
904
     * @return string
905
     */
906 75
    public function getDeliveryFeeTotal()
907
    {
908 75
        return $this->delivery_fee_total;
909
    }
910
911
    /**
912
     * Set charge.
913
     *
914
     * @param string $charge
915
     *
916
     * @return Order
917
     */
918 315
    public function setCharge($charge)
919
    {
920 315
        $this->charge = $charge;
921
922 315
        return $this;
923
    }
924
925
    /**
926
     * Get charge.
927
     *
928
     * @return string
929
     */
930 215
    public function getCharge()
931
    {
932 215
        return $this->charge;
933
    }
934
935
    /**
936
     * Set tax.
937
     *
938
     * @param string $tax
939
     *
940
     * @return Order
941
     */
942 315
    public function setTax($tax)
943
    {
944 315
        $this->tax = $tax;
945
946 315
        return $this;
947
    }
948
949
    /**
950
     * Get tax.
951
     *
952
     * @return string
953
     */
954 16
    public function getTax()
955
    {
956 16
        return $this->tax;
957
    }
958
959
    /**
960
     * Set total.
961
     *
962
     * @param string $total
963
     *
964
     * @return Order
965
     */
966 315
    public function setTotal($total)
967
    {
968 315
        $this->total = $total;
969
970 315
        return $this;
971
    }
972
973
    /**
974
     * Get total.
975
     *
976
     * @return string
977
     */
978 223
    public function getTotal()
979
    {
980 223
        return $this->total;
981
    }
982
983
    /**
984
     * Set paymentTotal.
985
     *
986
     * @param string $paymentTotal
987
     *
988
     * @return Order
989
     */
990 315
    public function setPaymentTotal($paymentTotal)
991
    {
992 315
        $this->payment_total = $paymentTotal;
993
994 315
        return $this;
995
    }
996
997
    /**
998
     * Get paymentTotal.
999
     *
1000
     * @return string
1001
     */
1002 28
    public function getPaymentTotal()
1003
    {
1004 28
        return $this->payment_total;
1005
    }
1006
1007
    /**
1008
     * Set paymentMethod.
1009
     *
1010
     * @param string|null $paymentMethod
1011
     *
1012
     * @return Order
1013
     */
1014 221
    public function setPaymentMethod($paymentMethod = null)
1015
    {
1016 221
        $this->payment_method = $paymentMethod;
1017
1018 221
        return $this;
1019
    }
1020
1021
    /**
1022
     * Get paymentMethod.
1023
     *
1024
     * @return string|null
1025
     */
1026 20
    public function getPaymentMethod()
1027
    {
1028 20
        return $this->payment_method;
1029
    }
1030
1031
    /**
1032
     * Set note.
1033
     *
1034
     * @param string|null $note
1035
     *
1036
     * @return Order
1037
     */
1038 159
    public function setNote($note = null)
1039
    {
1040 159
        $this->note = $note;
1041
1042 159
        return $this;
1043
    }
1044
1045
    /**
1046
     * Get note.
1047
     *
1048
     * @return string|null
1049
     */
1050 20
    public function getNote()
1051
    {
1052 20
        return $this->note;
1053
    }
1054
1055
    /**
1056
     * Set createDate.
1057
     *
1058
     * @param \DateTime $createDate
1059
     *
1060
     * @return Order
1061
     */
1062 210
    public function setCreateDate($createDate)
1063
    {
1064 210
        $this->create_date = $createDate;
1065
1066 210
        return $this;
1067
    }
1068
1069
    /**
1070
     * Get createDate.
1071
     *
1072
     * @return \DateTime
1073
     */
1074 3
    public function getCreateDate()
1075
    {
1076 3
        return $this->create_date;
1077
    }
1078
1079
    /**
1080
     * Set updateDate.
1081
     *
1082
     * @param \DateTime $updateDate
1083
     *
1084
     * @return Order
1085
     */
1086 210
    public function setUpdateDate($updateDate)
1087
    {
1088 210
        $this->update_date = $updateDate;
1089
1090 210
        return $this;
1091
    }
1092
1093
    /**
1094
     * Get updateDate.
1095
     *
1096
     * @return \DateTime
1097
     */
1098 2
    public function getUpdateDate()
1099
    {
1100 2
        return $this->update_date;
1101
    }
1102
1103
    /**
1104
     * Set orderDate.
1105
     *
1106
     * @param \DateTime|null $orderDate
1107
     *
1108
     * @return Order
1109
     */
1110 47
    public function setOrderDate($orderDate = null)
1111
    {
1112 47
        $this->order_date = $orderDate;
1113
1114 47
        return $this;
1115
    }
1116
1117
    /**
1118
     * Get orderDate.
1119
     *
1120
     * @return \DateTime|null
1121
     */
1122 33
    public function getOrderDate()
1123
    {
1124 33
        return $this->order_date;
1125
    }
1126
1127
    /**
1128
     * Set paymentDate.
1129
     *
1130
     * @param \DateTime|null $paymentDate
1131
     *
1132
     * @return Order
1133
     */
1134 4
    public function setPaymentDate($paymentDate = null)
1135
    {
1136 4
        $this->payment_date = $paymentDate;
1137
1138 4
        return $this;
1139
    }
1140
1141
    /**
1142
     * Get paymentDate.
1143
     *
1144
     * @return \DateTime|null
1145
     */
1146 15
    public function getPaymentDate()
1147
    {
1148 15
        return $this->payment_date;
1149
    }
1150
1151
    /**
1152
     * Get currencyCode.
1153
     *
1154
     * @return string
1155
     */
1156
    public function getCurrencyCode()
1157
    {
1158
        return $this->currency_code;
1159
    }
1160
1161
    /**
1162
     * Set currencyCode.
1163
     *
1164
     * @param string|null $currencyCode
1165
     *
1166
     * @return $this
1167
     */
1168 210
    public function setCurrencyCode($currencyCode = null)
1169
    {
1170 210
        $this->currency_code = $currencyCode;
1171
1172 210
        return $this;
1173
    }
1174
1175
    /**
1176
     * @return null|string
1177
     */
1178 1
    public function getCompleteMessage()
1179
    {
1180 1
        return $this->complete_message;
1181
    }
1182
1183
    /**
1184
     * @param null|string $complete_message
1185
     *
1186
     * @return $this
1187
     */
1188
    public function setCompleteMessage($complete_message = null)
1189
    {
1190
        $this->complete_message = $complete_message;
1191
1192
        return $this;
1193
    }
1194
1195
    /**
1196
     * @param null|string $complete_message
1197
     *
1198
     * @return $this
1199
     */
1200
    public function appendCompleteMessage($complete_message = null)
1201
    {
1202
        $this->complete_message .= $complete_message;
1203
1204
        return $this;
1205
    }
1206
1207
    /**
1208
     * @return null|string
1209
     */
1210 11
    public function getCompleteMailMessage()
1211
    {
1212 11
        return $this->complete_mail_message;
1213
    }
1214
1215
    /**
1216
     * @param null|string $complete_mail_message
1217
     *
1218
     * @return
1219
     */
1220
    public function setCompleteMailMessage($complete_mail_message = null)
1221
    {
1222
        $this->complete_mail_message = $complete_mail_message;
1223
1224
        return $this;
1225
    }
1226
1227
    /**
1228
     * @param null|string $complete_mail_message
1229
     *
1230
     * @return
1231
     */
1232
    public function appendCompleteMailMessage($complete_mail_message = null)
1233
    {
1234
        $this->complete_mail_message .= $complete_mail_message;
1235
1236
        return $this;
1237
    }
1238
1239
    /**
1240
     * 商品の受注明細を取得
1241
     *
1242
     * @return OrderItem[]
1243
     */
1244 36
    public function getProductOrderItems()
1245
    {
1246 36
        $sio = new OrderItemCollection($this->OrderItems->toArray());
1247
1248 36
        return array_values($sio->getProductClasses()->toArray());
1249
    }
1250
1251
    /**
1252
     * 同じ規格の商品の個数をまとめた受注明細を取得
1253
     *
1254
     * @return OrderItem[]
1255
     */
1256 1
    public function getMergedProductOrderItems()
1257
    {
1258 1
        $ProductOrderItems = $this->getProductOrderItems();
1259
1260 1
        $orderItemArray = [];
1261
1262
        /** @var OrderItem $ProductOrderItem */
1263 1
        foreach ($ProductOrderItems as $ProductOrderItem) {
1264 1
            $productClassId = $ProductOrderItem->getProductClass()->getId();
1265 1
            if (array_key_exists($productClassId, $orderItemArray)) {
1266
                // 同じ規格の商品がある場合は個数をまとめる
1267
                /** @var ItemInterface $OrderItem */
1268 1
                $OrderItem = $orderItemArray[$productClassId];
1269 1
                $quantity = $OrderItem->getQuantity() + $ProductOrderItem->getQuantity();
1270 1
                $OrderItem->setQuantity($quantity);
1271
            } else {
1272
                // 新規規格の商品は新しく追加する
1273 1
                $OrderItem = new OrderItem();
1274
                $OrderItem
1275 1
                    ->setProduct($ProductOrderItem->getProduct())
1276 1
                    ->setProductName($ProductOrderItem->getProductName())
1277 1
                    ->setClassCategoryName1($ProductOrderItem->getClassCategoryName1())
1278 1
                    ->setClassCategoryName2($ProductOrderItem->getClassCategoryName2())
1279 1
                    ->setPriceIncTax($ProductOrderItem->getPriceIncTax())
1280 1
                    ->setQuantity($ProductOrderItem->getQuantity());
1281 1
                $orderItemArray[$productClassId] = $OrderItem;
1282
            }
1283
        }
1284
1285 1
        return array_values($orderItemArray);
1286
    }
1287
1288
    /**
1289
     * Add orderItem.
1290
     *
1291
     * @param \Eccube\Entity\OrderItem $OrderItem
1292
     *
1293
     * @return Order
1294
     */
1295 241
    public function addOrderItem(\Eccube\Entity\OrderItem $OrderItem)
1296
    {
1297 241
        $this->OrderItems[] = $OrderItem;
1298
1299 241
        return $this;
1300
    }
1301
1302
    /**
1303
     * Remove orderItem.
1304
     *
1305
     * @param \Eccube\Entity\OrderItem $OrderItem
1306
     *
1307
     * @return boolean TRUE if this collection contained the specified element, FALSE otherwise.
1308
     */
1309 28
    public function removeOrderItem(\Eccube\Entity\OrderItem $OrderItem)
1310
    {
1311 28
        return $this->OrderItems->removeElement($OrderItem);
1312
    }
1313
1314
    /**
1315
     * Get orderItems.
1316
     *
1317
     * @return \Doctrine\Common\Collections\Collection|OrderItem[]
1318
     */
1319 243
    public function getOrderItems()
1320
    {
1321 243
        return $this->OrderItems;
1322
    }
1323
1324
    /**
1325
     * Sorted to getOrderItems()
1326
     *
1327
     * @return ItemCollection
1328
     */
1329 232
    public function getItems()
1330
    {
1331 232
        return (new ItemCollection($this->getOrderItems()))->sort();
1332
    }
1333
1334
    /**
1335
     * Add shipping.
1336
     *
1337
     * @param \Eccube\Entity\Shipping $Shipping
1338
     *
1339
     * @return Order
1340
     */
1341 221
    public function addShipping(\Eccube\Entity\Shipping $Shipping)
1342
    {
1343 221
        $this->Shippings[] = $Shipping;
1344
1345 221
        return $this;
1346
    }
1347
1348
    /**
1349
     * Remove shipping.
1350
     *
1351
     * @param \Eccube\Entity\Shipping $Shipping
1352
     *
1353
     * @return boolean TRUE if this collection contained the specified element, FALSE otherwise.
1354
     */
1355 25
    public function removeShipping(\Eccube\Entity\Shipping $Shipping)
1356
    {
1357 25
        return $this->Shippings->removeElement($Shipping);
1358
    }
1359
1360
    /**
1361
     * Get shippings.
1362
     *
1363
     * @return \Doctrine\Common\Collections\Collection|\Eccube\Entity\Shipping[]
1364
     */
1365 104
    public function getShippings()
1366
    {
1367 104
        $criteria = Criteria::create()
1368 104
            ->orderBy(['name01' => Criteria::ASC, 'name02' => Criteria::ASC, 'id' => Criteria::ASC]);
1369
1370 104
        return $this->Shippings->matching($criteria);
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Doctrine\Common\Collections\Collection as the method matching() does only exist in the following implementations of said interface: Doctrine\Common\Collections\ArrayCollection, Doctrine\ORM\LazyCriteriaCollection, Doctrine\ORM\PersistentCollection, Eccube\Service\Calculator\OrderItemCollection, Eccube\Service\PurchaseFlow\ItemCollection.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
1371
    }
1372
1373
    /**
1374
     * Add mailHistory.
1375
     *
1376
     * @param \Eccube\Entity\MailHistory $mailHistory
1377
     *
1378
     * @return Order
1379
     */
1380
    public function addMailHistory(\Eccube\Entity\MailHistory $mailHistory)
1381
    {
1382
        $this->MailHistories[] = $mailHistory;
1383
1384
        return $this;
1385
    }
1386
1387
    /**
1388
     * Remove mailHistory.
1389
     *
1390
     * @param \Eccube\Entity\MailHistory $mailHistory
1391
     *
1392
     * @return boolean TRUE if this collection contained the specified element, FALSE otherwise.
1393
     */
1394
    public function removeMailHistory(\Eccube\Entity\MailHistory $mailHistory)
1395
    {
1396
        return $this->MailHistories->removeElement($mailHistory);
1397
    }
1398
1399
    /**
1400
     * Get mailHistories.
1401
     *
1402
     * @return \Doctrine\Common\Collections\Collection
1403
     */
1404 1
    public function getMailHistories()
1405
    {
1406 1
        return $this->MailHistories;
1407
    }
1408
1409
    /**
1410
     * Set customer.
1411
     *
1412
     * @param \Eccube\Entity\Customer|null $customer
1413
     *
1414
     * @return Order
1415
     */
1416 205
    public function setCustomer(\Eccube\Entity\Customer $customer = null)
1417
    {
1418 205
        $this->Customer = $customer;
1419
1420 205
        return $this;
1421
    }
1422
1423
    /**
1424
     * Get customer.
1425
     *
1426
     * @return \Eccube\Entity\Customer|null
1427
     */
1428 234
    public function getCustomer()
1429
    {
1430 234
        return $this->Customer;
1431
    }
1432
1433
    /**
1434
     * Set country.
1435
     *
1436
     * @param \Eccube\Entity\Master\Country|null $country
1437
     *
1438
     * @return Order
1439
     */
1440
    public function setCountry(\Eccube\Entity\Master\Country $country = null)
1441
    {
1442
        $this->Country = $country;
1443
1444
        return $this;
1445
    }
1446
1447
    /**
1448
     * Get country.
1449
     *
1450
     * @return \Eccube\Entity\Master\Country|null
1451
     */
1452
    public function getCountry()
1453
    {
1454
        return $this->Country;
1455
    }
1456
1457
    /**
1458
     * Set pref.
1459
     *
1460
     * @param \Eccube\Entity\Master\Pref|null $pref
1461
     *
1462
     * @return Order
1463
     */
1464 170
    public function setPref(\Eccube\Entity\Master\Pref $pref = null)
1465
    {
1466 170
        $this->Pref = $pref;
1467
1468 170
        return $this;
1469
    }
1470
1471
    /**
1472
     * Get pref.
1473
     *
1474
     * @return \Eccube\Entity\Master\Pref|null
1475
     */
1476 73
    public function getPref()
1477
    {
1478 73
        return $this->Pref;
1479
    }
1480
1481
    /**
1482
     * Set sex.
1483
     *
1484
     * @param \Eccube\Entity\Master\Sex|null $sex
1485
     *
1486
     * @return Order
1487
     */
1488 6
    public function setSex(\Eccube\Entity\Master\Sex $sex = null)
1489
    {
1490 6
        $this->Sex = $sex;
1491
1492 6
        return $this;
1493
    }
1494
1495
    /**
1496
     * Get sex.
1497
     *
1498
     * @return \Eccube\Entity\Master\Sex|null
1499
     */
1500 3
    public function getSex()
1501
    {
1502 3
        return $this->Sex;
1503
    }
1504
1505
    /**
1506
     * Set job.
1507
     *
1508
     * @param \Eccube\Entity\Master\Job|null $job
1509
     *
1510
     * @return Order
1511
     */
1512 5
    public function setJob(\Eccube\Entity\Master\Job $job = null)
1513
    {
1514 5
        $this->Job = $job;
1515
1516 5
        return $this;
1517
    }
1518
1519
    /**
1520
     * Get job.
1521
     *
1522
     * @return \Eccube\Entity\Master\Job|null
1523
     */
1524 3
    public function getJob()
1525
    {
1526 3
        return $this->Job;
1527
    }
1528
1529
    /**
1530
     * Set payment.
1531
     *
1532
     * @param \Eccube\Entity\Payment|null $payment
1533
     *
1534
     * @return Order
1535
     */
1536 221
    public function setPayment(\Eccube\Entity\Payment $payment = null)
1537
    {
1538 221
        $this->Payment = $payment;
1539
1540 221
        return $this;
1541
    }
1542
1543
    /**
1544
     * Get payment.
1545
     *
1546
     * @return \Eccube\Entity\Payment|null
1547
     */
1548 221
    public function getPayment()
1549
    {
1550 221
        return $this->Payment;
1551
    }
1552
1553
    /**
1554
     * Set deviceType.
1555
     *
1556
     * @param \Eccube\Entity\Master\DeviceType|null $deviceType
1557
     *
1558
     * @return Order
1559
     */
1560 51
    public function setDeviceType(\Eccube\Entity\Master\DeviceType $deviceType = null)
1561
    {
1562 51
        $this->DeviceType = $deviceType;
1563
1564 51
        return $this;
1565
    }
1566
1567
    /**
1568
     * Get deviceType.
1569
     *
1570
     * @return \Eccube\Entity\Master\DeviceType|null
1571
     */
1572 2
    public function getDeviceType()
1573
    {
1574 2
        return $this->DeviceType;
1575
    }
1576
1577
    /**
1578
     * Set customerOrderStatus.
1579
     *
1580
     * @param \Eccube\Entity\Master\CustomerOrderStatus|null $customerOrderStatus
1581
     *
1582
     * @return Order
1583
     */
1584
    public function setCustomerOrderStatus(\Eccube\Entity\Master\CustomerOrderStatus $customerOrderStatus = null)
1585
    {
1586
        $this->CustomerOrderStatus = $customerOrderStatus;
1587
1588
        return $this;
1589
    }
1590
1591
    /**
1592
     * Get customerOrderStatus.
1593
     *
1594
     * @return \Eccube\Entity\Master\CustomerOrderStatus|null
1595
     */
1596
    public function getCustomerOrderStatus()
1597
    {
1598
        return $this->CustomerOrderStatus;
1599
    }
1600
1601
    /**
1602
     * Set orderStatus.
1603
     *
1604
     * @param \Eccube\Entity\Master\OrderStatus|null $orderStatus
1605
     *
1606
     * @return Order
1607
     */
1608 315
    public function setOrderStatus(\Eccube\Entity\Master\OrderStatus $orderStatus = null)
1609
    {
1610 315
        $this->OrderStatus = $orderStatus;
1611
1612 315
        return $this;
1613
    }
1614
1615
    /**
1616
     * Get orderStatus.
1617
     *
1618
     * @return \Eccube\Entity\Master\OrderStatus|null
1619
     */
1620 209
    public function getOrderStatus()
1621
    {
1622 209
        return $this->OrderStatus;
1623
    }
1624
1625
    /**
1626
     * @param ItemInterface $item
1627
     */
1628 56
    public function addItem(ItemInterface $item)
1629
    {
1630 56
        $this->OrderItems->add($item);
1631
    }
1632
1633 1
    public function getQuantity()
1634
    {
1635 1
        $quantity = 0;
1636 1
        foreach ($this->getItems() as $item) {
1637 1
            $quantity += $item->getQuantity();
1638
        }
1639
1640 1
        return $quantity;
1641
    }
1642
}
1643