src/Entity/CatalogProducts.php line 144

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Interfaces\DefaultLinkedEntity;
  4. use App\Entity\Traits\ActiveTrait;
  5. use App\Entity\Traits\DeleteTrait;
  6. use App\Entity\Traits\ImageUploadTrait;
  7. use App\Entity\Traits\LinkTrait;
  8. use App\Entity\Traits\MetaTrait;
  9. use App\Entity\Traits\TitleAndContentTrait;
  10. use App\Entity\Traits\TranslateTrait;
  11. use Doctrine\ORM\Mapping as ORM;
  12. use Gedmo\Mapping\Annotation as Gedmo;
  13. use Gedmo\Timestampable\Traits\TimestampableEntity;
  14. use Symfony\Component\Validator\Constraints as Assert;
  15. /**
  16. * Catalog.
  17. *
  18. * @Gedmo\Loggable
  19. *
  20. * @Gedmo\TranslationEntity(class="App\Entity\CatalogProductsTranslations")
  21. */
  22. #[ORM\Entity(repositoryClass: \App\Repository\CatalogRepository::class)]
  23. #[ORM\Table(name: 'catalog_products')]
  24. class CatalogProducts implements DefaultLinkedEntity
  25. {
  26. use TitleAndContentTrait;
  27. use MetaTrait;
  28. use LinkTrait;
  29. use ActiveTrait;
  30. use DeleteTrait;
  31. use ImageUploadTrait;
  32. use TimestampableEntity;
  33. use TranslateTrait;
  34. #[ORM\Column(name: 'id', type: 'integer')]
  35. #[ORM\Id]
  36. #[ORM\GeneratedValue(strategy: 'AUTO')]
  37. private readonly int $id;
  38. /**
  39. * @Gedmo\Translatable
  40. */
  41. #[ORM\Column(name: 'description', type: 'text', nullable: true)]
  42. private ?string $description = null;
  43. /**
  44. * @var string
  45. */
  46. #[Assert\NotBlank(message: 'The price should not be blank')]
  47. #[ORM\Column(type: 'decimal', precision: 8, scale: 2)]
  48. private $price;
  49. #[ORM\ManyToOne(targetEntity: 'CatalogCategories', inversedBy: 'products')]
  50. #[ORM\JoinColumn(name: 'category_id', referencedColumnName: 'id')]
  51. private ?CatalogCategories $category = null;
  52. /**
  53. * Get fullSlugPath.
  54. *
  55. * @return string
  56. */
  57. public function getFullSlugPath()
  58. {
  59. // this function generates a full url category path
  60. $url = [];
  61. $cat = $this->category;
  62. while (null != $cat) {
  63. $cat = $cat->getParent();
  64. if (null != $cat) {
  65. $url[] = $cat->getSlug();
  66. }
  67. }
  68. $urlrev = array_reverse($url);
  69. return '/'.implode('/', $urlrev).'/'.$this->category->getSlug().'/'.$this->getSlug();
  70. }
  71. /**
  72. * Get id.
  73. *
  74. * @return int
  75. */
  76. public function getId()
  77. {
  78. return $this->id;
  79. }
  80. /**
  81. * Set description.
  82. *
  83. * @param string $description
  84. *
  85. * @return CatalogProducts
  86. */
  87. public function setDescription($description)
  88. {
  89. $this->description = $description;
  90. return $this;
  91. }
  92. /**
  93. * Get description.
  94. *
  95. * @return string
  96. */
  97. public function getDescription()
  98. {
  99. return $this->description;
  100. }
  101. /**
  102. * Set price.
  103. *
  104. * @param string $price
  105. *
  106. * @return CatalogProducts
  107. */
  108. public function setPrice($price)
  109. {
  110. $this->price = $price;
  111. return $this;
  112. }
  113. /**
  114. * Get price.
  115. *
  116. * @return string
  117. */
  118. public function getPrice()
  119. {
  120. return $this->price;
  121. }
  122. /**
  123. * Set category.
  124. *
  125. * @return CatalogProducts
  126. */
  127. public function setCategory(CatalogCategories $category = null)
  128. {
  129. $this->category = $category;
  130. return $this;
  131. }
  132. /**
  133. * Get category.
  134. *
  135. * @return \App\Entity\CatalogCategories
  136. */
  137. public function getCategory()
  138. {
  139. return $this->category;
  140. }
  141. // REQUIRED BY THE META LINKS TRAIT
  142. public function getLinkedPageId(): int
  143. {
  144. // CW TODO _ SET THIS CORRECTLY
  145. return 0;
  146. }
  147. }