src/Entity/Order.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\SuperClass\BaseEntity;
  4. use App\Repository\OrderRepository;
  5. use App\Validator\Cart\UniqueItem;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\ORM\Mapping as ORM;
  9. /**
  10. * @ORM\Entity(repositoryClass=OrderRepository::class)
  11. * @ORM\Table(name="`order`")
  12. */
  13. class Order extends BaseEntity
  14. {
  15. /**
  16. * An order that is in progress, not placed yet.
  17. *
  18. * @var string
  19. */
  20. public const STATUS_CART = 'cart';
  21. /**
  22. * @ORM\Column(type="string", length=255)
  23. */
  24. private $status = self::STATUS_CART;
  25. /**
  26. * @ORM\OneToMany(targetEntity=OrderItem::class, mappedBy="orderRef", cascade={"persist","remove"})
  27. * @UniqueItem()
  28. */
  29. private $orderItems;
  30. /**
  31. * @ORM\ManyToOne(targetEntity=Customer::class, inversedBy="orders")
  32. */
  33. private $customer;
  34. /**
  35. * @ORM\Column(type="datetime", nullable=true)
  36. */
  37. private $accepted_terms_at;
  38. /**
  39. * @ORM\Column(type="boolean")
  40. */
  41. private $public_accessable = true;
  42. /**
  43. * @ORM\ManyToOne(targetEntity=Source::class, cascade={"persist", "remove"})
  44. */
  45. private $source;
  46. /**
  47. * @ORM\ManyToOne(targetEntity=Address::class, cascade={"persist", "remove"})
  48. */
  49. private $billing;
  50. /**
  51. * @ORM\ManyToOne(targetEntity=Address::class, cascade={"persist", "remove"})
  52. */
  53. private $shipping;
  54. public function __construct()
  55. {
  56. $this->orderItems = new ArrayCollection();
  57. }
  58. public function getStatus(): ?string
  59. {
  60. return $this->status;
  61. }
  62. public function setStatus(string $status): self
  63. {
  64. $this->status = $status;
  65. return $this;
  66. }
  67. /**
  68. * @return Collection<int, OrderItem>
  69. */
  70. public function getOrderItems(): Collection
  71. {
  72. return $this->orderItems;
  73. }
  74. public function addOrderItem(OrderItem $orderItem): self
  75. {
  76. if (!$this->orderItems->contains($orderItem)) {
  77. $this->orderItems[] = $orderItem;
  78. $orderItem->setOrderRef($this);
  79. }
  80. return $this;
  81. }
  82. public function removeOrderItem(OrderItem $orderItem): self
  83. {
  84. if ($this->orderItems->removeElement($orderItem)) {
  85. // set the owning side to null (unless already changed)
  86. if ($orderItem->getOrderRef() === $this) {
  87. $orderItem->setOrderRef(null);
  88. }
  89. }
  90. return $this;
  91. }
  92. /**
  93. * Calculates the order total.
  94. */
  95. public function getTotal(): float
  96. {
  97. $total = 0;
  98. foreach ($this->getOrderItems() as $item) {
  99. $total += $item->getPaymentOption()->getAmount();
  100. }
  101. return $total;
  102. }
  103. public function getCustomer(): ?Customer
  104. {
  105. return $this->customer;
  106. }
  107. public function setCustomer(?Customer $customer): self
  108. {
  109. $this->customer = $customer;
  110. return $this;
  111. }
  112. public function getAcceptedTermsAt(): ?\DateTimeInterface
  113. {
  114. return $this->accepted_terms_at;
  115. }
  116. public function setAcceptedTermsAt(?\DateTimeInterface $accepted_terms_at): self
  117. {
  118. $this->accepted_terms_at = $accepted_terms_at;
  119. return $this;
  120. }
  121. public function isPublicAccessable(): ?bool
  122. {
  123. return $this->public_accessable;
  124. }
  125. public function setPublicAccessable(bool $public_accessable): self
  126. {
  127. $this->public_accessable = $public_accessable;
  128. return $this;
  129. }
  130. public function getSource(): ?Source
  131. {
  132. return $this->source;
  133. }
  134. public function setSource(?Source $source): self
  135. {
  136. $this->source = $source;
  137. return $this;
  138. }
  139. public function getBilling(): ?Address
  140. {
  141. return $this->billing;
  142. }
  143. public function setBilling(?Address $billing): self
  144. {
  145. $this->billing = $billing;
  146. return $this;
  147. }
  148. public function getShipping(): ?Address
  149. {
  150. return $this->shipping;
  151. }
  152. public function setShipping(?Address $shipping): self
  153. {
  154. $this->shipping = $shipping;
  155. return $this;
  156. }
  157. }