src/ECommerceBundle/Entity/CartHasProductPrice.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\ECommerceBundle\Entity;
  3. use App\NewShippingBundle\Entity\ShippingTime;
  4. use App\ProductBundle\Entity\ProductPrice;
  5. use Doctrine\DBAL\Types\Types;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Component\Validator\Constraints as Assert;
  8. /**
  9. * @ORM\HasLifecycleCallbacks
  10. * @ORM\Table("cart_has_product_price")
  11. * @ORM\Entity(repositoryClass="App\ECommerceBundle\Repository\CartHasProductPriceRepository")
  12. */
  13. class CartHasProductPrice
  14. {
  15. /**
  16. * @Assert\NotBlank()
  17. * @ORM\Id
  18. * @ORM\ManyToOne(targetEntity="Cart", inversedBy="cartHasProductPrices")
  19. * @ORM\JoinColumn(name="cart_id", referencedColumnName="id", onDelete="CASCADE")
  20. */
  21. private ?Cart $cart = null;
  22. /**
  23. * @Assert\NotBlank()
  24. * @ORM\Id
  25. * @ORM\ManyToOne(targetEntity="App\ProductBundle\Entity\ProductPrice")
  26. */
  27. private ?ProductPrice $productPrice = null;
  28. /**
  29. * @ORM\ManyToOne(targetEntity="App\NewShippingBundle\Entity\ShippingTime")
  30. */
  31. private ?ShippingTime $shippingTime = null;
  32. /**
  33. * @Assert\NotBlank()
  34. * @ORM\Column(name="qty", type="integer", nullable=false)
  35. */
  36. private int $qty = 0;
  37. /**
  38. * @ORM\Column(name="created", type="datetime")
  39. */
  40. private ?\DateTimeInterface $created = null;
  41. /**
  42. * @ORM\Column(name="modified", type="datetime")
  43. */
  44. private ?\DateTimeInterface $modified = null;
  45. /**
  46. * @ORM\PrePersist()
  47. * @ORM\PreUpdate()
  48. */
  49. public function updatedTimestamps(): void
  50. {
  51. $this->setModified(new \DateTime(date('Y-m-d H:i:s')));
  52. if ($this->getCreated() == null) {
  53. $this->setCreated(new \DateTime(date('Y-m-d H:i:s')));
  54. }
  55. }
  56. public function getPrice(): ?float
  57. {
  58. return $this->getProductPrice()->getSellPrice() * $this->getQty();
  59. }
  60. public function getQty(): ?int
  61. {
  62. return $this->qty;
  63. }
  64. public function setQty(int $qty): self
  65. {
  66. $this->qty = $qty;
  67. return $this;
  68. }
  69. public function getCreated(): ?\DateTimeInterface
  70. {
  71. return $this->created;
  72. }
  73. public function setCreated(\DateTimeInterface $created): self
  74. {
  75. $this->created = $created;
  76. return $this;
  77. }
  78. public function getModified(): ?\DateTimeInterface
  79. {
  80. return $this->modified;
  81. }
  82. public function setModified(\DateTimeInterface $modified): self
  83. {
  84. $this->modified = $modified;
  85. return $this;
  86. }
  87. public function getCart(): ?Cart
  88. {
  89. return $this->cart;
  90. }
  91. public function setCart(?Cart $cart): self
  92. {
  93. $this->cart = $cart;
  94. return $this;
  95. }
  96. public function getProductPrice(): ?ProductPrice
  97. {
  98. return $this->productPrice;
  99. }
  100. public function setProductPrice(?ProductPrice $productPrice): self
  101. {
  102. $this->productPrice = $productPrice;
  103. return $this;
  104. }
  105. public function getShippingTime(): ?ShippingTime
  106. {
  107. return $this->shippingTime;
  108. }
  109. public function setShippingTime(?ShippingTime $shippingTime): static
  110. {
  111. $this->shippingTime = $shippingTime;
  112. return $this;
  113. }
  114. }