src/Entity/SpecialPrice.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. /**
  5. * Specials
  6. *
  7. * @ORM\Table(name="specials")
  8. * @ORM\Entity(repositoryClass="App\Repository\SpecialPriceRepository")
  9. * @ORM\HasLifecycleCallbacks()
  10. */
  11. class SpecialPrice
  12. {
  13. /**
  14. * @var int
  15. *
  16. * @ORM\Column(name="specials_id", type="integer", nullable=false)
  17. * @ORM\Id
  18. * @ORM\GeneratedValue(strategy="IDENTITY")
  19. */
  20. private $id;
  21. /** *
  22. * @ORM\ManyToOne(targetEntity="App\Entity\Product")
  23. * @ORM\JoinColumn(name="products_id", referencedColumnName="products_id", onDelete="CASCADE")
  24. */
  25. private $product;
  26. /**
  27. * @ORM\Column(name="specials_new_products_price", type="decimal", precision=15, scale=4, nullable=false, options={"default"="0.0000"})
  28. */
  29. private $price = 0;
  30. /**
  31. * @var \DateTime|null
  32. *
  33. * @ORM\Column(name="specials_date_added", type="datetime", nullable=true)
  34. */
  35. private $dateAdded;
  36. /**
  37. * @var \DateTime|null
  38. *
  39. * @ORM\Column(name="specials_last_modified", type="datetime", nullable=true)
  40. */
  41. private $lastModified;
  42. /**
  43. * @var \DateTime|null
  44. *
  45. * @ORM\Column(name="expires_date", type="datetime", nullable=true)
  46. */
  47. private $expireDate;
  48. /**
  49. * @var \DateTime|null
  50. *
  51. * @ORM\Column(name="date_status_change", type="datetime", nullable=true)
  52. */
  53. private $startDate;
  54. /**
  55. * @var int
  56. *
  57. * @ORM\Column(name="status", type="integer", nullable=false, options={"default"="1"})
  58. */
  59. private $status;
  60. /** *
  61. * @ORM\ManyToOne(targetEntity="App\Entity\CustomerGroup")
  62. * @ORM\JoinColumn(name="customers_group_id", referencedColumnName="customers_group_id", nullable=true)
  63. */
  64. private $customersGroup;
  65. public function getId(): int {
  66. return $this->id;
  67. }
  68. public function getProduct() {
  69. return $this->product;
  70. }
  71. public function getPrice($withEcotax = false) {
  72. if($withEcotax){
  73. return round($this->price, 2)+$this->product->getEcotax();
  74. }
  75. return $this->price;
  76. }
  77. public function getDateAdded(): ?\DateTime {
  78. return $this->dateAdded;
  79. }
  80. public function getLastModified(): ?\DateTime {
  81. return $this->lastModified;
  82. }
  83. public function getExpireDate(): ?\DateTime {
  84. return $this->expireDate;
  85. }
  86. public function getStartDate(): ?\DateTime {
  87. return $this->startDate;
  88. }
  89. public function getStatus(): ?int {
  90. return $this->status;
  91. }
  92. public function getCustomersGroup(): ?CustomerGroup {
  93. return $this->customersGroup;
  94. }
  95. public function setProduct($product) {
  96. $this->product = $product;
  97. }
  98. public function setPrice($price) {
  99. if(is_string($price) && strpos($price, ',')){
  100. $price = floatval(str_replace(',', '.', $price));
  101. }
  102. $this->price = $price;
  103. }
  104. public function setDateAdded(?\DateTime $dateAdded) {
  105. $this->dateAdded = $dateAdded;
  106. }
  107. public function setLastModified(?\DateTime $lastModified) {
  108. $this->lastModified = $lastModified;
  109. }
  110. public function setExpireDate(?\DateTime $expireDate) {
  111. $this->expireDate = $expireDate;
  112. }
  113. public function setStartDate(?\DateTime $startDate) {
  114. $this->startDate = $startDate;
  115. }
  116. public function setStatus(int $status) {
  117. $this->status = $status;
  118. }
  119. public function setCustomersGroup(?CustomerGroup $customersGroup) {
  120. $this->customersGroup = $customersGroup;
  121. }
  122. public function toArray()
  123. {
  124. return [
  125. 'id'=>$this->getId(),
  126. 'product'=>$this->getProduct()->getName().' ('.$this->getProduct()->getModel().')',
  127. 'price'=>$this->getPrice(),
  128. 'startDate'=>empty($this->startDate)?null:$this->startDate->format('Y-m-d H:i:s'),
  129. 'expireDate'=>empty($this->expireDate)?null:$this->expireDate->format('Y-m-d H:i:s'),
  130. 'createdAt'=>empty($this->dateAdded)?null:$this->dateAdded->format('Y-m-d H:i:s')
  131. ];
  132. }
  133. /**
  134. * @ORM\PostLoad
  135. *
  136. * @todo Remove once 0 values in the table are converted to NULL.
  137. */
  138. public function postLoad(\Doctrine\ORM\Event\LifecycleEventArgs $args) {
  139. if ($this->customersGroup && $this->customersGroup->getId() == 0) {
  140. $this->customersGroup = null;
  141. }
  142. }
  143. }