src/ProductBundle/Entity/ProductSearch.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\ProductBundle\Entity;
  3. use App\CurrencyBundle\Entity\Currency;
  4. use App\MediaBundle\Entity\Image;
  5. use Doctrine\ORM\Mapping as ORM;
  6. /**
  7. * @ORM\HasLifecycleCallbacks
  8. * @ORM\Table("product_search", indexes={@ORM\Index(columns={"normalized_text"}, flags={"fulltext"})})
  9. * @ORM\Entity(repositoryClass="App\ProductBundle\Repository\ProductSearchRepository")
  10. */
  11. class ProductSearch
  12. {
  13. /**
  14. * @ORM\Id
  15. * @ORM\OneToOne(targetEntity="Product")
  16. * @ORM\JoinColumn(name="product_id", referencedColumnName="id", nullable=false)
  17. */
  18. private Product $product;
  19. /**
  20. * @ORM\ManyToOne(targetEntity="App\ProductBundle\Entity\ProductPrice")
  21. */
  22. private ?ProductPrice $productPrice = null;
  23. /**
  24. * @ORM\ManyToOne(targetEntity="App\ProductBundle\Entity\Category")
  25. */
  26. private Category $category;
  27. /**
  28. * @ORM\ManyToOne(targetEntity="App\ProductBundle\Entity\Brand")
  29. */
  30. private ?Brand $brand = null;
  31. /**
  32. * @ORM\ManyToOne(targetEntity="App\CurrencyBundle\Entity\Currency")
  33. */
  34. private Currency $currency;
  35. /**
  36. * @ORM\ManyToOne(targetEntity="App\MediaBundle\Entity\Image")
  37. * @ORM\JoinColumn(name="main_image_id", referencedColumnName="id", onDelete="SET NULL")
  38. */
  39. public ?Image $mainImage = null;
  40. /**
  41. * @ORM\Column(name="titles", type="json", nullable=false)
  42. */
  43. private ?array $titles = [];
  44. /**
  45. * @ORM\Column(name="slugs", type="json", nullable=false)
  46. */
  47. private ?array $slugs = [];
  48. /**
  49. * @ORM\Column(name="specs", type="json", nullable=true)
  50. */
  51. private ?array $specs;
  52. /**
  53. * @ORM\Column(name="min_sell_price", type="float")
  54. */
  55. private float $minSellPrice;
  56. /**
  57. * @ORM\Column(name="max_sell_price", type="float")
  58. */
  59. private float $maxSellPrice;
  60. /**
  61. * @ORM\Column(name="min_original_price", type="float")
  62. */
  63. private float $minOriginalPrice;
  64. /**
  65. * @ORM\Column(name="max_original_price", type="float")
  66. */
  67. private float $maxOriginalPrice;
  68. /**
  69. * @ORM\Column(name="normalized_text", type="text", nullable=true)
  70. */
  71. private ?string $normalizedTxt;
  72. /**
  73. * @ORM\Column(name="has_multi_price", type="boolean")
  74. */
  75. private bool $hasMultiPrice = false;
  76. /**
  77. * @ORM\Column(name="featured", type="boolean")
  78. */
  79. private bool $featured = false;
  80. /**
  81. * @ORM\Column(name="recommended_sort", type="smallint")
  82. */
  83. private int $recommendedSort = 0;
  84. /**
  85. * @ORM\Column(name="new_arrival", type="boolean")
  86. */
  87. private bool $newArrival = false;
  88. /**
  89. * @ORM\Column(name="has_offer", type="boolean")
  90. */
  91. private bool $hasOffer = false;
  92. /**
  93. * @ORM\Column(name="offer_expiry_date", type="date", nullable=true)
  94. */
  95. private ?\DateTimeInterface $offerExpiryDate;
  96. /**
  97. * @ORM\Column(name="promotion_percentage", type="float", nullable=true)
  98. */
  99. private float $promotionPercentage = 0;
  100. /**
  101. * @ORM\Column(name="has_stock", type="boolean", options={"default" : 1})
  102. */
  103. private bool $hasStock = true;
  104. /**
  105. * @ORM\Column(name="last_update_datetime", type="datetime")
  106. */
  107. private ?\DateTimeInterface $lastUpdate;
  108. /**
  109. * Now we tell doctrine that before we persist or update we call the updatedTimestamps() function.
  110. *
  111. * @ORM\PrePersist
  112. * @ORM\PreUpdate
  113. */
  114. public function updatedTimestamps(): void
  115. {
  116. $this->setLastUpdate(new \DateTime(date('Y-m-d H:i:s')));
  117. $this->calculateRecommendedSort();
  118. }
  119. private function calculateRecommendedSort(): void
  120. {
  121. $score = 0;
  122. if ($this->isFeatured()) {
  123. $score += 1;
  124. }
  125. $this->setRecommendedSort($score);
  126. }
  127. public function getSlugByLocale(string $locale): ?string
  128. {
  129. if (array_key_exists($locale, $this->getSlugs())) {
  130. return $this->slugs[$locale];
  131. }
  132. if (count($this->slugs) > 0) {
  133. return reset($this->slugs);
  134. }
  135. return null;
  136. }
  137. public function getTitleByLocale(string $locale): ?string
  138. {
  139. if (array_key_exists($locale, $this->getTitles())) {
  140. return $this->titles[$locale];
  141. }
  142. if (count($this->titles) > 0) {
  143. return reset($this->titles);
  144. }
  145. return null;
  146. }
  147. public function getCategory(): ?Category
  148. {
  149. return $this->category;
  150. }
  151. public function setCategory(?Category $category): self
  152. {
  153. $this->category = $category;
  154. return $this;
  155. }
  156. public function getSpecs(): array
  157. {
  158. return $this->specs;
  159. }
  160. public function setSpecs(?array $specs): self
  161. {
  162. $this->specs = $specs;
  163. return $this;
  164. }
  165. public function getMinSellPrice(): ?float
  166. {
  167. return $this->minSellPrice;
  168. }
  169. public function setMinSellPrice(float $minSellPrice): self
  170. {
  171. $this->minSellPrice = $minSellPrice;
  172. return $this;
  173. }
  174. public function getMaxSellPrice(): ?float
  175. {
  176. return $this->maxSellPrice;
  177. }
  178. public function setMaxSellPrice(float $maxSellPrice): self
  179. {
  180. $this->maxSellPrice = $maxSellPrice;
  181. return $this;
  182. }
  183. public function getMinOriginalPrice(): ?float
  184. {
  185. return $this->minOriginalPrice;
  186. }
  187. public function setMinOriginalPrice(float $minOriginalPrice): self
  188. {
  189. $this->minOriginalPrice = $minOriginalPrice;
  190. return $this;
  191. }
  192. public function getMaxOriginalPrice(): ?float
  193. {
  194. return $this->maxOriginalPrice;
  195. }
  196. public function setMaxOriginalPrice(float $maxOriginalPrice): self
  197. {
  198. $this->maxOriginalPrice = $maxOriginalPrice;
  199. return $this;
  200. }
  201. public function getNormalizedTxt(): ?string
  202. {
  203. return $this->normalizedTxt;
  204. }
  205. public function setNormalizedTxt(?string $normalizedTxt): self
  206. {
  207. $this->normalizedTxt = $normalizedTxt;
  208. return $this;
  209. }
  210. public function isHasMultiPrice(): ?bool
  211. {
  212. return $this->hasMultiPrice;
  213. }
  214. public function setHasMultiPrice(bool $hasMultiPrice): self
  215. {
  216. $this->hasMultiPrice = $hasMultiPrice;
  217. return $this;
  218. }
  219. public function isFeatured(): ?bool
  220. {
  221. return $this->featured;
  222. }
  223. public function setFeatured(bool $featured): self
  224. {
  225. $this->featured = $featured;
  226. return $this;
  227. }
  228. public function getRecommendedSort(): ?int
  229. {
  230. return $this->recommendedSort;
  231. }
  232. public function setRecommendedSort(int $recommendedSort): self
  233. {
  234. $this->recommendedSort = $recommendedSort;
  235. return $this;
  236. }
  237. public function isNewArrival(): ?bool
  238. {
  239. return $this->newArrival;
  240. }
  241. public function setNewArrival(bool $newArrival): self
  242. {
  243. $this->newArrival = $newArrival;
  244. return $this;
  245. }
  246. public function isHasOffer(): ?bool
  247. {
  248. return $this->hasOffer;
  249. }
  250. public function setHasOffer(bool $hasOffer): self
  251. {
  252. $this->hasOffer = $hasOffer;
  253. return $this;
  254. }
  255. public function isHasStock(): ?bool
  256. {
  257. return $this->hasStock;
  258. }
  259. public function setHasStock(bool $hasStock): self
  260. {
  261. $this->hasStock = $hasStock;
  262. return $this;
  263. }
  264. public function getOfferExpiryDate(): ?\DateTimeInterface
  265. {
  266. return $this->offerExpiryDate;
  267. }
  268. public function setOfferExpiryDate(?\DateTimeInterface $offerExpiryDate): self
  269. {
  270. $this->offerExpiryDate = $offerExpiryDate;
  271. return $this;
  272. }
  273. public function getPromotionPercentage(): ?float
  274. {
  275. return $this->promotionPercentage;
  276. }
  277. public function setPromotionPercentage(?float $promotionPercentage): self
  278. {
  279. $this->promotionPercentage = $promotionPercentage;
  280. return $this;
  281. }
  282. public function getLastUpdate(): ?\DateTimeInterface
  283. {
  284. return $this->lastUpdate;
  285. }
  286. public function setLastUpdate(\DateTimeInterface $lastUpdate): self
  287. {
  288. $this->lastUpdate = $lastUpdate;
  289. return $this;
  290. }
  291. public function getProduct(): ?Product
  292. {
  293. return $this->product;
  294. }
  295. public function setProduct(Product $product): self
  296. {
  297. $this->product = $product;
  298. return $this;
  299. }
  300. public function getCurrency(): ?Currency
  301. {
  302. return $this->currency;
  303. }
  304. public function setCurrency(?Currency $currency): self
  305. {
  306. $this->currency = $currency;
  307. return $this;
  308. }
  309. public function getMainImage(): ?Image
  310. {
  311. return $this->mainImage;
  312. }
  313. public function setMainImage(?Image $mainImage): self
  314. {
  315. $this->mainImage = $mainImage;
  316. return $this;
  317. }
  318. public function getTitles(): array
  319. {
  320. return $this->titles;
  321. }
  322. public function setTitles(array $titles): self
  323. {
  324. $this->titles = $titles;
  325. return $this;
  326. }
  327. public function getSlugs(): array
  328. {
  329. return $this->slugs;
  330. }
  331. public function setSlugs(array $slugs): self
  332. {
  333. $this->slugs = $slugs;
  334. return $this;
  335. }
  336. public function getProductPrice(): ?ProductPrice
  337. {
  338. return $this->productPrice;
  339. }
  340. public function setProductPrice(?ProductPrice $productPrice): static
  341. {
  342. $this->productPrice = $productPrice;
  343. return $this;
  344. }
  345. public function getBrand(): ?Brand
  346. {
  347. return $this->brand;
  348. }
  349. public function setBrand(?Brand $brand): static
  350. {
  351. $this->brand = $brand;
  352. return $this;
  353. }
  354. }