vendor/roothirsch/tuer24-bundle/src/Entity/Tuer24CartItem.php line 11

Open in your IDE?
  1. <?php
  2. namespace Roothirsch\Tuer24Bundle\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use Roothirsch\Tuer24Bundle\Repository\Tuer24CartItemRepository;
  5. #[ORM\Entity(repositoryClass: "Roothirsch\Tuer24Bundle\Repository\Tuer24CartItemRepository")]
  6. #[ORM\Table(name: 'roothirsch_tuer24_cart_item')]
  7. #[ORM\HasLifecycleCallbacks]
  8. class Tuer24CartItem
  9. {
  10. #[ORM\Id]
  11. #[ORM\GeneratedValue]
  12. #[ORM\Column]
  13. private ?int $id = null;
  14. #[ORM\ManyToOne(inversedBy: 'items')]
  15. #[ORM\JoinColumn(nullable: false)]
  16. private ?Tuer24Cart $cart = null;
  17. #[ORM\Column]
  18. private ?int $productId = null;
  19. #[ORM\Column(length: 255)]
  20. private ?string $productSku = null;
  21. #[ORM\Column(length: 255)]
  22. private ?string $productName = null;
  23. #[ORM\Column]
  24. private ?float $price = null;
  25. #[ORM\Column]
  26. private ?int $quantity = null;
  27. #[ORM\Column(nullable: true)]
  28. private ?float $discountPercent = null;
  29. #[ORM\Column]
  30. private ?\DateTimeImmutable $createdAt = null;
  31. #[ORM\Column]
  32. private ?\DateTimeImmutable $updatedAt = null;
  33. public function __construct()
  34. {
  35. $this->createdAt = new \DateTimeImmutable();
  36. $this->updatedAt = new \DateTimeImmutable();
  37. $this->quantity = 1;
  38. }
  39. #[ORM\PreUpdate]
  40. public function preUpdate(): void
  41. {
  42. $this->updatedAt = new \DateTimeImmutable();
  43. }
  44. public function getId(): ?int
  45. {
  46. return $this->id;
  47. }
  48. public function getCart(): ?Tuer24Cart
  49. {
  50. return $this->cart;
  51. }
  52. public function setCart(?Tuer24Cart $cart): self
  53. {
  54. $this->cart = $cart;
  55. return $this;
  56. }
  57. public function getProductId(): ?int
  58. {
  59. return $this->productId;
  60. }
  61. public function setProductId(int $productId): self
  62. {
  63. $this->productId = $productId;
  64. return $this;
  65. }
  66. public function getProductSku(): ?string
  67. {
  68. return $this->productSku;
  69. }
  70. public function setProductSku(string $productSku): self
  71. {
  72. $this->productSku = $productSku;
  73. return $this;
  74. }
  75. public function getProductName(): ?string
  76. {
  77. return $this->productName;
  78. }
  79. public function setProductName(string $productName): self
  80. {
  81. $this->productName = $productName;
  82. return $this;
  83. }
  84. public function getPrice(): ?float
  85. {
  86. return $this->price;
  87. }
  88. public function setPrice(float $price): self
  89. {
  90. $this->price = $price;
  91. return $this;
  92. }
  93. public function getQuantity(): ?int
  94. {
  95. return $this->quantity;
  96. }
  97. public function setQuantity(int $quantity): self
  98. {
  99. $this->quantity = $quantity;
  100. return $this;
  101. }
  102. public function getDiscountPercent(): ?float
  103. {
  104. return $this->discountPercent;
  105. }
  106. public function setDiscountPercent(?float $discountPercent): self
  107. {
  108. $this->discountPercent = $discountPercent;
  109. return $this;
  110. }
  111. public function getDiscountAmount(): float
  112. {
  113. if ($this->discountPercent === null || $this->discountPercent <= 0) {
  114. return 0;
  115. }
  116. return $this->price * ($this->discountPercent / 100) * $this->quantity;
  117. }
  118. public function getSubtotal(): float
  119. {
  120. return $this->price * $this->quantity;
  121. }
  122. public function getTotal(): float
  123. {
  124. return $this->getSubtotal() - $this->getDiscountAmount();
  125. }
  126. public function getCreatedAt(): ?\DateTimeImmutable
  127. {
  128. return $this->createdAt;
  129. }
  130. public function setCreatedAt(\DateTimeImmutable $createdAt): self
  131. {
  132. $this->createdAt = $createdAt;
  133. return $this;
  134. }
  135. public function getUpdatedAt(): ?\DateTimeImmutable
  136. {
  137. return $this->updatedAt;
  138. }
  139. public function setUpdatedAt(\DateTimeImmutable $updatedAt): self
  140. {
  141. $this->updatedAt = $updatedAt;
  142. return $this;
  143. }
  144. }