You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

681 lines
18KB

  1. <?php
  2. namespace Lc\ShopBundle\Model;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Lc\ShopBundle\Context\FilterMerchantInterface;
  7. use Lc\ShopBundle\Context\PriceInterface;
  8. use Lc\ShopBundle\Context\ProductInterface;
  9. use Lc\ShopBundle\Context\ProductPropertyInterface;
  10. /**
  11. * @ORM\MappedSuperclass()
  12. */
  13. abstract class ProductFamily extends AbstractDocumentEntity implements ProductPropertyInterface, PriceInterface, FilterMerchantInterface
  14. {
  15. use ProductPropertyTrait;
  16. //Champ hydraté par ProductFamilyUtils
  17. protected $reductionCatalog;
  18. /**
  19. * @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\MerchantInterface", inversedBy="productFamilies")
  20. * @ORM\JoinColumn(nullable=false)
  21. */
  22. protected $merchant;
  23. /**
  24. * @ORM\ManyToMany(targetEntity="Lc\ShopBundle\Context\ProductCategoryInterface", inversedBy="productFamilies")
  25. */
  26. protected $productCategories;
  27. /**
  28. * @ORM\Column(type="boolean")
  29. */
  30. protected $activeProducts;
  31. /**
  32. * @ORM\Column(type="string", length=255, nullable=true)
  33. */
  34. protected $productsType;
  35. /**
  36. * @ORM\OneToMany(targetEntity="Lc\ShopBundle\Context\ProductInterface", mappedBy="productFamily", orphanRemoval=true, cascade={"persist"}, fetch="EAGER")
  37. */
  38. protected $products;
  39. /**
  40. * @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\TaxRateInterface")
  41. */
  42. protected $supplierTaxRate;
  43. /**
  44. * @ORM\Column(type="string", length=255, nullable=true)
  45. */
  46. protected $subtitle;
  47. /**
  48. * @ORM\Column(type="text", nullable=true)
  49. */
  50. protected $warningMessage;
  51. /**
  52. * @ORM\Column(type="string", length=255, nullable=true)
  53. */
  54. protected $warningMessageType;
  55. /**
  56. * @ORM\Column(type="text", nullable=true)
  57. */
  58. protected $note;
  59. /**
  60. * @ORM\Column(type="string", length=31, nullable=true)
  61. */
  62. protected $behaviorOutOfStock;
  63. /**
  64. * @ORM\Column(type="string", length=31)
  65. */
  66. protected $behaviorCountStock;
  67. /**
  68. * @ORM\Column(type="date", nullable=true)
  69. */
  70. protected $propertyNoveltyExpirationDate;
  71. /**
  72. * @ORM\Column(type="string", length=255, nullable=true)
  73. */
  74. protected $propertyOrganicLabel;
  75. /**
  76. * @ORM\Column(type="text", nullable=true)
  77. */
  78. protected $propertyAllergens;
  79. /**
  80. * @ORM\Column(type="text", nullable=true)
  81. */
  82. protected $propertyComposition;
  83. /**
  84. * @ORM\Column(type="text", nullable=true)
  85. */
  86. protected $propertyFragrances;
  87. /**
  88. * @ORM\Column(type="text", nullable=true)
  89. */
  90. protected $propertyPackaging;
  91. /**
  92. * @ORM\Column(type="text", nullable=true)
  93. */
  94. protected $propertyCharacteristics;
  95. /**
  96. * @ORM\Column(type="text", nullable=true)
  97. */
  98. protected $propertyWeight;
  99. /**
  100. * @ORM\Column(type="text", nullable=true)
  101. */
  102. protected $propertyQuantity;
  103. /**
  104. * @ORM\Column(type="text", nullable=true)
  105. */
  106. protected $propertyFeature;
  107. /**
  108. * @ORM\Column(type="text", nullable=true)
  109. */
  110. protected $propertyVariety;
  111. /**
  112. * @ORM\Column(type="text", nullable=true)
  113. */
  114. protected $propertyAlcoholLevel;
  115. /**
  116. * @ORM\Column(type="string", length=255, nullable=true)
  117. */
  118. protected $behaviorExpirationDate;
  119. /**
  120. * @ORM\Column(type="string", length=255, nullable=true)
  121. */
  122. protected $typeExpirationDate;
  123. /**
  124. * @ORM\Column(type="string", length=32, nullable=true)
  125. */
  126. protected $behaviorAddToCart;
  127. /**
  128. * @ORM\Column(type="string", length=31)
  129. */
  130. protected $behaviorPrice;
  131. public function __construct()
  132. {
  133. $this->productCategories = new ArrayCollection();
  134. $this->products = new ArrayCollection();
  135. }
  136. public function __toString()
  137. {
  138. return $this->getTitle();
  139. }
  140. public function getTaxRateInherited()
  141. {
  142. if ($this->getTaxRate()) {
  143. return $this->getTaxRate();
  144. } else {
  145. return $this->getMerchant()->getTaxRate();
  146. }
  147. }
  148. public function getMerchant(): ?Merchant
  149. {
  150. return $this->merchant;
  151. }
  152. public function setMerchant(?Merchant $merchant): self
  153. {
  154. $this->merchant = $merchant;
  155. return $this;
  156. }
  157. public function getActiveProducts(): ?bool
  158. {
  159. return $this->activeProducts;
  160. }
  161. public function setActiveProducts(bool $activeProducts): self
  162. {
  163. $this->activeProducts = $activeProducts;
  164. return $this;
  165. }
  166. public function getProductsType(): ?string
  167. {
  168. return $this->productsType;
  169. }
  170. public function setProductsType(?string $productsType): self
  171. {
  172. $this->productsType = $productsType;
  173. return $this;
  174. }
  175. /**
  176. * @return Collection|ProductInterface[]
  177. */
  178. public function getProducts(): Collection
  179. {
  180. return $this->products;
  181. }
  182. public function addProduct(ProductInterface $product): self
  183. {
  184. if (!$this->products->contains($product)) {
  185. $this->products[] = $product;
  186. $product->setProductFamily($this);
  187. }
  188. return $this;
  189. }
  190. public function removeProduct(ProductInterface $product): self
  191. {
  192. if ($this->products->contains($product)) {
  193. $this->products->removeElement($product);
  194. // set the owning side to null (unless already changed)
  195. if ($product->getProductFamily() === $this) {
  196. $product->setProductFamily(null);
  197. }
  198. }
  199. return $this;
  200. }
  201. public function getReductionCatalog(): ?ReductionCatalog
  202. {
  203. return $this->reductionCatalog;
  204. }
  205. public function getReductionCatalogInherited(): ?ReductionCatalog
  206. {
  207. return $this->getReductionCatalog() ;
  208. }
  209. public function setReductionCatalog(?ReductionCatalog $reductionCatalog): self
  210. {
  211. $this->reductionCatalog = $reductionCatalog;
  212. return $this;
  213. }
  214. /**
  215. * @return Collection|ProductCategory[]
  216. */
  217. public function getProductCategories(): Collection
  218. {
  219. return $this->productCategories;
  220. }
  221. public function initProductCategories()
  222. {
  223. $this->productCategories = new ArrayCollection();
  224. }
  225. public function addProductCategory(ProductCategory $productCategory): self
  226. {
  227. if (!$this->productCategories->contains($productCategory)) {
  228. $this->productCategories[] = $productCategory;
  229. }
  230. return $this;
  231. }
  232. public function removeProductCategory(ProductCategory $productCategory): self
  233. {
  234. if ($this->productCategories->contains($productCategory)) {
  235. $this->productCategories->removeElement($productCategory);
  236. }
  237. return $this;
  238. }
  239. public function getProductCategoryParent()
  240. {
  241. $productCategories = $this->getProductCategories();
  242. if (count($productCategories) > 0) {
  243. return $productCategories[0]->getParent();
  244. }
  245. return false;
  246. }
  247. public function getProductCategoryChild()
  248. {
  249. $productCategories = $this->getProductCategories();
  250. foreach ($productCategories as $productCategory) {
  251. if ($productCategory->getParent()) {
  252. return $productCategory;
  253. }
  254. }
  255. return false;
  256. }
  257. public function getSupplierTaxRate(): ?TaxRate
  258. {
  259. return $this->supplierTaxRate;
  260. }
  261. public function setSupplierTaxRate(?TaxRate $supplierTaxRate): self
  262. {
  263. $this->supplierTaxRate = $supplierTaxRate;
  264. return $this;
  265. }
  266. public function getSubtitle(): ?string
  267. {
  268. return $this->subtitle;
  269. }
  270. public function setSubtitle(?string $subtitle): self
  271. {
  272. $this->subtitle = $subtitle;
  273. return $this;
  274. }
  275. public function getWarningMessage(): ?string
  276. {
  277. return $this->warningMessage;
  278. }
  279. public function setWarningMessage(?string $warningMessage): self
  280. {
  281. $this->warningMessage = $warningMessage;
  282. return $this;
  283. }
  284. public function getWarningMessageType(): ?string
  285. {
  286. return $this->warningMessageType;
  287. }
  288. public function setWarningMessageType(?string $warningMessageType): self
  289. {
  290. $this->warningMessageType = $warningMessageType;
  291. return $this;
  292. }
  293. public function getNote(): ?string
  294. {
  295. return $this->note;
  296. }
  297. public function setNote(?string $note): self
  298. {
  299. $this->note = $note;
  300. return $this;
  301. }
  302. public function getBehaviorOutOfStock(): ?string
  303. {
  304. return $this->behaviorOutOfStock;
  305. }
  306. public function setBehaviorOutOfStock(?string $behaviorOutOfStock): self
  307. {
  308. $this->behaviorOutOfStock = $behaviorOutOfStock;
  309. return $this;
  310. }
  311. public function getBehaviorCountStock(): ?string
  312. {
  313. return $this->behaviorCountStock;
  314. }
  315. public function setBehaviorCountStock(string $behaviorCountStock): self
  316. {
  317. $this->behaviorCountStock = $behaviorCountStock;
  318. return $this;
  319. }
  320. public function isPropertyNoveltyOnline(): ?bool
  321. {
  322. if ($this->getPropertyNoveltyExpirationDate()) {
  323. $now = new \DateTime();
  324. if ($now <= $this->getPropertyNoveltyExpirationDate()) {
  325. return true;
  326. }
  327. }
  328. return false;
  329. }
  330. public function getPropertyNoveltyExpirationDate(): ?\DateTimeInterface
  331. {
  332. return $this->propertyNoveltyExpirationDate;
  333. }
  334. public function setPropertyNoveltyExpirationDate(?\DateTimeInterface $propertyNoveltyExpirationDate): self
  335. {
  336. $this->propertyNoveltyExpirationDate = $propertyNoveltyExpirationDate;
  337. return $this;
  338. }
  339. public function getPropertyOrganicLabel(): ?string
  340. {
  341. return $this->propertyOrganicLabel;
  342. }
  343. public function setPropertyOrganicLabel(?string $propertyOrganicLabel): self
  344. {
  345. $this->propertyOrganicLabel = $propertyOrganicLabel;
  346. return $this;
  347. }
  348. public function getPropertyAllergens(): ?string
  349. {
  350. return $this->propertyAllergens;
  351. }
  352. public function setPropertyAllergens(?string $propertyAllergens): self
  353. {
  354. $this->propertyAllergens = $propertyAllergens;
  355. return $this;
  356. }
  357. public function getPropertyComposition(): ?string
  358. {
  359. return $this->propertyComposition;
  360. }
  361. public function setPropertyComposition(?string $propertyComposition): self
  362. {
  363. $this->propertyComposition = $propertyComposition;
  364. return $this;
  365. }
  366. public function getPropertyFragrances(): ?string
  367. {
  368. return $this->propertyFragrances;
  369. }
  370. public function setPropertyFragrances(?string $propertyFragrances): self
  371. {
  372. $this->propertyFragrances = $propertyFragrances;
  373. return $this;
  374. }
  375. public function countProperties(): bool
  376. {
  377. $count = 0;
  378. $count += (int)strlen($this->getPropertyAllergens()) > 0;
  379. $count += (int)strlen($this->getPropertyComposition()) > 0;
  380. $count += (int)strlen($this->getPropertyFragrances()) > 0;
  381. $count += (int)strlen($this->getPropertyOrganicLabel()) > 0;
  382. $count += (int)($this->getPropertyExpirationDate() != null);
  383. return $count;
  384. }
  385. public function getBehaviorExpirationDate(): ?string
  386. {
  387. return $this->behaviorExpirationDate;
  388. }
  389. public function setBehaviorExpirationDate(?string $behaviorExpirationDate): self
  390. {
  391. $this->behaviorExpirationDate = $behaviorExpirationDate;
  392. return $this;
  393. }
  394. public function getTypeExpirationDate(): ?string
  395. {
  396. return $this->typeExpirationDate;
  397. }
  398. public function setTypeExpirationDate(?string $typeExpirationDate): self
  399. {
  400. $this->typeExpirationDate = $typeExpirationDate;
  401. return $this;
  402. }
  403. public function getPropertyWeight(): ?string
  404. {
  405. return $this->propertyWeight;
  406. }
  407. public function setPropertyWeight(?string $propertyWeight): self
  408. {
  409. $this->propertyWeight = $propertyWeight;
  410. return $this;
  411. }
  412. public function getPropertyQuantity(): ?string
  413. {
  414. return $this->propertyQuantity;
  415. }
  416. public function setPropertyQuantity(?string $propertyQuantity): self
  417. {
  418. $this->propertyQuantity = $propertyQuantity;
  419. return $this;
  420. }
  421. public function getPropertyVariety(): ?string
  422. {
  423. return $this->propertyVariety;
  424. }
  425. public function setPropertyVariety(?string $propertyVariety): self
  426. {
  427. $this->propertyQuantity = $propertyVariety;
  428. return $this;
  429. }
  430. public function getPropertyFeature(): ?string
  431. {
  432. return $this->propertyFeature;
  433. }
  434. public function setPropertyFeature(?string $propertyFeature): self
  435. {
  436. $this->propertyFeature = $propertyFeature;
  437. return $this;
  438. }
  439. public function getPropertyAlcoholLevel(): ?string
  440. {
  441. return $this->propertyAlcoholLevel;
  442. }
  443. public function setPropertyAlcoholLevel(?string $propertyAlcoholLevel): self
  444. {
  445. $this->propertyAlcoholLevel = $propertyAlcoholLevel;
  446. return $this;
  447. }
  448. public function getPropertyPackaging(): ?string
  449. {
  450. return $this->propertyPackaging;
  451. }
  452. public function setPropertyPackaging(?string $propertyPackaging): self
  453. {
  454. $this->propertyPackaging = $propertyPackaging;
  455. return $this;
  456. }
  457. public function getPropertyCharacteristics(): ?string
  458. {
  459. return $this->propertyCharacteristics;
  460. }
  461. public function setPropertyCharacteristics(?string $propertyCharacteristics): self
  462. {
  463. $this->propertyCharacteristics = $propertyCharacteristics;
  464. return $this;
  465. }
  466. public function getBehaviorAddToCart(): ?string
  467. {
  468. return $this->behaviorAddToCart;
  469. }
  470. public function setBehaviorAddToCart(?string $behaviorAddToCart): self
  471. {
  472. $this->behaviorAddToCart = $behaviorAddToCart;
  473. return $this;
  474. }
  475. public function getBehaviorPrice(): ?string
  476. {
  477. return $this->behaviorPrice;
  478. }
  479. public function getBehaviorPriceInherited()
  480. {
  481. return $this->getBehaviorPrice() ;
  482. }
  483. public function setBehaviorPrice(?string $behaviorPrice): self
  484. {
  485. $this->behaviorPrice = $behaviorPrice;
  486. return $this;
  487. }
  488. public function hasProductsWithVariousWeight()
  489. {
  490. if ($this->getActiveProducts()) {
  491. $arrayCountProducts = [];
  492. $products = $this->getProducts();
  493. foreach ($products as $product) {
  494. $titleProduct = $product->getTitleInherited();
  495. if (!isset($arrayCountProducts[$titleProduct])) {
  496. $arrayCountProducts[$titleProduct] = [];
  497. }
  498. if (!in_array($product->getQuantityLabelInherited(), $arrayCountProducts[$titleProduct])) {
  499. $arrayCountProducts[$titleProduct][] = $product->getQuantityLabelInherited();
  500. }
  501. if (count($arrayCountProducts[$titleProduct]) > 1) {
  502. return true;
  503. }
  504. }
  505. }
  506. return false;
  507. }
  508. public function getProductsGroupByTitle()
  509. {
  510. $arrayProductsGroupByTitle = [];
  511. $products = $this->getProducts();
  512. foreach ($products as $product) {
  513. $titleProduct = $product->getTitleInherited();
  514. if (!isset($arrayProductsGroupByTitle[$titleProduct])) {
  515. $arrayProductsGroupByTitle[$titleProduct] = [];
  516. }
  517. $arrayProductsGroupByTitle[$titleProduct][] = $product;
  518. }
  519. return $arrayProductsGroupByTitle;
  520. }
  521. }