Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

714 lines
20KB

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