Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

788 lines
22KB

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