src/Entity/Product.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\SuperClass\BaseEntity;
  4. use App\Repository\ProductRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Gedmo\Mapping\Annotation as Gedmo;
  9. /**
  10. * @ORM\Entity(repositoryClass=ProductRepository::class)
  11. */
  12. class Product extends BaseEntity
  13. {
  14. /**
  15. * @ORM\Column(type="string", length=255)
  16. */
  17. private $name;
  18. /**
  19. * @ORM\Column(type="text")
  20. */
  21. private $metadata;
  22. /**
  23. * @ORM\Column(type="json")
  24. */
  25. private $description = [];
  26. /**
  27. * @ORM\ManyToOne(targetEntity=Category::class, inversedBy="products")
  28. * @ORM\JoinColumn(nullable=true)
  29. */
  30. private $category;
  31. /**
  32. * @ORM\Column(type="integer")
  33. */
  34. private $price;
  35. /**
  36. * @ORM\Column(type="integer")
  37. */
  38. private $discount;
  39. /**
  40. * @ORM\Column(type="boolean")
  41. */
  42. private $active;
  43. /**
  44. * @ORM\ManyToOne(targetEntity=User::class, inversedBy="products")
  45. */
  46. private $created_by;
  47. /**
  48. * @ORM\ManyToOne(targetEntity=Product::class, inversedBy="related_services")
  49. */
  50. private $product;
  51. /**
  52. * @ORM\OneToMany(targetEntity=Product::class, mappedBy="product")
  53. */
  54. private $related_services;
  55. /**
  56. * @ORM\Column(type="boolean")
  57. */
  58. private $can_ship;
  59. /**
  60. * @Gedmo\Slug(fields={"name"})
  61. * @ORM\Column(type="string", length=255)
  62. */
  63. private $slug;
  64. /**
  65. * @ORM\OneToMany(targetEntity=OrderItem::class, mappedBy="products")
  66. */
  67. private $orderItems;
  68. /**
  69. * @ORM\OneToMany(targetEntity=Installment::class, mappedBy="item")
  70. */
  71. private $installments;
  72. public function __construct()
  73. {
  74. $this->related_services = new ArrayCollection();
  75. $this->orderItems = new ArrayCollection();
  76. $this->installments = new ArrayCollection();
  77. }
  78. public function getId(): ?int
  79. {
  80. return $this->id;
  81. }
  82. public function getName(): ?string
  83. {
  84. return $this->name;
  85. }
  86. public function setName(string $name): self
  87. {
  88. $this->name = $name;
  89. return $this;
  90. }
  91. public function getDescription(): ?array
  92. {
  93. return $this->description;
  94. }
  95. public function setDescription(array $description): self
  96. {
  97. $this->description = $description;
  98. return $this;
  99. }
  100. public function getPrice(): ?int
  101. {
  102. return $this->price;
  103. }
  104. public function setPrice(int $price): self
  105. {
  106. $this->price = $price;
  107. return $this;
  108. }
  109. public function getCreatedBy(): ?User
  110. {
  111. return $this->created_by;
  112. }
  113. public function setCreatedBy(?User $created_by): self
  114. {
  115. $this->created_by = $created_by;
  116. return $this;
  117. }
  118. public function getActive(): ?bool
  119. {
  120. return $this->active;
  121. }
  122. public function setActive(bool $active): self
  123. {
  124. $this->active = $active;
  125. return $this;
  126. }
  127. public function getMetadata(): ?string
  128. {
  129. return $this->metadata;
  130. }
  131. public function setMetadata(string $metadata): self
  132. {
  133. $this->metadata = $metadata;
  134. return $this;
  135. }
  136. public function getDiscount(): ?float
  137. {
  138. return $this->discount;
  139. }
  140. public function setDiscount(float $discount): self
  141. {
  142. $this->discount = $discount;
  143. return $this;
  144. }
  145. public function getCategory(): ?Category
  146. {
  147. return $this->category;
  148. }
  149. public function setCategory(?Category $category): self
  150. {
  151. $this->category = $category;
  152. return $this;
  153. }
  154. public function getProduct(): ?self
  155. {
  156. return $this->product;
  157. }
  158. public function setProduct(?self $product): self
  159. {
  160. $this->product = $product;
  161. return $this;
  162. }
  163. /**
  164. * @return Collection|self[]
  165. */
  166. public function getRelatedServices(): Collection
  167. {
  168. return $this->related_services;
  169. }
  170. public function addRelatedService(self $relatedService): self
  171. {
  172. if (!$this->related_services->contains($relatedService)) {
  173. $this->related_services[] = $relatedService;
  174. $relatedService->setProduct($this);
  175. }
  176. return $this;
  177. }
  178. public function removeRelatedService(self $relatedService): self
  179. {
  180. if ($this->related_services->removeElement($relatedService)) {
  181. // set the owning side to null (unless already changed)
  182. if ($relatedService->getProduct() === $this) {
  183. $relatedService->setProduct(null);
  184. }
  185. }
  186. return $this;
  187. }
  188. public function getCanShip(): ?bool
  189. {
  190. return $this->can_ship;
  191. }
  192. public function setCanShip(bool $can_ship): self
  193. {
  194. $this->can_ship = $can_ship;
  195. return $this;
  196. }
  197. public function getSlug(): ?string
  198. {
  199. return $this->slug;
  200. }
  201. /**
  202. * @return Collection<int, OrderItem>
  203. */
  204. public function getOrderItems(): Collection
  205. {
  206. return $this->orderItems;
  207. }
  208. public function addOrderItem(OrderItem $orderItem): self
  209. {
  210. if (!$this->orderItems->contains($orderItem)) {
  211. $this->orderItems[] = $orderItem;
  212. $orderItem->setProducts($this);
  213. }
  214. return $this;
  215. }
  216. public function removeOrderItem(OrderItem $orderItem): self
  217. {
  218. if ($this->orderItems->removeElement($orderItem)) {
  219. // set the owning side to null (unless already changed)
  220. if ($orderItem->getProducts() === $this) {
  221. $orderItem->setProducts(null);
  222. }
  223. }
  224. return $this;
  225. }
  226. public function __toString()
  227. {
  228. return $this->getName();
  229. }
  230. /**
  231. * @return Collection<int, Installment>
  232. */
  233. public function getInstallments(): Collection
  234. {
  235. return $this->installments;
  236. }
  237. public function addInstallment(Installment $installment): self
  238. {
  239. if (!$this->installments->contains($installment)) {
  240. $this->installments[] = $installment;
  241. $installment->setItem($this);
  242. }
  243. return $this;
  244. }
  245. public function removeInstallment(Installment $installment): self
  246. {
  247. if ($this->installments->removeElement($installment)) {
  248. // set the owning side to null (unless already changed)
  249. if ($installment->getItem() === $this) {
  250. $installment->setItem(null);
  251. }
  252. }
  253. return $this;
  254. }
  255. }