src/Entity/CustomerProduct.php line 23

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Interfaces\ProductInterface;
  4. use App\Repository\CustomerProductRepository;
  5. use App\Traits\DateTrait;
  6. use DateTime;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use JMS\Serializer\Annotation as Serializer;
  9. use JMS\Serializer\Annotation\Expose;
  10. use JMS\Serializer\Annotation\Groups;
  11. use Symfony\Component\HttpFoundation\File\File;
  12. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  13. /**
  14. * @ORM\Entity(repositoryClass=CustomerProductRepository::class)
  15. * @ORM\HasLifecycleCallbacks()
  16. *
  17. * @Vich\Uploadable
  18. * @Serializer\ExclusionPolicy("ALL")
  19. */
  20. class CustomerProduct implements ProductInterface
  21. {
  22. /**
  23. * @ORM\Id
  24. * @ORM\GeneratedValue
  25. * @ORM\Column(type="integer")
  26. *
  27. * @Expose()
  28. * @Groups({"id"})
  29. */
  30. private ?int $id = null;
  31. /**
  32. * Référence
  33. * @ORM\Column(type="string", length=255)
  34. *
  35. * @Expose
  36. * @Groups({"sku"})
  37. */
  38. private ?string $sku = null;
  39. /**
  40. * @ORM\Column(type="string", length=255)
  41. *
  42. * @Expose()
  43. * @Groups({"name"})
  44. */
  45. private ?string $name = null;
  46. /**
  47. * @ORM\Column(type="text", nullable=true)
  48. */
  49. private ?string $description = null;
  50. /**
  51. * @ORM\Column(type="string", length=255, nullable=true)
  52. *
  53. * @Expose()
  54. * @Serializer\Groups({"image"})
  55. */
  56. private ?string $image = null;
  57. // Vich Uploader
  58. /**
  59. * @Vich\UploadableField(mapping="customer_product_images", fileNameProperty="image")
  60. * @var File
  61. */
  62. private $imageFile;
  63. /**
  64. * @ORM\Column(type="float", nullable=true)
  65. */
  66. private ?float $ratePrice = null;
  67. /**
  68. * @ORM\Column(type="text", nullable=true)
  69. */
  70. private ?string $categoryValues = null;
  71. /**
  72. * @ORM\Column(type="string", length=128, nullable=true)
  73. *
  74. * @Expose()
  75. * @Serializer\Groups({"category"})
  76. */
  77. private ?string $category = null;
  78. /**
  79. * @ORM\Column(type="boolean")
  80. *
  81. * @Expose()
  82. * @Serializer\Groups({"enabled"})
  83. */
  84. private $enabled = true;
  85. use DateTrait;
  86. /**
  87. * @Serializer\VirtualProperty()
  88. * @Serializer\SerializedName("array_category_values")
  89. *
  90. * @Expose()
  91. * @Groups({"array_category_values"})
  92. * @return mixed
  93. */
  94. public function getArrayCategoryValues()
  95. {
  96. return json_decode($this->categoryValues, TRUE) ?? [];
  97. }
  98. /**
  99. * @param string $slug
  100. * @param int $value
  101. *
  102. * @return $this
  103. */
  104. public function modifyValueToCategory(string $slug, int $value): self
  105. {
  106. $newArray = $this->getArrayCategoryValues();
  107. $newArray[ $slug ] = $value;
  108. $this->categoryValues = json_encode($newArray);
  109. return $this;
  110. }
  111. public function getId(): ?int
  112. {
  113. return $this->id;
  114. }
  115. public function getName(): ?string
  116. {
  117. return $this->name;
  118. }
  119. public function setName(string $name): self
  120. {
  121. $this->name = $name;
  122. return $this;
  123. }
  124. public function getDescription(): ?string
  125. {
  126. return $this->description;
  127. }
  128. public function setDescription(?string $description): self
  129. {
  130. $this->description = $description;
  131. return $this;
  132. }
  133. public function getImage(): ?string
  134. {
  135. return $this->image;
  136. }
  137. public function setImage(?string $image): self
  138. {
  139. $this->image = $image;
  140. return $this;
  141. }
  142. public function getImageFile()
  143. {
  144. return $this->imageFile;
  145. }
  146. /**
  147. * @param File $imageFile
  148. *
  149. * @return void
  150. */
  151. public function setImageFile(File $imageFile): void
  152. {
  153. $this->imageFile = $imageFile;
  154. if (NULL !== $imageFile) {
  155. // It is required that at least one field changes if you are using doctrine
  156. // otherwise the event listeners won't be called and the file is lost
  157. $this->updatedAt = new DateTime();
  158. }
  159. }
  160. public function getRatePrice(): ?float
  161. {
  162. return $this->ratePrice;
  163. }
  164. public function setRatePrice(?float $ratePrice): self
  165. {
  166. $this->ratePrice = $ratePrice;
  167. return $this;
  168. }
  169. public function getCategory(): ?string
  170. {
  171. return $this->category;
  172. }
  173. public function setCategory(?string $category): self
  174. {
  175. $this->category = $category;
  176. return $this;
  177. }
  178. public function getCategoryValues()
  179. {
  180. return $this->categoryValues;
  181. }
  182. public function setCategoryValues($categoryValues): CustomerProduct
  183. {
  184. $this->categoryValues = $categoryValues;
  185. return $this;
  186. }
  187. /**
  188. * @return mixed
  189. */
  190. public function getEnabled()
  191. {
  192. return $this->enabled;
  193. }
  194. /**
  195. * @param mixed $enabled
  196. *
  197. * @return CustomerProduct
  198. */
  199. public function setEnabled($enabled): CustomerProduct
  200. {
  201. $this->enabled = $enabled;
  202. return $this;
  203. }
  204. // methode pour matcher avec la mise au panier du customerProduct
  205. public function getPriceHT(): ?float
  206. {
  207. return $this->getRatePrice();
  208. }
  209. // methode pour matcher avec la mise au panier du customerProduct
  210. public function getPriceTTC(): ?float
  211. {
  212. return $this->getRatePrice();
  213. }
  214. // methode pour matcher avec la mise au panier du customerProduct
  215. public function getPrice(): ?float
  216. {
  217. return $this->getRatePrice();
  218. }
  219. public function getSku(): string
  220. {
  221. return $this->sku;
  222. }
  223. public function setSku(string $sku): self
  224. {
  225. $this->sku = $sku;
  226. return $this;
  227. }
  228. }