vendor/roothirsch/tuer24-bundle/src/Entity/Tuer24OrderItem.php line 10

Open in your IDE?
  1. <?php
  2. namespace Roothirsch\Tuer24Bundle\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use Roothirsch\Tuer24Bundle\Repository\Tuer24OrderItemRepository;
  5. #[ORM\Entity(repositoryClass: "Roothirsch\Tuer24Bundle\Repository\Tuer24OrderItemRepository")]
  6. #[ORM\Table(name: 'roothirsch_tuer24_order_item')]
  7. class Tuer24OrderItem
  8. {
  9. #[ORM\Id]
  10. #[ORM\GeneratedValue]
  11. #[ORM\Column]
  12. private ?int $id = null;
  13. #[ORM\ManyToOne(inversedBy: 'items')]
  14. #[ORM\JoinColumn(nullable: false)]
  15. private ?Tuer24Order $order = null;
  16. #[ORM\Column]
  17. private ?int $productId = null;
  18. #[ORM\Column(length: 255, nullable: true)]
  19. private ?string $productSku = null;
  20. #[ORM\Column(length: 255)]
  21. private ?string $productName = null;
  22. #[ORM\Column]
  23. private ?int $quantity = 0;
  24. #[ORM\Column(type: 'decimal', precision: 15, scale: 2)]
  25. private ?string $price = '0.00';
  26. #[ORM\Column(type: 'decimal', precision: 15, scale: 2)]
  27. private ?string $total = '0.00';
  28. public function __construct()
  29. {
  30. $this->calculateTotal();
  31. }
  32. public function getId(): ?int
  33. {
  34. return $this->id;
  35. }
  36. public function getOrder(): ?Tuer24Order
  37. {
  38. return $this->order;
  39. }
  40. public function setOrder(?Tuer24Order $order): self
  41. {
  42. $this->order = $order;
  43. return $this;
  44. }
  45. public function getProductId(): ?int
  46. {
  47. return $this->productId;
  48. }
  49. public function setProductId(int $productId): self
  50. {
  51. $this->productId = $productId;
  52. return $this;
  53. }
  54. public function getProductSku(): ?string
  55. {
  56. return $this->productSku;
  57. }
  58. public function setProductSku(?string $productSku): self
  59. {
  60. $this->productSku = $productSku;
  61. return $this;
  62. }
  63. public function getProductName(): ?string
  64. {
  65. return $this->productName;
  66. }
  67. public function setProductName(string $productName): self
  68. {
  69. $this->productName = $productName;
  70. return $this;
  71. }
  72. public function getQuantity(): ?int
  73. {
  74. return $this->quantity;
  75. }
  76. public function setQuantity(int $quantity): self
  77. {
  78. $this->quantity = $quantity;
  79. $this->calculateTotal();
  80. return $this;
  81. }
  82. public function getPrice(): ?string
  83. {
  84. return $this->price;
  85. }
  86. public function getPriceAsFloat(): ?float
  87. {
  88. return $this->price !== null ? (float)$this->price : null;
  89. }
  90. public function setPrice(string|float $price): self
  91. {
  92. $this->price = (string)$price;
  93. $this->calculateTotal();
  94. return $this;
  95. }
  96. public function getTotal(): ?string
  97. {
  98. return $this->total;
  99. }
  100. public function getTotalAsFloat(): ?float
  101. {
  102. return $this->total !== null ? (float)$this->total : null;
  103. }
  104. public function setTotal(string|float $total): self
  105. {
  106. $this->total = (string)$total;
  107. return $this;
  108. }
  109. public function calculateTotal(): self
  110. {
  111. $this->total = (string)((float)$this->price * $this->quantity);
  112. return $this;
  113. }
  114. }