src/Entity/ECommerce/Cart.php line 1212

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Entity\ECommerce;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use JMS\Serializer\Annotation as JMS;
  8. use App\Entity\ECommerce\Interfaces\ECUserInterface;
  9. use App\Entity\ECommerce\Traits\DatesInterface;
  10. use App\Entity\ECommerce\Traits\DatesTrait;
  11. use App\Entity\App\User;
  12. use Stringable;
  13. use Symfony\Component\Validator\Constraints;
  14. /**
  15. * Cart
  16. *
  17. * @ORM\Table(name="cart")
  18. *
  19. * @ORM\Entity(repositoryClass="App\Repository\ECommerce\CartRepository")
  20. */
  21. class Cart implements DatesInterface, Stringable
  22. {
  23. /**
  24. * Money calculations rounding precision
  25. */
  26. public const int ROUNDING_PRECISION = 2;
  27. /**
  28. * @var int
  29. *
  30. * @ORM\Column(name="id", type="integer")
  31. * @ORM\Id
  32. * @ORM\GeneratedValue(strategy="AUTO")
  33. *
  34. * @JMS\Expose()
  35. * @JMS\Groups({"cart_private", "view_cart"})
  36. */
  37. private $id;
  38. /**
  39. * @var bool
  40. *
  41. * @ORM\Column(name="payed", type="boolean")
  42. *
  43. * @JMS\Expose()
  44. * @JMS\Groups({"cart_private"})
  45. */
  46. private $payed = false;
  47. /**
  48. * @var bool
  49. *
  50. * @ORM\Column(name="checked_out", type="boolean")
  51. *
  52. * @JMS\Expose()
  53. * @JMS\Groups({"cart_private"})
  54. */
  55. private $checkedOut = false;
  56. /**
  57. * @var \DateTime
  58. *
  59. * @ORM\Column(name="checked_out_at", type="datetime", nullable=true)
  60. *
  61. * @JMS\Expose()
  62. * @JMS\Groups({"cart_private"})
  63. */
  64. private $checkedOutAt;
  65. /**
  66. * @var boolean
  67. *
  68. * @ORM\Column(name="shipped", type="boolean")
  69. *
  70. * @JMS\Expose()
  71. * @JMS\Groups({"cart_private"})
  72. */
  73. private $shipped = false;
  74. /**
  75. * @var /DateTime
  76. *
  77. * @ORM\Column(name="shipped_at", type="datetime", nullable=true)
  78. *
  79. * @JMS\Expose()
  80. * @JMS\Groups({"cart_private"})
  81. */
  82. private $shippedAt;
  83. /**
  84. * @var float
  85. *
  86. * @ORM\Column(name="rebate", type="decimal", precision=18, scale=4, nullable=true)
  87. *
  88. * @JMS\Expose()
  89. * @JMS\Groups({"cart_private", "view_cart"})
  90. */
  91. private $rebate;
  92. /**
  93. * @var float
  94. *
  95. * @ORM\Column(name="rebate_converted", type="decimal", precision=18, scale=4, nullable=true)
  96. *
  97. * @JMS\Expose()
  98. * @JMS\Groups({"cart_private", "view_cart"})
  99. */
  100. private $rebateConverted;
  101. /**
  102. * @var float
  103. *
  104. * @ORM\Column(name="subtotal", type="decimal", precision=18, scale=4, nullable=true)
  105. *
  106. * @JMS\Expose()
  107. * @JMS\Groups({"cart_private", "view_cart"})
  108. */
  109. private $subtotal;
  110. /**
  111. * @var float
  112. *
  113. * @ORM\Column(name="subtotal_converted", type="decimal", precision=18, scale=4, nullable=true)
  114. *
  115. * @JMS\Expose()
  116. * @JMS\Groups({"cart_private", "view_cart"})
  117. */
  118. private $subtotalConverted;
  119. /**
  120. * @var float
  121. *
  122. * @ORM\Column(name="tax", type="decimal", precision=18, scale=4, nullable=true)
  123. *
  124. * @JMS\Expose()
  125. * @JMS\Groups({"cart_private", "view_cart"})
  126. */
  127. private $tax;
  128. /**
  129. * @var float
  130. *
  131. * @ORM\Column(name="tax_converted", type="decimal", precision=18, scale=4, nullable=true)
  132. *
  133. * @JMS\Expose()
  134. * @JMS\Groups({"cart_private", "view_cart"})
  135. */
  136. private $taxConverted;
  137. /**
  138. * @var float
  139. *
  140. * @ORM\Column(name="total", type="decimal", precision=18, scale=4, nullable=true)
  141. *
  142. * @JMS\Expose()
  143. * @JMS\Groups({"cart_private", "view_cart"})
  144. */
  145. private $total;
  146. /**
  147. * @var float
  148. *
  149. * @ORM\Column(name="total_converted", type="decimal", precision=18, scale=4, nullable=true)
  150. *
  151. * @JMS\Expose()
  152. * @JMS\Groups({"cart_private", "view_cart"})
  153. */
  154. private $totalConverted;
  155. /**
  156. * @var float
  157. *
  158. * @ORM\Column(name="shipping_price", type="decimal", precision=18, scale=4, nullable=true)
  159. *
  160. * @JMS\Expose()
  161. * @JMS\Groups({"cart_private", "view_cart"})
  162. */
  163. private $shippingPrice;
  164. /**
  165. * @var float
  166. *
  167. * @ORM\Column(name="shipping_price_converted", type="decimal", precision=18, scale=4, nullable=true)
  168. *
  169. * @JMS\Expose()
  170. * @JMS\Groups({"cart_private", "view_cart"})
  171. */
  172. private $shippingPriceConverted;
  173. /**
  174. * @var string
  175. *
  176. * @ORM\Column(name="invoice_country", type="string", length=2, nullable=true)
  177. *
  178. * @JMS\Expose()
  179. * @JMS\Groups({"cart_private"})
  180. */
  181. private $invoiceCountry;
  182. /**
  183. * @var string
  184. *
  185. * @ORM\Column(name="invoice_state", type="string", length=30, nullable=true)
  186. *
  187. * @JMS\Expose()
  188. * @JMS\Groups({"cart_private"})
  189. */
  190. private $invoiceState;
  191. /**
  192. * @var string
  193. *
  194. * @ORM\Column(name="invoice_city", type="string", length=70, nullable=true)
  195. *
  196. * @JMS\Expose()
  197. * @JMS\Groups({"cart_private"})
  198. */
  199. private $invoiceCity;
  200. /**
  201. * @var string
  202. *
  203. * @ORM\Column(name="invoice_zip", type="string", length=30, nullable=true)
  204. *
  205. * @JMS\Expose()
  206. * @JMS\Groups({"cart_private"})
  207. */
  208. private $invoiceZip;
  209. /**
  210. * @var string
  211. *
  212. * @ORM\Column(name="invoice_address", type="string", length=120, nullable=true)
  213. *
  214. * @JMS\Expose()
  215. * @JMS\Groups({"cart_private"})
  216. */
  217. private $invoiceAddress;
  218. /**
  219. * @var string
  220. *
  221. * @ORM\Column(name="invoice_phone", type="string", length=120, nullable=true)
  222. *
  223. * @JMS\Expose()
  224. * @JMS\Groups({"cart_private"})
  225. */
  226. private $invoicePhone;
  227. /**
  228. * @var boolean
  229. *
  230. * @ORM\Column(name="shipping_location_changed", type="boolean", nullable=true)
  231. *
  232. * @JMS\Expose()
  233. * @JMS\Groups({"cart_private"})
  234. */
  235. private $shippingLocationChanged = false;
  236. /**
  237. * @var string
  238. *
  239. * @ORM\Column(name="shipping_country", type="string", length=2, nullable=true)
  240. *
  241. * @JMS\Expose()
  242. * @JMS\Groups({"cart_private"})
  243. */
  244. private $shippingCountry;
  245. /**
  246. * @var string
  247. *
  248. * @ORM\Column(name="shipping_state", type="string", length=30, nullable=true)
  249. *
  250. * @JMS\Expose()
  251. * @JMS\Groups({"cart_private"})
  252. */
  253. private $shippingState;
  254. /**
  255. * @var string
  256. *
  257. * @ORM\Column(name="shipping_city", type="string", length=70, nullable=true)
  258. *
  259. * @JMS\Expose()
  260. * @JMS\Groups({"cart_private"})
  261. */
  262. private $shippingCity;
  263. /**
  264. * @var string
  265. *
  266. * @ORM\Column(name="shipping_zip", type="string", length=30, nullable=true)
  267. *
  268. * @JMS\Expose()
  269. * @JMS\Groups({"cart_private"})
  270. */
  271. private $shippingZip;
  272. /**
  273. * @var string
  274. *
  275. * @ORM\Column(name="shipping_address", type="string", length=120, nullable=true)
  276. *
  277. * @JMS\Expose()
  278. * @JMS\Groups({"cart_private"})
  279. */
  280. private $shippingAddress;
  281. /**
  282. * @var string
  283. *
  284. * @ORM\Column(name="shipping_phone", type="string", length=120, nullable=true)
  285. *
  286. * @JMS\Expose()
  287. * @JMS\Groups({"cart_private"})
  288. */
  289. private $shippingPhone;
  290. /**
  291. * @var bool
  292. *
  293. * @ORM\Column(name="shipping_dates_confirmed", type="boolean", options={"default":0})
  294. *
  295. * @Constraints\IsTrue(groups={"CheckOut"})
  296. *
  297. * @JMS\Expose()
  298. * @JMS\Groups({"cart_private"})
  299. */
  300. private $shippingDatesConfirmed=0;
  301. /**
  302. * @var Shipping
  303. *
  304. * @ORM\ManyToOne(targetEntity="App\Entity\ECommerce\Shipping", inversedBy="carts")
  305. * @ORM\JoinColumn(name="shipping", referencedColumnName="id")
  306. *
  307. * @JMS\Expose()
  308. * @JMS\Groups({"cart_private"})
  309. */
  310. private $shipping;
  311. /**
  312. * @var Currency
  313. *
  314. * @ORM\ManyToOne(targetEntity="App\Entity\ECommerce\Currency")
  315. * @ORM\JoinColumn(name="currency", referencedColumnName="code")
  316. *
  317. * @JMS\Expose()
  318. * @JMS\Groups({"cart_private", "view_cart"})
  319. */
  320. private $currency;
  321. /**
  322. * @var float
  323. *
  324. * @ORM\Column(name="currency_rate", type="decimal", precision=12, scale=4, nullable=true)
  325. *
  326. * @JMS\Expose()
  327. * @JMS\Groups({"cart_private", "view_cart"})
  328. */
  329. private $currencyRate;
  330. /**
  331. * @var ArrayCollection
  332. *
  333. * @ORM\OneToMany(targetEntity="App\Entity\ECommerce\CartItem", mappedBy="cart", cascade={"persist"})
  334. *
  335. * @Constraints\Valid(groups={"CheckOut"})
  336. *
  337. * @JMS\Expose()
  338. * @JMS\Groups({"cart_private", "view_cart"})
  339. */
  340. private $items;
  341. /**
  342. * @var Invoice
  343. *
  344. * @ORM\OneToOne(targetEntity="App\Entity\ECommerce\Invoice", mappedBy="cart", cascade={"persist"})
  345. *
  346. * @JMS\Expose()
  347. * @JMS\Groups({"cart_private"})
  348. */
  349. private $invoice;
  350. /**
  351. * @var Client
  352. *
  353. * @ORM\ManyToOne(targetEntity="App\Entity\ECommerce\Client", inversedBy="carts")
  354. * @ORM\JoinColumn(name="client", referencedColumnName="id")
  355. *
  356. * @JMS\Expose()
  357. * @JMS\Groups({"cart_private"})
  358. */
  359. private $client;
  360. /**
  361. * @var User
  362. *
  363. * @ORM\ManyToOne(targetEntity="App\Entity\App\User", inversedBy="carts")
  364. * @ORM\JoinColumn(name="user_id", referencedColumnName="id")
  365. *
  366. * @JMS\Expose()
  367. * @JMS\Groups({"cart"})
  368. */
  369. private $user;
  370. /**
  371. * Dates trait
  372. * createdAt, updatedAt, IndexAt, syncedAt
  373. */
  374. use DatesTrait {
  375. DatesTrait::__construct as __DT_construct;
  376. }
  377. /**
  378. * Constructor
  379. */
  380. public function __construct(ECUserInterface $user)
  381. {
  382. $this->__DT_construct();
  383. $this->items = new ArrayCollection();
  384. $this->setCreatedAt();
  385. if ($user) {
  386. $this->user = $user;
  387. $this->client = $user->getClient();
  388. }
  389. }
  390. /**
  391. * To String
  392. */
  393. public function __toString(): string
  394. {
  395. return (string)$this->id;
  396. }
  397. /**
  398. * Get id
  399. */
  400. public function getId(): int
  401. {
  402. return $this->id ?? 0;
  403. }
  404. /**
  405. * Set createdAt
  406. *
  407. * @param \DateTime $createdAt
  408. */
  409. public function setCreatedAt($createdAt = null): self
  410. {
  411. $this->createdAt = $createdAt ?? new \DateTime();
  412. return $this;
  413. }
  414. /**
  415. * Get createdAt
  416. *
  417. * @return \DateTime
  418. */
  419. public function getCreatedAt()
  420. {
  421. return $this->createdAt;
  422. }
  423. /**
  424. * Set updatedAt
  425. *
  426. * @param \DateTime $updatedAt
  427. */
  428. public function setUpdatedAt($updatedAt = null): self
  429. {
  430. $this->updatedAt = $updatedAt ?? new \DateTime();
  431. return $this;
  432. }
  433. /**
  434. * Get updatedAt
  435. *
  436. * @return \DateTime
  437. */
  438. public function getUpdatedAt()
  439. {
  440. return $this->updatedAt;
  441. }
  442. /**
  443. * Set payed
  444. *
  445. * @param boolean $payed
  446. */
  447. public function setPayed($payed): self
  448. {
  449. $this->payed = $payed;
  450. return $this;
  451. }
  452. public function isPayed(): bool
  453. {
  454. return $this->payed ?? false;
  455. }
  456. /**
  457. * Get payed
  458. *
  459. * @return boolean
  460. */
  461. public function getPayed()
  462. {
  463. return $this->payed ?? false;
  464. }
  465. /**
  466. * Set subtotal
  467. *
  468. *
  469. */
  470. public function setSubtotal(float $subtotal): self
  471. {
  472. $this->subtotal = $this->round($subtotal);
  473. return $this;
  474. }
  475. /**
  476. * Get subtotal
  477. *
  478. * @return float
  479. */
  480. public function getSubtotal()
  481. {
  482. return $this->subtotal;
  483. }
  484. /**
  485. * Set tax
  486. *
  487. *
  488. */
  489. public function setTax(float $tax): self
  490. {
  491. $this->tax = $this->round($tax);
  492. return $this;
  493. }
  494. /**
  495. * Get tax
  496. *
  497. * @return string
  498. */
  499. public function getTax()
  500. {
  501. return $this->tax;
  502. }
  503. /**
  504. * Set shippingPrice
  505. *
  506. *
  507. */
  508. public function setShippingPrice(float $shippingPrice): self
  509. {
  510. $this->shippingPrice = $this->round($shippingPrice);
  511. return $this;
  512. }
  513. /**
  514. * Get shippingPrice
  515. *
  516. * @return float
  517. */
  518. public function getShippingPrice()
  519. {
  520. return $this->shippingPrice;
  521. }
  522. /**
  523. * Set total
  524. *
  525. * @param float $total
  526. */
  527. public function setTotal($total): self
  528. {
  529. $this->total = $total;
  530. return $this;
  531. }
  532. /**
  533. * Get total
  534. *
  535. * @return float
  536. */
  537. public function getTotal()
  538. {
  539. return $this->total;
  540. }
  541. /**
  542. * Set invoiceCountry
  543. *
  544. * @param string $invoiceCountry
  545. */
  546. public function setInvoiceCountry($invoiceCountry): self
  547. {
  548. $this->invoiceCountry = $invoiceCountry;
  549. return $this;
  550. }
  551. /**
  552. * Get invoiceCountry
  553. *
  554. * @return string
  555. */
  556. public function getInvoiceCountry()
  557. {
  558. return $this->invoiceCountry;
  559. }
  560. /**
  561. * Set invoiceState
  562. *
  563. * @param string $invoiceState
  564. */
  565. public function setInvoiceState($invoiceState): self
  566. {
  567. $this->invoiceState = $invoiceState;
  568. return $this;
  569. }
  570. /**
  571. * Get invoiceState
  572. *
  573. * @return string
  574. */
  575. public function getInvoiceState()
  576. {
  577. return $this->invoiceState;
  578. }
  579. /**
  580. * Set invoiceCity
  581. *
  582. * @param string $invoiceCity
  583. */
  584. public function setInvoiceCity($invoiceCity): self
  585. {
  586. $this->invoiceCity = $invoiceCity;
  587. return $this;
  588. }
  589. /**
  590. * Get invoiceCity
  591. *
  592. * @return string
  593. */
  594. public function getInvoiceCity()
  595. {
  596. return $this->invoiceCity;
  597. }
  598. /**
  599. * Set invoiceZip
  600. *
  601. * @param string $invoiceZip
  602. */
  603. public function setInvoiceZip($invoiceZip): self
  604. {
  605. $this->invoiceZip = $invoiceZip;
  606. return $this;
  607. }
  608. /**
  609. * Get invoiceZip
  610. *
  611. * @return string
  612. */
  613. public function getInvoiceZip()
  614. {
  615. return $this->invoiceZip;
  616. }
  617. /**
  618. * Set invoiceAddress
  619. *
  620. * @param string $invoiceAddress
  621. */
  622. public function setInvoiceAddress($invoiceAddress): self
  623. {
  624. $this->invoiceAddress = $invoiceAddress;
  625. return $this;
  626. }
  627. /**
  628. * Get invoiceAddress
  629. *
  630. * @return string
  631. */
  632. public function getInvoiceAddress()
  633. {
  634. return $this->invoiceAddress;
  635. }
  636. /**
  637. * Set invoicePhone
  638. *
  639. * @param string $invoicePhone
  640. */
  641. public function setInvoicePhone($invoicePhone): self
  642. {
  643. $this->invoicePhone = $invoicePhone;
  644. return $this;
  645. }
  646. /**
  647. * Get invoicePhone
  648. *
  649. * @return string
  650. */
  651. public function getInvoicePhone()
  652. {
  653. return $this->invoicePhone;
  654. }
  655. /**
  656. * Set shippingCountry
  657. *
  658. * @param string $shippingCountry
  659. */
  660. public function setShippingCountry($shippingCountry): self
  661. {
  662. $this->shippingCountry = $shippingCountry;
  663. return $this;
  664. }
  665. /**
  666. * Get shippingCountry
  667. *
  668. * @return string
  669. */
  670. public function getShippingCountry()
  671. {
  672. return $this->shippingCountry;
  673. }
  674. /**
  675. * Set shippingState
  676. *
  677. * @param string $shippingState
  678. */
  679. public function setShippingState($shippingState): self
  680. {
  681. $this->shippingState = $shippingState;
  682. return $this;
  683. }
  684. /**
  685. * Get shippingState
  686. *
  687. * @return string
  688. */
  689. public function getShippingState()
  690. {
  691. return $this->shippingState;
  692. }
  693. /**
  694. * Set shippingCity
  695. *
  696. * @param string $shippingCity
  697. */
  698. public function setShippingCity($shippingCity): self
  699. {
  700. $this->shippingCity = $shippingCity;
  701. return $this;
  702. }
  703. /**
  704. * Get shippingCity
  705. *
  706. * @return string
  707. */
  708. public function getShippingCity()
  709. {
  710. return $this->shippingCity;
  711. }
  712. /**
  713. * Set shippingZip
  714. *
  715. * @param string $shippingZip
  716. */
  717. public function setShippingZip($shippingZip): self
  718. {
  719. $this->shippingZip = $shippingZip;
  720. return $this;
  721. }
  722. /**
  723. * Get shippingZip
  724. *
  725. * @return string
  726. */
  727. public function getShippingZip()
  728. {
  729. return $this->shippingZip;
  730. }
  731. /**
  732. * Set shippingAddress
  733. *
  734. * @param string $shippingAddress
  735. */
  736. public function setShippingAddress($shippingAddress): self
  737. {
  738. $this->shippingAddress = $shippingAddress;
  739. return $this;
  740. }
  741. /**
  742. * Get shippingAddress
  743. *
  744. * @return string
  745. */
  746. public function getShippingAddress()
  747. {
  748. return $this->shippingAddress;
  749. }
  750. /**
  751. * Set shippingPhone
  752. *
  753. * @param string $shippingPhone
  754. */
  755. public function setShippingPhone($shippingPhone): self
  756. {
  757. $this->shippingPhone = $shippingPhone;
  758. return $this;
  759. }
  760. /**
  761. * Get shippingPhone
  762. *
  763. * @return string
  764. */
  765. public function getShippingPhone()
  766. {
  767. return $this->shippingPhone;
  768. }
  769. /**
  770. * Set shippingDatesConfirmed.
  771. *
  772. * @param bool $shippingDatesConfirmed
  773. */
  774. public function setShippingDatesConfirmed($shippingDatesConfirmed): static
  775. {
  776. $this->shippingDatesConfirmed = $shippingDatesConfirmed;
  777. return $this;
  778. }
  779. /**
  780. * Get shippingDatesConfirmed.
  781. *
  782. * @return bool
  783. */
  784. public function getShippingDatesConfirmed()
  785. {
  786. return $this->shippingDatesConfirmed;
  787. }
  788. /**
  789. * Set shippingLocationChanged
  790. *
  791. *
  792. */
  793. public function setShippingLocationChanged(bool $shippingLocationChanged): self
  794. {
  795. $this->shippingLocationChanged = $shippingLocationChanged;
  796. return $this;
  797. }
  798. /**
  799. * Get shippingLocationChanged
  800. *
  801. * @return boolean
  802. */
  803. public function getShippingLocationChanged()
  804. {
  805. return $this->shippingLocationChanged;
  806. }
  807. /**
  808. * Set currency
  809. *
  810. * @param string $currency
  811. */
  812. public function setCurrency($currency): self
  813. {
  814. $this->currency = $currency;
  815. return $this;
  816. }
  817. /**
  818. * Get currency
  819. *
  820. * @return Currency
  821. */
  822. public function getCurrency()
  823. {
  824. return $this->currency;
  825. }
  826. /**
  827. * Set checkedOut
  828. *
  829. * @param boolean $checkedOut
  830. */
  831. public function setCheckedOut($checkedOut): self
  832. {
  833. $this->checkedOut = $checkedOut;
  834. return $this;
  835. }
  836. /**
  837. * Get checkedOut
  838. */
  839. public function getCheckedOut(): bool
  840. {
  841. return $this->isCheckedOut();
  842. }
  843. /**
  844. * Get checkedOut
  845. */
  846. public function isCheckedOut(): bool
  847. {
  848. return $this->checkedOut ?? false;
  849. }
  850. /**
  851. * Set checkedOutAt
  852. *
  853. * @param \DateTime $checkedOutAt
  854. */
  855. public function setCheckedOutAt($checkedOutAt=null): self
  856. {
  857. $this->checkedOutAt = $checkedOutAt ?? new \DateTime();
  858. return $this;
  859. }
  860. /**
  861. * Get checkedOutAt
  862. *
  863. * @return \DateTime
  864. */
  865. public function getCheckedOutAt()
  866. {
  867. return $this->checkedOutAt;
  868. }
  869. /**
  870. * Set shipped
  871. *
  872. * @param boolean $shipped
  873. */
  874. public function setShipped($shipped): self
  875. {
  876. $this->shipped = $shipped;
  877. return $this;
  878. }
  879. /**
  880. * Get shipped
  881. */
  882. public function getShipped(): bool
  883. {
  884. return $this->isShipped();
  885. }
  886. public function isShipped(): bool
  887. {
  888. return $this->shipped ?? false;
  889. }
  890. /**
  891. * Set shippedAt
  892. *
  893. * @param \DateTime $shippedAt
  894. */
  895. public function setShippedAt($shippedAt): self
  896. {
  897. $this->shippedAt = $shippedAt;
  898. return $this;
  899. }
  900. /**
  901. * Get shippedAt
  902. *
  903. * @return \DateTime
  904. */
  905. public function getShippedAt()
  906. {
  907. return $this->shippedAt;
  908. }
  909. /**
  910. * Add shipping
  911. *
  912. *
  913. */
  914. public function setShipping(Shipping $shipping): self
  915. {
  916. $this->shipping = $shipping;
  917. return $this;
  918. }
  919. /**
  920. * Get shipping
  921. *
  922. * @return Shipping
  923. */
  924. public function getShipping()
  925. {
  926. return $this->shipping;
  927. }
  928. /**
  929. * Set currencyRate
  930. *
  931. * @param string $currencyRate
  932. */
  933. public function setCurrencyRate($currencyRate): self
  934. {
  935. $this->currencyRate = $currencyRate;
  936. return $this;
  937. }
  938. /**
  939. * Get currencyRate
  940. *
  941. * @return string
  942. */
  943. public function getCurrencyRate()
  944. {
  945. return $this->currencyRate;
  946. }
  947. /**
  948. * Set subtotalConverted
  949. *
  950. *
  951. */
  952. public function setSubtotalConverted(float $subtotalConverted): self
  953. {
  954. $this->subtotalConverted = $this->round($subtotalConverted);
  955. return $this;
  956. }
  957. /**
  958. * Get subtotalConverted
  959. *
  960. * @return float
  961. */
  962. public function getSubtotalConverted()
  963. {
  964. return $this->subtotalConverted;
  965. }
  966. /**
  967. * Set taxConverted
  968. *
  969. *
  970. */
  971. public function setTaxConverted(float $taxConverted): self
  972. {
  973. $this->taxConverted = $this->round($taxConverted);
  974. return $this;
  975. }
  976. /**
  977. * Get taxConverted
  978. *
  979. * @return string
  980. */
  981. public function getTaxConverted()
  982. {
  983. return $this->taxConverted;
  984. }
  985. /**
  986. * Set totalConverted
  987. *
  988. *
  989. */
  990. public function setTotalConverted(float $totalConverted): self
  991. {
  992. $this->totalConverted = $this->round($totalConverted);
  993. return $this;
  994. }
  995. /**
  996. * Get totalConverted
  997. *
  998. * @return string
  999. */
  1000. public function getTotalConverted()
  1001. {
  1002. return $this->totalConverted;
  1003. }
  1004. /**
  1005. * Set shippingPriceConverted
  1006. *
  1007. *
  1008. */
  1009. public function setShippingPriceConverted(float $shippingPriceConverted): self
  1010. {
  1011. $this->shippingPriceConverted = $this->round($shippingPriceConverted);
  1012. return $this;
  1013. }
  1014. /**
  1015. * Get shippingPriceConverted
  1016. *
  1017. * @return string
  1018. */
  1019. public function getShippingPriceConverted()
  1020. {
  1021. return $this->shippingPriceConverted;
  1022. }
  1023. /**
  1024. * Set rebate
  1025. *
  1026. *
  1027. */
  1028. public function setRebate(float $rebate): self
  1029. {
  1030. $this->rebate = $rebate;
  1031. return $this;
  1032. }
  1033. /**
  1034. * Get rebate
  1035. */
  1036. public function getRebate(): float
  1037. {
  1038. return (float) $this->rebate;
  1039. }
  1040. /**
  1041. * Set rebateConverted
  1042. *
  1043. *
  1044. */
  1045. public function setRebateConverted(float $rebateConverted): self
  1046. {
  1047. $this->rebateConverted = $rebateConverted;
  1048. return $this;
  1049. }
  1050. /**
  1051. * Get rebateConverted
  1052. */
  1053. public function getRebateConverted(): float
  1054. {
  1055. return (float) $this->rebateConverted;
  1056. }
  1057. /**
  1058. * Set invoice
  1059. *
  1060. * @param Invoice|null $invoice
  1061. */
  1062. public function setInvoice(Invoice $invoice = null): self
  1063. {
  1064. $this->invoice = $invoice;
  1065. return $this;
  1066. }
  1067. /**
  1068. * Get invoice
  1069. *
  1070. * @return Invoice
  1071. */
  1072. public function getInvoice(): ?Invoice
  1073. {
  1074. return $this->invoice;
  1075. }
  1076. /**
  1077. * Set client
  1078. *
  1079. *
  1080. */
  1081. public function setClient(Client $client = null): self
  1082. {
  1083. $this->client = $client;
  1084. return $this;
  1085. }
  1086. /**
  1087. * Get client
  1088. *
  1089. * @return Client
  1090. */
  1091. public function getClient()
  1092. {
  1093. return $this->client;
  1094. }
  1095. /**
  1096. * Set items
  1097. *
  1098. *
  1099. * @return $this
  1100. */
  1101. public function setItems(array $items): static
  1102. {
  1103. $this->items = new ArrayCollection($items);
  1104. return $this;
  1105. }
  1106. /**
  1107. * Add item
  1108. *
  1109. *
  1110. */
  1111. public function addItem(CartItem $item): self
  1112. {
  1113. $this->items[] = $item->setCart($this);
  1114. return $this;
  1115. }
  1116. /**
  1117. * Remove item
  1118. */
  1119. public function removeItem(CartItem $item): void
  1120. {
  1121. $this->items->removeElement($item);
  1122. }
  1123. /**
  1124. * Get items
  1125. */
  1126. public function getItems(): Collection
  1127. {
  1128. return $this->items;
  1129. }
  1130. public function hasItems(): bool
  1131. {
  1132. return !$this->items->isEmpty();
  1133. }
  1134. public function countItems(): int
  1135. {
  1136. if (!$this->hasItems()) {
  1137. return 0;
  1138. }
  1139. $items = array_map(fn(CartItem $item): ?int => $item->getQuantity(), $this->items->toArray());
  1140. return array_sum($items);
  1141. }
  1142. /**
  1143. * Set user
  1144. *
  1145. *
  1146. */
  1147. public function setUser(User $user = null): self
  1148. {
  1149. $this->user = $user;
  1150. return $this;
  1151. }
  1152. /**
  1153. * Get user
  1154. */
  1155. public function getUser(): User
  1156. {
  1157. return $this->user;
  1158. }
  1159. /**
  1160. * Round numbers
  1161. *
  1162. *
  1163. */
  1164. private function round(float $amount): float
  1165. {
  1166. return round($amount, self::ROUNDING_PRECISION);
  1167. }
  1168. }