Completed
Push — 1.10 ( f87090...370553 )
by
unknown
13:18 queued 19s
created

Cart::getShippingAddress()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace OroCRM\Bundle\MagentoBundle\Entity;
4
5
use Doctrine\ORM\Mapping as ORM;
6
use Doctrine\Common\Collections\Collection;
7
use Doctrine\Common\Collections\ArrayCollection;
8
9
use Oro\Bundle\OrganizationBundle\Entity\Organization;
10
use Oro\Bundle\UserBundle\Entity\User;
11
use Oro\Bundle\WorkflowBundle\Entity\WorkflowItem;
12
use Oro\Bundle\WorkflowBundle\Entity\WorkflowStep;
13
use Oro\Bundle\LocaleBundle\Model\FirstNameInterface;
14
use Oro\Bundle\LocaleBundle\Model\LastNameInterface;
15
use Oro\Bundle\EntityConfigBundle\Metadata\Annotation\Config;
16
use Oro\Bundle\EntityConfigBundle\Metadata\Annotation\ConfigField;
17
18
use OroCRM\Bundle\MagentoBundle\Model\ExtendCart;
19
use OroCRM\Bundle\SalesBundle\Entity\Opportunity;
20
use OroCRM\Bundle\ChannelBundle\Model\ChannelAwareInterface;
21
22
/**
23
 * @SuppressWarnings(PHPMD.ExcessivePublicCount)
24
 * @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
25
 * @SuppressWarnings(PHPMD.TooManyFields)
26
 *
27
 * @package OroCRM\Bundle\OroCRMMagentoBundle\Entity
28
 * @ORM\Entity(repositoryClass="OroCRM\Bundle\MagentoBundle\Entity\Repository\CartRepository")
29
 * @ORM\HasLifecycleCallbacks
30
 * @ORM\Table(name="orocrm_magento_cart",
31
 *  indexes={
32
 *      @ORM\Index(name="magecart_origin_idx", columns={"origin_id"}),
33
 *      @ORM\Index(name="magecart_updated_idx",columns={"updatedAt"})
34
 *  },
35
 *  uniqueConstraints={
36
 *      @ORM\UniqueConstraint(name="unq_cart_origin_id_channel_id", columns={"origin_id", "channel_id"})
37
 *  }
38
 * )
39
 * @Config(
40
 *      routeView="orocrm_magento_cart_view",
41
 *      defaultValues={
42
 *          "entity"={
43
 *              "icon"="icon-shopping-cart"
44
 *          },
45
 *          "ownership"={
46
 *              "owner_type"="USER",
47
 *              "owner_field_name"="owner",
48
 *              "owner_column_name"="user_owner_id",
49
 *              "organization_field_name"="organization",
50
 *              "organization_column_name"="organization_id"
51
 *          },
52
 *          "security"={
53
 *              "type"="ACL",
54
 *              "group_name"="",
55
 *              "category"="sales_data"
56
 *          },
57
 *          "form"={
58
 *              "grid_name"="magento-cart-grid",
59
 *          },
60
 *          "workflow"={
61
 *              "active_workflow"="b2c_flow_abandoned_shopping_cart"
62
 *          },
63
 *          "grid"={
64
 *              "default"="magento-cart-grid",
65
 *              "context"="magento-cart-for-context-grid"
66
 *          },
67
 *          "tag"={
68
 *              "enabled"=true
69
 *          }
70
 *      }
71
 * )
72
 */
73
class Cart extends ExtendCart implements
74
    ChannelAwareInterface,
75
    FirstNameInterface,
76
    LastNameInterface,
77
    OriginAwareInterface,
78
    IntegrationAwareInterface
79
{
80
    use IntegrationEntityTrait, OriginTrait, NamesAwareTrait, ChannelEntityTrait;
81
82
    /**
83
     * @var CartItem[]|Collection
84
     *
85
     * @ORM\OneToMany(targetEntity="OroCRM\Bundle\MagentoBundle\Entity\CartItem",
86
     *     mappedBy="cart", cascade={"all"}, orphanRemoval=true
87
     * )
88
     * @ORM\OrderBy({"originId" = "DESC"})
89
     * @ConfigField(
90
     *      defaultValues={
91
     *          "importexport"={
92
     *              "full"=true
93
     *          }
94
     *      }
95
     * )
96
     */
97
    protected $cartItems;
98
99
    /**
100
     * @ORM\ManyToOne(targetEntity="Customer", inversedBy="carts")
101
     * @ORM\JoinColumn(name="customer_id", referencedColumnName="id", onDelete="CASCADE")
102
     */
103
    protected $customer;
104
105
    /**
106
     * @var Store
107
     *
108
     * @ORM\ManyToOne(targetEntity="OroCRM\Bundle\MagentoBundle\Entity\Store")
109
     * @ORM\JoinColumn(name="store_id", referencedColumnName="id", onDelete="SET NULL")
110
     * @ConfigField(
111
     *      defaultValues={
112
     *          "importexport"={
113
     *              "full"=false
114
     *          }
115
     *      }
116
     * )
117
     */
118
    protected $store;
119
120
    /**
121
     * Total items qty
122
     *
123
     * @var float
124
     *
125
     * @ORM\Column(name="items_qty", type="float")
126
     */
127
    protected $itemsQty;
128
129
    /**
130
     * Items count
131
     *
132
     * @var integer
133
     *
134
     * @ORM\Column(name="items_count", type="integer", options={"unsigned"=true})
135
     */
136
    protected $itemsCount;
137
138
    /**
139
     * @var string
140
     *
141
     * @ORM\Column(name="base_currency_code", type="string", length=32, nullable=false)
142
     */
143
    protected $baseCurrencyCode;
144
145
    /**
146
     * @var string
147
     *
148
     * @ORM\Column(name="store_currency_code", type="string", length=32, nullable=false)
149
     */
150
    protected $storeCurrencyCode;
151
152
    /**
153
     * @var string
154
     *
155
     * @ORM\Column(name="quote_currency_code", type="string", length=32, nullable=false)
156
     */
157
    protected $quoteCurrencyCode;
158
159
    /**
160
     * @var float
161
     *
162
     * @ORM\Column(name="store_to_base_rate", type="float", nullable=false)
163
     */
164
    protected $storeToBaseRate;
165
166
    /**
167
     * @var float
168
     *
169
     * @ORM\Column(name="store_to_quote_rate", type="float", nullable=true)
170
     */
171
    protected $storeToQuoteRate;
172
173
    /**
174
     * @var string
175
     *
176
     * @ORM\Column(name="email", type="string", length=255, nullable=true)
177
     * @ConfigField(
178
     *      defaultValues={
179
     *          "entity"={
180
     *              "contact_information"="email"
181
     *          }
182
     *      }
183
     * )
184
     */
185
    protected $email;
186
187
    /**
188
     * @var string
189
     *
190
     * @ORM\Column(name="gift_message", type="string", length=255, nullable=true)
191
     */
192
    protected $giftMessage;
193
194
    /**
195
     * @var float
196
     *
197
     * @ORM\Column(name="is_guest", type="boolean")
198
     */
199
    protected $isGuest;
200
201
    /**
202
     * @var CartAddress $shippingAddress
203
     *
204
     * @ORM\ManyToOne(targetEntity="OroCRM\Bundle\MagentoBundle\Entity\CartAddress", cascade={"persist", "remove"})
205
     * @ORM\JoinColumn(name="shipping_address_id", referencedColumnName="id", onDelete="SET NULL")
206
     * @ConfigField(
207
     *      defaultValues={
208
     *          "importexport"={
209
     *              "full"=true
210
     *          }
211
     *      }
212
     * )
213
     */
214
    protected $shippingAddress;
215
216
    /**
217
     * @var CartAddress $billingAddress
218
     *
219
     * @ORM\ManyToOne(targetEntity="OroCRM\Bundle\MagentoBundle\Entity\CartAddress", cascade={"persist", "remove"})
220
     * @ORM\JoinColumn(name="billing_address_id", referencedColumnName="id", onDelete="SET NULL")
221
     * @ConfigField(
222
     *      defaultValues={
223
     *          "importexport"={
224
     *              "full"=true
225
     *          }
226
     *      }
227
     * )
228
     */
229
    protected $billingAddress;
230
231
    /**
232
     * @var string
233
     *
234
     * @ORM\Column(name="payment_details", type="string", length=255, nullable=true)
235
     */
236
    protected $paymentDetails;
237
238
    /**
239
     * @var CartStatus
240
     *
241
     * @ORM\ManyToOne(targetEntity="OroCRM\Bundle\MagentoBundle\Entity\CartStatus")
242
     * @ORM\JoinColumn(name="status_name", referencedColumnName="name", onDelete="SET NULL")
243
     * @ConfigField(
244
     *      defaultValues={
245
     *          "importexport"={
246
     *              "full"=false
247
     *          }
248
     *      }
249
     * )
250
     */
251
    protected $status;
252
253
    /**
254
     * @var Opportunity
255
     *
256
     * @ORM\ManyToOne(targetEntity="OroCRM\Bundle\SalesBundle\Entity\Opportunity")
257
     * @ORM\JoinColumn(name="opportunity_id", referencedColumnName="id", onDelete="SET NULL")
258
     */
259
    protected $opportunity;
260
261
    /**
262
     * @var string
263
     *
264
     * @ORM\Column(name="notes", type="text", nullable=true)
265
     */
266
    protected $notes;
267
268
    /**
269
     * @var WorkflowItem
270
     *
271
     * @ORM\OneToOne(targetEntity="Oro\Bundle\WorkflowBundle\Entity\WorkflowItem")
272
     * @ORM\JoinColumn(name="workflow_item_id", referencedColumnName="id", onDelete="SET NULL")
273
     */
274
    protected $workflowItem;
275
276
    /**
277
     * @var WorkflowStep
278
     *
279
     * @ORM\ManyToOne(targetEntity="Oro\Bundle\WorkflowBundle\Entity\WorkflowStep")
280
     * @ORM\JoinColumn(name="workflow_step_id", referencedColumnName="id", onDelete="SET NULL")
281
     */
282
    protected $workflowStep;
283
284
    /**
285
     * @var string
286
     *
287
     * @ORM\Column(name="status_message", type="string", length=255, nullable=true)
288
     */
289
    protected $statusMessage;
290
291
    /**
292
     * @var User
293
     * @ORM\ManyToOne(targetEntity="Oro\Bundle\UserBundle\Entity\User")
294
     * @ORM\JoinColumn(name="user_owner_id", referencedColumnName="id", onDelete="SET NULL")
295
     */
296
    protected $owner;
297
298
    /**
299
     * @var Organization
300
     *
301
     * @ORM\ManyToOne(targetEntity="Oro\Bundle\OrganizationBundle\Entity\Organization")
302
     * @ORM\JoinColumn(name="organization_id", referencedColumnName="id", onDelete="SET NULL")
303
     */
304
    protected $organization;
305
306
    /**
307
     * @var \DateTime
308
     *
309
     * @ORM\Column(type="datetime", name="imported_at", nullable=true)
310
     */
311
    protected $importedAt;
312
313
    /**
314
     * @var \DateTime
315
     *
316
     * @ORM\Column(type="datetime", name="synced_at", nullable=true)
317
     */
318
    protected $syncedAt;
319
320
    /**
321
     * @param WorkflowItem $workflowItem
322
     *
323
     * @return Cart
324
     */
325
    public function setWorkflowItem($workflowItem)
326
    {
327
        $this->workflowItem = $workflowItem;
328
329
        return $this;
330
    }
331
332
    /**
333
     * @return WorkflowItem
334
     */
335
    public function getWorkflowItem()
336
    {
337
        return $this->workflowItem;
338
    }
339
340
    /**
341
     * @param WorkflowStep $workflowStep
342
     *
343
     * @return Cart
344
     */
345
    public function setWorkflowStep($workflowStep)
346
    {
347
        $this->workflowStep = $workflowStep;
348
349
        return $this;
350
    }
351
352
    /**
353
     * @return WorkflowStep
354
     */
355
    public function getWorkflowStep()
356
    {
357
        return $this->workflowStep;
358
    }
359
360
    public function __construct()
361
    {
362
        parent::__construct();
363
364
        $this->status    = new CartStatus('open');
365
        $this->cartItems = new ArrayCollection();
366
    }
367
368
    /**
369
     * @return CartItem[]|Collection
370
     */
371
    public function getCartItems()
372
    {
373
        return $this->cartItems;
374
    }
375
376
    /**
377
     * @param CartItem[]|Collection $cartItems
378
     */
379
    public function setCartItems(Collection $cartItems)
380
    {
381
        $this->cartItems = $cartItems;
382
    }
383
384
    /**
385
     * @param CartItem $cartItem
386
     *
387
     * @return $this
388
     */
389
    public function addCartItem(CartItem $cartItem)
390
    {
391
        if (!$this->cartItems->contains($cartItem)) {
392
            $this->cartItems->add($cartItem);
393
            $cartItem->setCart($this);
394
        }
395
396
        return $this;
397
    }
398
399
    /**
400
     * @param CartItem $cartItem
401
     *
402
     * @return $this
403
     */
404
    public function removeCartItem(CartItem $cartItem)
405
    {
406
        if ($this->cartItems->contains($cartItem)) {
407
            $this->cartItems->removeElement($cartItem);
408
        }
409
410
        return $this;
411
    }
412
413
    /**
414
     * @param Store $store
415
     */
416
    public function setStore($store)
417
    {
418
        $this->store = $store;
419
    }
420
421
    /**
422
     * @return Store
423
     */
424
    public function getStore()
425
    {
426
        return $this->store;
427
    }
428
429
    /**
430
     * @return Customer
431
     */
432
    public function getCustomer()
433
    {
434
        return $this->customer;
435
    }
436
437
    /**
438
     * @param Customer|null $customer
439
     *
440
     * @return Cart
441
     */
442
    public function setCustomer(Customer $customer = null)
443
    {
444
        $this->customer = $customer;
445
446
        return $this;
447
    }
448
449
    /**
450
     * @param CartAddress $shippingAddress
451
     *
452
     * @return Cart
453
     */
454
    public function setShippingAddress(CartAddress $shippingAddress = null)
455
    {
456
        $this->shippingAddress = $shippingAddress;
457
458
        return $this;
459
    }
460
461
    /**
462
     * @param CartAddress $billingAddress
463
     *
464
     * @return Cart
465
     */
466
    public function setBillingAddress(CartAddress $billingAddress = null)
467
    {
468
        $this->billingAddress = $billingAddress;
469
470
        return $this;
471
    }
472
473
    /**
474
     * @return CartAddress
475
     */
476
    public function getBillingAddress()
477
    {
478
        return $this->billingAddress;
479
    }
480
481
    /**
482
     * @return CartAddress
483
     */
484
    public function getShippingAddress()
485
    {
486
        return $this->shippingAddress;
487
    }
488
489
    /**
490
     * @return string
491
     */
492
    public function getEmail()
493
    {
494
        return $this->email;
495
    }
496
497
    /**
498
     * @param string $email
499
     *
500
     * @return Cart
501
     */
502
    public function setEmail($email)
503
    {
504
        $this->email = $email;
505
506
        return $this;
507
    }
508
509
    /**
510
     * @return float
511
     */
512
    public function getItemsQty()
513
    {
514
        return $this->itemsQty;
515
    }
516
517
    /**
518
     * @param float $itemsQty
519
     *
520
     * @return Cart
521
     */
522
    public function setItemsQty($itemsQty)
523
    {
524
        $this->itemsQty = $itemsQty;
525
526
        return $this;
527
    }
528
529
    /**
530
     * @return float
531
     */
532
    public function getSubTotal()
533
    {
534
        return $this->subTotal;
535
    }
536
537
    /**
538
     * @return string
539
     */
540
    public function getQuoteCurrencyCode()
541
    {
542
        return $this->quoteCurrencyCode;
543
    }
544
545
    /**
546
     * @param string $quoteCurrencyCode
547
     *
548
     * @return Cart
549
     */
550
    public function setQuoteCurrencyCode($quoteCurrencyCode)
551
    {
552
        $this->quoteCurrencyCode = $quoteCurrencyCode;
553
554
        return $this;
555
    }
556
557
    /**
558
     * @param string $paymentDetails
559
     */
560
    public function setPaymentDetails($paymentDetails)
561
    {
562
        $this->paymentDetails = $paymentDetails;
563
    }
564
565
    /**
566
     * @return string
567
     */
568
    public function getPaymentDetails()
569
    {
570
        return $this->paymentDetails;
571
    }
572
573
    /**
574
     * @param CartStatus $status
575
     *
576
     * @return Cart
577
     */
578
    public function setStatus($status)
579
    {
580
        $this->status = $status;
581
582
        return $this;
583
    }
584
585
    /**
586
     * @return CartStatus
587
     */
588
    public function getStatus()
589
    {
590
        return $this->status;
591
    }
592
593
    /**
594
     * @param string $baseCurrencyCode
595
     *
596
     * @return Cart
597
     */
598
    public function setBaseCurrencyCode($baseCurrencyCode)
599
    {
600
        $this->baseCurrencyCode = $baseCurrencyCode;
601
602
        return $this;
603
    }
604
605
    /**
606
     * @return string
607
     */
608
    public function getBaseCurrencyCode()
609
    {
610
        return $this->baseCurrencyCode;
611
    }
612
613
    /**
614
     * @param string $giftMessage
615
     *
616
     * @return Cart
617
     */
618
    public function setGiftMessage($giftMessage)
619
    {
620
        $this->giftMessage = $giftMessage;
621
622
        return $this;
623
    }
624
625
    /**
626
     * @return string
627
     */
628
    public function getGiftMessage()
629
    {
630
        return $this->giftMessage;
631
    }
632
633
    /**
634
     * @param float $isGuest
635
     *
636
     * @return Cart
637
     */
638
    public function setIsGuest($isGuest)
639
    {
640
        $this->isGuest = $isGuest;
641
642
        return $this;
643
    }
644
645
    /**
646
     * @return float
647
     */
648
    public function getIsGuest()
649
    {
650
        return $this->isGuest;
651
    }
652
653
    /**
654
     * @param int $itemsCount
655
     *
656
     * @return Cart
657
     */
658
    public function setItemsCount($itemsCount)
659
    {
660
        $this->itemsCount = $itemsCount;
661
662
        return $this;
663
    }
664
665
    /**
666
     * @return int
667
     */
668
    public function getItemsCount()
669
    {
670
        return $this->itemsCount;
671
    }
672
673
    /**
674
     * @param string $storeCurrencyCode
675
     *
676
     * @return Cart
677
     */
678
    public function setStoreCurrencyCode($storeCurrencyCode)
679
    {
680
        $this->storeCurrencyCode = $storeCurrencyCode;
681
682
        return $this;
683
    }
684
685
    /**
686
     * @return string
687
     */
688
    public function getStoreCurrencyCode()
689
    {
690
        return $this->storeCurrencyCode;
691
    }
692
693
    /**
694
     * @param float $storeToBaseRate
695
     *
696
     * @return Cart
697
     */
698
    public function setStoreToBaseRate($storeToBaseRate)
699
    {
700
        $this->storeToBaseRate = $storeToBaseRate;
701
702
        return $this;
703
    }
704
705
    /**
706
     * @return float
707
     */
708
    public function getStoreToBaseRate()
709
    {
710
        return $this->storeToBaseRate;
711
    }
712
713
    /**
714
     * @param float $storeToQuoteRate
715
     *
716
     * @return Cart
717
     */
718
    public function setStoreToQuoteRate($storeToQuoteRate)
719
    {
720
        $this->storeToQuoteRate = $storeToQuoteRate;
721
722
        return $this;
723
    }
724
725
    /**
726
     * @return float
727
     */
728
    public function getStoreToQuoteRate()
729
    {
730
        return $this->storeToQuoteRate;
731
    }
732
733
    /**
734
     * @param Opportunity $opportunity
735
     *
736
     * @return Cart
737
     */
738
    public function setOpportunity($opportunity)
739
    {
740
        $this->opportunity = $opportunity;
741
742
        return $this;
743
    }
744
745
    /**
746
     * @return Opportunity
747
     */
748
    public function getOpportunity()
749
    {
750
        return $this->opportunity;
751
    }
752
753
    /**
754
     * @param string $notes
755
     *
756
     * @return Cart
757
     */
758
    public function setNotes($notes)
759
    {
760
        $this->notes = $notes;
761
        return $this;
762
    }
763
764
    /**
765
     * @return string
766
     */
767
    public function getNotes()
768
    {
769
        return $this->notes;
770
    }
771
772
    /**
773
     * Pre persist event listener
774
     *
775
     * @ORM\PrePersist
776
     */
777
    public function beforeSave()
778
    {
779
        $this->updateNames();
780
    }
781
782
    /**
783
     * Pre update event handler
784
     *
785
     * @ORM\PreUpdate
786
     */
787
    public function doPreUpdate()
788
    {
789
        $this->updateNames();
790
    }
791
792
    /**
793
     * @param string $statusMessage
794
     */
795
    public function setStatusMessage($statusMessage)
796
    {
797
        $this->statusMessage = $statusMessage;
798
    }
799
800
    /**
801
     * @return string
802
     */
803
    public function getStatusMessage()
804
    {
805
        return $this->statusMessage;
806
    }
807
808
    /**
809
     * @return User
810
     */
811
    public function getOwner()
812
    {
813
        return $this->owner;
814
    }
815
816
    /**
817
     * @param User $user
818
     */
819
    public function setOwner(User $user)
820
    {
821
        $this->owner = $user;
822
    }
823
824
    /**
825
     * Set organization
826
     *
827
     * @param Organization $organization
828
     * @return Cart
829
     */
830
    public function setOrganization(Organization $organization = null)
831
    {
832
        $this->organization = $organization;
833
834
        return $this;
835
    }
836
837
    /**
838
     * Get organization
839
     *
840
     * @return Organization
841
     */
842
    public function getOrganization()
843
    {
844
        return $this->organization;
845
    }
846
847
    /**
848
     * @return \DateTime
849
     */
850
    public function getSyncedAt()
851
    {
852
        return $this->syncedAt;
853
    }
854
855
    /**
856
     * @param \DateTime|null $syncedAt
857
     * @return Cart
858
     */
859
    public function setSyncedAt(\DateTime $syncedAt = null)
860
    {
861
        $this->syncedAt = $syncedAt;
862
863
        return $this;
864
    }
865
866
    /**
867
     * @return \DateTime
868
     */
869
    public function getImportedAt()
870
    {
871
        return $this->importedAt;
872
    }
873
874
    /**
875
     * @param \DateTime|null $importedAt
876
     * @return Cart
877
     */
878
    public function setImportedAt(\DateTime $importedAt = null)
879
    {
880
        $this->importedAt = $importedAt;
881
882
        return $this;
883
    }
884
885
    /**
886
     * @return string
887
     */
888
    public function __toString()
889
    {
890
        return (string)$this->getId();
891
    }
892
}
893