src/Entity/ECommerce/ProductCategory.php line 23

Open in your IDE?
  1. <?php
  2. namespace App\Entity\ECommerce;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use App\Entity\ECommerce\Traits\DatesInterface;
  7. use App\Entity\ECommerce\Traits\DatesTrait;
  8. use Knp\DoctrineBehaviors\Contract\Entity\TranslatableInterface;
  9. use Knp\DoctrineBehaviors\Model\Translatable\TranslatableTrait;
  10. /**
  11. * Category
  12. *
  13. * @ORM\Table(name="product_category", indexes={
  14. * @ORM\Index(name="product_category_ids", columns={"id", "remote_id"}),
  15. * })
  16. *
  17. * @ORM\Entity(repositoryClass="App\Repository\ECommerce\ProductCategoryRepository")
  18. * @ORM\Cache(usage="READ_ONLY", region="public")
  19. */
  20. class ProductCategory implements DatesInterface, TranslatableInterface, \Stringable
  21. {
  22. use TranslatableTrait;
  23. use DatesTrait {
  24. DatesTrait::__construct as __D_construct;
  25. }
  26. /**
  27. * @var int
  28. *
  29. * @ORM\Column(name="id", type="integer")
  30. * @ORM\Id
  31. * @ORM\GeneratedValue(strategy="AUTO")
  32. */
  33. private $id;
  34. /**
  35. * @var int
  36. *
  37. * @ORM\Column(name="remote_id", type="integer", nullable=true)
  38. */
  39. private $remote_id;
  40. /**
  41. * @var ArrayCollection
  42. *
  43. * @ORM\OneToMany(targetEntity="App\Entity\ECommerce\Product", mappedBy="category")
  44. */
  45. private $products;
  46. /**
  47. * @var ArrayCollection
  48. *
  49. * @ORM\OneToMany(targetEntity="App\Entity\ECommerce\ProductSubCategory", mappedBy="category")
  50. */
  51. private $subCategories;
  52. /**
  53. * Category constructor.
  54. */
  55. public function __construct()
  56. {
  57. $this->__D_construct();
  58. $this->products = new ArrayCollection();
  59. }
  60. public function __toString(): string
  61. {
  62. return (string) $this->translate()->getName();
  63. }
  64. /**
  65. * Get id
  66. *
  67. * @return int
  68. */
  69. public function getId()
  70. {
  71. return $this->id;
  72. }
  73. /**
  74. * Add product
  75. *
  76. *
  77. */
  78. public function addProduct(Product $product): ProductCategory
  79. {
  80. $this->products[] = $product;
  81. return $this;
  82. }
  83. /**
  84. * Remove product
  85. */
  86. public function removeProduct(Product $product): void
  87. {
  88. $this->products->removeElement($product);
  89. }
  90. /**
  91. * Get products
  92. */
  93. public function getProducts(): Collection
  94. {
  95. return $this->products;
  96. }
  97. /**
  98. * Set remoteId
  99. *
  100. * @param integer $remoteId
  101. */
  102. public function setRemoteId($remoteId): static
  103. {
  104. $this->remote_id = $remoteId;
  105. return $this;
  106. }
  107. /**
  108. * Get remoteId
  109. *
  110. * @return integer
  111. */
  112. public function getRemoteId()
  113. {
  114. return $this->remote_id;
  115. }
  116. /**
  117. * Add subCategory
  118. *
  119. *
  120. */
  121. public function addSubCategory(\App\Entity\ECommerce\ProductSubCategory $subCategory): static
  122. {
  123. $this->subCategories[] = $subCategory;
  124. return $this;
  125. }
  126. /**
  127. * Remove subCategory
  128. */
  129. public function removeSubCategory(\App\Entity\ECommerce\ProductSubCategory $subCategory): void
  130. {
  131. $this->subCategories->removeElement($subCategory);
  132. }
  133. /**
  134. * Get subCategories
  135. *
  136. * @return \Doctrine\Common\Collections\Collection
  137. */
  138. public function getSubCategories()
  139. {
  140. return $this->subCategories;
  141. }
  142. }