Failed Conditions
Pull Request — experimental/sf (#3236)
by Kentaro
132:46 queued 125:39
created

Order   F

Complexity

Total Complexity 114

Size/Duplication

Total Lines 1610
Duplicated Lines 0 %

Coupling/Cohesion

Components 5
Dependencies 10

Test Coverage

Coverage 87.29%

Importance

Changes 0
Metric Value
dl 0
loc 1610
ccs 261
cts 299
cp 0.8729
rs 0.8
c 0
b 0
f 0
wmc 114
lcom 5
cbo 10

101 Methods

Rating   Name   Duplication   Size   Complexity  
A isMultiple() 0 4 2
A findShipping() 0 10 3
A getSaleTypes() 0 13 3
A getTotalPrice() 0 7 1
A __construct() 0 15 1
A getId() 0 4 1
A setPreOrderId() 0 6 1
A getPreOrderId() 0 4 1
A setOrderNo() 0 6 1
A getOrderNo() 0 4 1
A setMessage() 0 6 1
A getMessage() 0 4 1
A setName01() 0 6 1
A getName01() 0 4 1
A setName02() 0 6 1
A getName02() 0 4 1
A setKana01() 0 6 1
A getKana01() 0 4 1
A setKana02() 0 6 1
A getKana02() 0 4 1
A setCompanyName() 0 6 1
A getCompanyName() 0 4 1
A setEmail() 0 6 1
A getEmail() 0 4 1
A setPhoneNumber() 0 6 1
A getPhoneNumber() 0 4 1
A setPostalCode() 0 6 1
A getPostalCode() 0 4 1
A setAddr01() 0 6 1
A getAddr01() 0 4 1
A setAddr02() 0 6 1
A getAddr02() 0 4 1
A setBirth() 0 6 1
A getBirth() 0 4 1
A setSubtotal() 0 6 1
A getSubtotal() 0 4 1
A setDiscount() 0 6 1
A getDiscount() 0 4 1
A setDeliveryFeeTotal() 0 6 1
A getDeliveryFeeTotal() 0 4 1
A setCharge() 0 6 1
A getCharge() 0 4 1
A setTax() 0 6 1
A getTax() 0 4 1
A setTotal() 0 6 1
A getTotal() 0 4 1
A setPaymentTotal() 0 6 1
A getPaymentTotal() 0 4 1
A setPaymentMethod() 0 6 1
A getPaymentMethod() 0 4 1
A setNote() 0 6 1
A getNote() 0 4 1
A setCreateDate() 0 6 1
A getCreateDate() 0 4 1
A setUpdateDate() 0 6 1
A getUpdateDate() 0 4 1
A setOrderDate() 0 6 1
A getOrderDate() 0 4 1
A setShippingDate() 0 6 1
A getShippingDate() 0 4 1
A setPaymentDate() 0 6 1
A getPaymentDate() 0 4 1
A getCurrencyCode() 0 4 1
A setCurrencyCode() 0 6 1
A getCompleteMessage() 0 4 1
A setCompleteMessage() 0 6 1
A appendCompleteMessage() 0 6 1
A getCompleteMailMessage() 0 4 1
A setCompleteMailMessage() 0 6 1
A appendCompleteMailMessage() 0 6 1
A getProductOrderItems() 0 6 1
A getMergedProductOrderItems() 0 31 3
A addOrderItem() 0 6 1
A removeOrderItem() 0 4 1
A getOrderItems() 0 4 1
A getItems() 0 4 1
B getShippings() 0 32 6
A setShippings() 0 5 1
A addMailHistory() 0 6 1
A removeMailHistory() 0 4 1
A getMailHistories() 0 4 1
A setCustomer() 0 6 1
A getCustomer() 0 4 1
A setCountry() 0 6 1
A getCountry() 0 4 1
A setPref() 0 6 1
A getPref() 0 4 1
A setSex() 0 6 1
A getSex() 0 4 1
A setJob() 0 6 1
A getJob() 0 4 1
A setPayment() 0 6 1
A getPayment() 0 4 1
A setDeviceType() 0 6 1
A getDeviceType() 0 4 1
A setCustomerOrderStatus() 0 6 1
A getCustomerOrderStatus() 0 4 1
A setOrderStatus() 0 6 1
A getOrderStatus() 0 4 1
A addItem() 0 4 1
A getQuantity() 0 9 2

How to fix   Complexity   

Complex Class

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

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

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