vendor/roothirsch/tuer24-bundle/src/Entity/Tuer24Order.php line 13

Open in your IDE?
  1. <?php
  2. namespace Roothirsch\Tuer24Bundle\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Roothirsch\Tuer24Bundle\Repository\Tuer24OrderRepository;
  7. #[ORM\Entity(repositoryClass: "Roothirsch\Tuer24Bundle\Repository\Tuer24OrderRepository")]
  8. #[ORM\Table(name: 'roothirsch_tuer24_order')]
  9. #[ORM\HasLifecycleCallbacks]
  10. class Tuer24Order
  11. {
  12. #[ORM\Id]
  13. #[ORM\GeneratedValue]
  14. #[ORM\Column]
  15. private ?int $id = null;
  16. #[ORM\Column(nullable: true)]
  17. private ?int $userId = null;
  18. #[ORM\Column(nullable: true)]
  19. private ?int $companyId = null;
  20. #[ORM\Column(type: 'decimal', precision: 15, scale: 2)]
  21. private ?string $totalPrice = '0.00';
  22. #[ORM\Column(length: 20)]
  23. private ?string $status = 'new';
  24. #[ORM\Column(nullable: true)]
  25. private ?int $shippingAddressId = null;
  26. #[ORM\Column(nullable: true)]
  27. private ?int $billingAddressId = null;
  28. #[ORM\Column(length: 100, nullable: true)]
  29. private ?string $shippingMethod = null;
  30. #[ORM\Column(length: 100, nullable: true)]
  31. private ?string $paymentMethod = null;
  32. #[ORM\Column(length: 50)]
  33. private ?string $paymentStatus = 'pending';
  34. #[ORM\Column(length: 255, nullable: true)]
  35. private ?string $paymentReference = null;
  36. #[ORM\Column(type: 'datetime_immutable', nullable: true)]
  37. private ?\DateTimeImmutable $paidAt = null;
  38. #[ORM\OneToMany(mappedBy: 'order', targetEntity: Tuer24OrderItem::class, orphanRemoval: true, cascade: ['persist', 'remove'])]
  39. private Collection $items;
  40. #[ORM\Column]
  41. private ?\DateTimeImmutable $createdAt = null;
  42. #[ORM\Column]
  43. private ?\DateTimeImmutable $updatedAt = null;
  44. #[ORM\Column(length: 255, nullable: true)]
  45. private ?string $notes = null;
  46. public function __construct()
  47. {
  48. $this->items = new ArrayCollection();
  49. $this->createdAt = new \DateTimeImmutable();
  50. $this->updatedAt = new \DateTimeImmutable();
  51. }
  52. #[ORM\PreUpdate]
  53. public function preUpdate(): void
  54. {
  55. $this->updatedAt = new \DateTimeImmutable();
  56. }
  57. public function getId(): ?int
  58. {
  59. return $this->id;
  60. }
  61. public function getUserId(): ?int
  62. {
  63. return $this->userId;
  64. }
  65. public function setUserId(?int $userId): self
  66. {
  67. $this->userId = $userId;
  68. return $this;
  69. }
  70. public function getCompanyId(): ?int
  71. {
  72. return $this->companyId;
  73. }
  74. public function setCompanyId(?int $companyId): self
  75. {
  76. $this->companyId = $companyId;
  77. return $this;
  78. }
  79. public function getTotalPrice(): ?string
  80. {
  81. return $this->totalPrice;
  82. }
  83. public function getTotalPriceAsFloat(): ?float
  84. {
  85. return $this->totalPrice !== null ? (float)$this->totalPrice : null;
  86. }
  87. public function setTotalPrice(string|float $totalPrice): self
  88. {
  89. $this->totalPrice = (string)$totalPrice;
  90. return $this;
  91. }
  92. public function calculateTotalPrice(): self
  93. {
  94. $total = 0.0;
  95. foreach ($this->items as $item) {
  96. $total += (float)$item->getTotal();
  97. }
  98. $this->totalPrice = (string)$total;
  99. return $this;
  100. }
  101. public function getStatus(): ?string
  102. {
  103. return $this->status;
  104. }
  105. public function setStatus(string $status): self
  106. {
  107. $this->status = $status;
  108. return $this;
  109. }
  110. public function getShippingAddressId(): ?int
  111. {
  112. return $this->shippingAddressId;
  113. }
  114. public function setShippingAddressId(?int $shippingAddressId): self
  115. {
  116. $this->shippingAddressId = $shippingAddressId;
  117. return $this;
  118. }
  119. public function getBillingAddressId(): ?int
  120. {
  121. return $this->billingAddressId;
  122. }
  123. public function setBillingAddressId(?int $billingAddressId): self
  124. {
  125. $this->billingAddressId = $billingAddressId;
  126. return $this;
  127. }
  128. public function getShippingMethod(): ?string
  129. {
  130. return $this->shippingMethod;
  131. }
  132. public function setShippingMethod(?string $shippingMethod): self
  133. {
  134. $this->shippingMethod = $shippingMethod;
  135. return $this;
  136. }
  137. public function getPaymentMethod(): ?string
  138. {
  139. return $this->paymentMethod;
  140. }
  141. public function setPaymentMethod(?string $paymentMethod): self
  142. {
  143. $this->paymentMethod = $paymentMethod;
  144. return $this;
  145. }
  146. public function getPaymentStatus(): ?string
  147. {
  148. return $this->paymentStatus;
  149. }
  150. public function setPaymentStatus(string $paymentStatus): self
  151. {
  152. $this->paymentStatus = $paymentStatus;
  153. return $this;
  154. }
  155. public function getPaymentReference(): ?string
  156. {
  157. return $this->paymentReference;
  158. }
  159. public function setPaymentReference(?string $paymentReference): self
  160. {
  161. $this->paymentReference = $paymentReference;
  162. return $this;
  163. }
  164. public function getPaidAt(): ?\DateTimeImmutable
  165. {
  166. return $this->paidAt;
  167. }
  168. public function setPaidAt(?\DateTimeImmutable $paidAt): self
  169. {
  170. $this->paidAt = $paidAt;
  171. return $this;
  172. }
  173. public function markAsPaid(?string $paymentReference = null): self
  174. {
  175. $this->paymentStatus = 'paid';
  176. if ($paymentReference) {
  177. $this->paymentReference = $paymentReference;
  178. }
  179. $this->paidAt = new \DateTimeImmutable();
  180. return $this;
  181. }
  182. /**
  183. * @return Collection<int, Tuer24OrderItem>
  184. */
  185. public function getItems(): Collection
  186. {
  187. return $this->items;
  188. }
  189. public function addItem(Tuer24OrderItem $item): self
  190. {
  191. if (!$this->items->contains($item)) {
  192. $this->items->add($item);
  193. $item->setOrder($this);
  194. }
  195. return $this;
  196. }
  197. public function removeItem(Tuer24OrderItem $item): self
  198. {
  199. if ($this->items->removeElement($item)) {
  200. if ($item->getOrder() === $this) {
  201. $item->setOrder(null);
  202. }
  203. }
  204. return $this;
  205. }
  206. public function clearItems(): self
  207. {
  208. $this->items->clear();
  209. return $this;
  210. }
  211. public function countItems(): int
  212. {
  213. return $this->items->count();
  214. }
  215. public function getTotalQuantity(): int
  216. {
  217. $quantity = 0;
  218. foreach ($this->items as $item) {
  219. $quantity += $item->getQuantity();
  220. }
  221. return $quantity;
  222. }
  223. public function getCreatedAt(): ?\DateTimeImmutable
  224. {
  225. return $this->createdAt;
  226. }
  227. public function setCreatedAt(\DateTimeImmutable $createdAt): self
  228. {
  229. $this->createdAt = $createdAt;
  230. return $this;
  231. }
  232. public function getUpdatedAt(): ?\DateTimeImmutable
  233. {
  234. return $this->updatedAt;
  235. }
  236. public function setUpdatedAt(\DateTimeImmutable $updatedAt): self
  237. {
  238. $this->updatedAt = $updatedAt;
  239. return $this;
  240. }
  241. public function getNotes(): ?string
  242. {
  243. return $this->notes;
  244. }
  245. public function setNotes(?string $notes): self
  246. {
  247. $this->notes = $notes;
  248. return $this;
  249. }
  250. }