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.

954 lines
24KB

  1. <?php
  2. namespace Lc\CaracoleBundle\Model\Product;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Lc\CaracoleBundle\Doctrine\Extension\FilterSectionInterface;
  7. use Lc\CaracoleBundle\Doctrine\Extension\PriceInterface;
  8. use Lc\CaracoleBundle\Doctrine\Extension\ProductPropertyTrait;
  9. use Lc\CaracoleBundle\Doctrine\Extension\ProductPropertyInterface;
  10. use Gedmo\Mapping\Annotation as Gedmo;
  11. use Lc\CaracoleBundle\Model\Reduction\ReductionCatalogInterface;
  12. use Lc\CaracoleBundle\Model\Section\SectionInterface;
  13. use Lc\SovBundle\Doctrine\Extension\BlameableNullableTrait;
  14. use Lc\SovBundle\Doctrine\Pattern\AbstractFullEntity;
  15. /**
  16. * @ORM\MappedSuperclass()
  17. */
  18. abstract class ProductFamilyModel extends AbstractFullEntity implements ProductPropertyInterface, PriceInterface,
  19. FilterSectionInterface
  20. {
  21. use ProductPropertyTrait;
  22. use BlameableNullableTrait;
  23. const BEHAVIOR_COUNT_STOCK_UNLIMITED = 'unlimited';
  24. const BEHAVIOR_COUNT_STOCK_BY_MEASURE = 'by-measure';
  25. const BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY = 'by-product-family';
  26. const BEHAVIOR_COUNT_STOCK_BY_PRODUCT = 'by-product';
  27. public function getBehaviorCountStockChoices(): array
  28. {
  29. return [
  30. self::BEHAVIOR_COUNT_STOCK_BY_MEASURE,
  31. self::BEHAVIOR_COUNT_STOCK_BY_PRODUCT,
  32. self::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY,
  33. self::BEHAVIOR_COUNT_STOCK_UNLIMITED,
  34. ];
  35. }
  36. const BEHAVIOR_DISPLAY_SALE_BY_MEASURE = 'by-measure';
  37. const BEHAVIOR_DISPLAY_SALE_BY_QUANTITY = 'by-quantity';
  38. public function getBehaviorDisplaySaleChoices(): array
  39. {
  40. return [
  41. self::BEHAVIOR_DISPLAY_SALE_BY_MEASURE,
  42. self::BEHAVIOR_DISPLAY_SALE_BY_QUANTITY,
  43. ];
  44. }
  45. const BEHAVIOR_STOCK_CYCLE_RENEWABLE = 'renewable';
  46. const BEHAVIOR_STOCK_CYCLE_RENEWABLE_VALIDATION = 'renewable-with-validation';
  47. const BEHAVIOR_STOCK_CYCLE_NON_RENEWABLE = 'non-renewable';
  48. public function getBehaviorStockCycleChoices(): array
  49. {
  50. return [
  51. self::BEHAVIOR_STOCK_CYCLE_NON_RENEWABLE,
  52. self::BEHAVIOR_STOCK_CYCLE_RENEWABLE,
  53. self::BEHAVIOR_STOCK_CYCLE_RENEWABLE_VALIDATION,
  54. ];
  55. }
  56. const WARNING_MESSAGE_TYPE_SUCCESS = 'success';
  57. const WARNING_MESSAGE_TYPE_ERROR = 'error';
  58. const WARNING_MESSAGE_TYPE_WARNING = 'warning';
  59. const WARNING_MESSAGE_TYPE_INFO = 'info';
  60. public function getWaringMessageTypeChoices(): array
  61. {
  62. return [
  63. self::WARNING_MESSAGE_TYPE_ERROR,
  64. self::WARNING_MESSAGE_TYPE_INFO,
  65. self::WARNING_MESSAGE_TYPE_SUCCESS,
  66. self::WARNING_MESSAGE_TYPE_WARNING,
  67. ];
  68. }
  69. const BEHAVIOR_ADD_TO_CART_SIMPLE = 'simple';
  70. const BEHAVIOR_ADD_TO_CART_MULTIPLE = 'multiple';
  71. public function getBehaviorAddToCartChoices(): array
  72. {
  73. return [
  74. self::BEHAVIOR_ADD_TO_CART_MULTIPLE,
  75. self::BEHAVIOR_ADD_TO_CART_SIMPLE,
  76. ];
  77. }
  78. const BEHAVIOR_PRICE_BY_PIECE = 'by-piece';
  79. const BEHAVIOR_PRICE_BY_REFERENCE_UNIT = 'by-reference-unit';
  80. public function getBehaviorPriceChoices(): array
  81. {
  82. return [
  83. self::BEHAVIOR_PRICE_BY_PIECE,
  84. self::BEHAVIOR_PRICE_BY_REFERENCE_UNIT,
  85. ];
  86. }
  87. const PROPERTY_ORGANIC_LABEL_AB = 'ab';
  88. const PROPERTY_ORGANIC_LABEL_NP = 'nature-progres';
  89. const PROPERTY_ORGANIC_LABEL_HVE = 'hve';
  90. const PROPERTY_ORGANIC_LABEL_TVVR = 'tvvr';
  91. public function getPropertyOrganicLabelChoices(): array
  92. {
  93. return [
  94. self::PROPERTY_ORGANIC_LABEL_AB,
  95. self::PROPERTY_ORGANIC_LABEL_NP,
  96. self::PROPERTY_ORGANIC_LABEL_HVE,
  97. self::PROPERTY_ORGANIC_LABEL_TVVR,
  98. ];
  99. }
  100. const TYPE_EXPIRATION_DATE_DLC = 'dlc';
  101. const TYPE_EXPIRATION_DATE_DDM = 'ddm';
  102. const TYPE_EXPIRATION_DATE_DLUO = 'dluo';
  103. public function getTypeExpirationDateChoices(): array
  104. {
  105. return [
  106. self::TYPE_EXPIRATION_DATE_DLC,
  107. self::TYPE_EXPIRATION_DATE_DDM,
  108. self::TYPE_EXPIRATION_DATE_DLUO,
  109. ];
  110. }
  111. const BEHAVIOR_EXPIRATION_DATE_BY_PRODUCT_FAMILY = 'by-product-family';
  112. const BEHAVIOR_EXPIRATION_DATE_BY_PRODUCT = 'by-product';
  113. public function getBehaviorExpirationDateChoices():array{
  114. return [
  115. self::BEHAVIOR_EXPIRATION_DATE_BY_PRODUCT_FAMILY,
  116. self::BEHAVIOR_EXPIRATION_DATE_BY_PRODUCT
  117. ];
  118. }
  119. // @TODO : Champ hydraté par ProductFamilyBuilder ?
  120. protected $reductionCatalog;
  121. /**
  122. * @ORM\ManyToMany(targetEntity="Lc\CaracoleBundle\Model\Product\ProductCategoryInterface", inversedBy="productFamilies")
  123. */
  124. protected $productCategories;
  125. /**
  126. * @ORM\Column(type="boolean")
  127. */
  128. protected $activeProducts;
  129. /**
  130. * @ORM\Column(type="string", length=255, nullable=true)
  131. */
  132. protected $productsType;
  133. /**
  134. * @ORM\Column(type="boolean", nullable=true)
  135. */
  136. protected $productsQuantityAsTitle;
  137. /**
  138. * @ORM\Column(type="string", length=255, nullable=true)
  139. */
  140. protected $quantityLabel;
  141. /**
  142. * @ORM\OneToMany(targetEntity="Lc\CaracoleBundle\Model\Product\ProductInterface", mappedBy="productFamily", orphanRemoval=true, cascade={"persist"})
  143. * @ORM\OrderBy({"position" = "ASC"})
  144. */
  145. protected $products;
  146. /**
  147. * @ORM\Column(type="string", length=255, nullable=true)
  148. */
  149. protected $subtitle;
  150. /**
  151. * @ORM\Column(type="text", nullable=true)
  152. */
  153. protected $warningMessage;
  154. /**
  155. * @ORM\Column(type="string", length=255, nullable=true)
  156. */
  157. protected $warningMessageType;
  158. /**
  159. * @ORM\Column(type="text", nullable=true)
  160. */
  161. protected $note;
  162. /**
  163. * @ORM\Column(type="string", length=31, nullable=true)
  164. */
  165. protected $behaviorOutOfStock;
  166. /**
  167. * @ORM\Column(type="string", length=31)
  168. */
  169. protected $behaviorCountStock;
  170. /**
  171. * @ORM\Column(type="string", length=255)
  172. */
  173. protected $behaviorDisplaySale;
  174. /**
  175. * @ORM\Column(type="date", nullable=true)
  176. */
  177. protected $propertyNoveltyExpirationDate;
  178. /**
  179. * @ORM\Column(type="string", length=255, nullable=true)
  180. */
  181. protected $propertyOrganicLabel;
  182. /**
  183. * @ORM\Column(type="text", nullable=true)
  184. */
  185. protected $propertyAllergens;
  186. /**
  187. * @ORM\Column(type="text", nullable=true)
  188. */
  189. protected $propertyComposition;
  190. /**
  191. * @ORM\Column(type="text", nullable=true)
  192. */
  193. protected $propertyFragrances;
  194. /**
  195. * @ORM\Column(type="text", nullable=true)
  196. */
  197. protected $propertyPackaging;
  198. /**
  199. * @ORM\Column(type="text", nullable=true)
  200. */
  201. protected $propertyCharacteristics;
  202. /**
  203. * @ORM\Column(type="text", nullable=true)
  204. */
  205. protected $propertyWeight;
  206. /**
  207. * @ORM\Column(type="text", nullable=true)
  208. */
  209. protected $propertyQuantity;
  210. /**
  211. * @ORM\Column(type="text", nullable=true)
  212. */
  213. protected $propertyFeature;
  214. /**
  215. * @ORM\Column(type="text", nullable=true)
  216. */
  217. protected $propertyVariety;
  218. /**
  219. * @ORM\Column(type="text", nullable=true)
  220. */
  221. protected $propertyAlcoholLevel;
  222. /**
  223. * @ORM\Column(type="string", length=255, nullable=true)
  224. */
  225. protected $behaviorExpirationDate;
  226. /**
  227. * @ORM\Column(type="string", length=255, nullable=true)
  228. */
  229. protected $typeExpirationDate;
  230. /**
  231. * @ORM\Column(type="string", length=32, nullable=true)
  232. */
  233. protected $behaviorAddToCart;
  234. /**
  235. * @ORM\Column(type="string", length=31)
  236. */
  237. protected $behaviorPrice;
  238. /**
  239. * @ORM\Column(type="boolean")
  240. */
  241. protected $saleStatus;
  242. /**
  243. * @ORM\ManyToOne(targetEntity="Lc\CaracoleBundle\Model\Section\SectionInterface")
  244. * @ORM\JoinColumn(nullable=false)
  245. */
  246. protected $section;
  247. public function __construct()
  248. {
  249. $this->productCategories = new ArrayCollection();
  250. $this->products = new ArrayCollection();
  251. }
  252. public function __toString()
  253. {
  254. return $this->getTitle();
  255. }
  256. public function getSection(): SectionInterface
  257. {
  258. return $this->section;
  259. }
  260. public function setSection(SectionInterface $section): self
  261. {
  262. $this->section = $section;
  263. return $this;
  264. }
  265. //TODO move
  266. public function getAvailableQuantityInherited()
  267. {
  268. $availableQuantity = 0;
  269. switch ($this->getBehaviorCountStock()) {
  270. case self::BEHAVIOR_COUNT_STOCK_BY_MEASURE :
  271. case self::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY :
  272. $availableQuantity = $this->getAvailableQuantity();
  273. break;
  274. case self::BEHAVIOR_COUNT_STOCK_BY_PRODUCT :
  275. foreach ($this->getProductsOnline() as $product) {
  276. $availableQuantity += $product->getAvailableQuantityInherited();
  277. }
  278. break;
  279. case self::BEHAVIOR_COUNT_STOCK_UNLIMITED :
  280. $availableQuantity = false;
  281. break;
  282. }
  283. return $availableQuantity;
  284. }
  285. //TODO move
  286. public function getTaxRateInherited()
  287. {
  288. if ($this->getTaxRate()) {
  289. return $this->getTaxRate();
  290. } else {
  291. return $this->getSection()->getMerchant()->getTaxRate();
  292. }
  293. }
  294. public function getActiveProducts(): ?bool
  295. {
  296. return $this->activeProducts;
  297. }
  298. public function setActiveProducts(bool $activeProducts): self
  299. {
  300. $this->activeProducts = $activeProducts;
  301. return $this;
  302. }
  303. public function getProductsQuantityAsTitle(): ?bool
  304. {
  305. return $this->productsQuantityAsTitle;
  306. }
  307. public function setProductsQuantityAsTitle(bool $productsQuantityAsTitle): self
  308. {
  309. $this->productsQuantityAsTitle = $productsQuantityAsTitle;
  310. return $this;
  311. }
  312. public function getProductsType(): ?string
  313. {
  314. return $this->productsType;
  315. }
  316. public function setProductsType(?string $productsType): self
  317. {
  318. $this->productsType = $productsType;
  319. return $this;
  320. }
  321. public function getQuantityLabel(): ?string
  322. {
  323. return $this->quantityLabel;
  324. }
  325. public function setQuantityLabel(?string $quantityLabel): self
  326. {
  327. $this->quantityLabel = $quantityLabel;
  328. return $this;
  329. }
  330. /**
  331. * @return Collection|ProductInterface[]
  332. */
  333. public function getProducts(): Collection
  334. {
  335. return $this->products;
  336. }
  337. //TODO move
  338. public function getProductsOnline(): Collection
  339. {
  340. $products = $this->getProducts();
  341. $productsOnlineArray = new ArrayCollection();
  342. foreach ($products as $product) {
  343. if ($product->getStatus() == 1 && $product->getOriginProduct() != true) {
  344. $productsOnlineArray[] = $product;
  345. }
  346. }
  347. return $productsOnlineArray;
  348. }
  349. public function addProduct(ProductInterface $product): self
  350. {
  351. if (!$this->products->contains($product)) {
  352. $this->products[] = $product;
  353. $product->setProductFamily($this);
  354. }
  355. return $this;
  356. }
  357. public function removeProduct(ProductInterface $product): self
  358. {
  359. if ($this->products->contains($product)) {
  360. $this->products->removeElement($product);
  361. // set the owning side to null (unless already changed)
  362. if ($product->getProductFamily() === $this) {
  363. $product->setProductFamily(null);
  364. }
  365. }
  366. return $this;
  367. }
  368. public function getReductionCatalog(): ?ReductionCatalogInterface
  369. {
  370. return $this->reductionCatalog;
  371. }
  372. //TODO move
  373. public function getReductionCatalogInherited(): ?ReductionCatalogInterface
  374. {
  375. return $this->getReductionCatalog();
  376. }
  377. public function setReductionCatalog(?ReductionCatalogInterface $reductionCatalog): self
  378. {
  379. $this->reductionCatalog = $reductionCatalog;
  380. return $this;
  381. }
  382. /**
  383. * @return Collection|ProductCategoryInterface[]
  384. */
  385. public function getProductCategories(): Collection
  386. {
  387. return $this->productCategories;
  388. }
  389. public function initProductCategories()
  390. {
  391. $this->productCategories = new ArrayCollection();
  392. }
  393. public function addProductCategory(ProductCategoryInterface $productCategory): self
  394. {
  395. if (!$this->productCategories->contains($productCategory)) {
  396. $this->productCategories[] = $productCategory;
  397. }
  398. return $this;
  399. }
  400. public function removeProductCategory(ProductCategoryInterface $productCategory): self
  401. {
  402. if ($this->productCategories->contains($productCategory)) {
  403. $this->productCategories->removeElement($productCategory);
  404. }
  405. return $this;
  406. }
  407. //TODO move
  408. public function getProductCategoryParent()
  409. {
  410. $productCategories = $this->getProductCategories();
  411. if (count($productCategories) > 0) {
  412. return $productCategories[0]->getParent();
  413. }
  414. return false;
  415. }
  416. //TODO move
  417. public function getProductCategoryChild()
  418. {
  419. $productCategories = $this->getProductCategories();
  420. foreach ($productCategories as $productCategory) {
  421. if ($productCategory->getParent()) {
  422. return $productCategory;
  423. }
  424. }
  425. return false;
  426. }
  427. public function getSubtitle(): ?string
  428. {
  429. return $this->subtitle;
  430. }
  431. public function setSubtitle(?string $subtitle): self
  432. {
  433. $this->subtitle = $subtitle;
  434. return $this;
  435. }
  436. public function getWarningMessage(): ?string
  437. {
  438. return $this->warningMessage;
  439. }
  440. public function setWarningMessage(?string $warningMessage): self
  441. {
  442. $this->warningMessage = $warningMessage;
  443. return $this;
  444. }
  445. public function getWarningMessageType(): ?string
  446. {
  447. return $this->warningMessageType;
  448. }
  449. public function setWarningMessageType(?string $warningMessageType): self
  450. {
  451. $this->warningMessageType = $warningMessageType;
  452. return $this;
  453. }
  454. public function getNote(): ?string
  455. {
  456. return $this->note;
  457. }
  458. public function setNote(?string $note): self
  459. {
  460. $this->note = $note;
  461. return $this;
  462. }
  463. public function getBehaviorOutOfStock(): ?string
  464. {
  465. return $this->behaviorOutOfStock;
  466. }
  467. public function setBehaviorOutOfStock(?string $behaviorOutOfStock): self
  468. {
  469. $this->behaviorOutOfStock = $behaviorOutOfStock;
  470. return $this;
  471. }
  472. public function getBehaviorCountStock(): ?string
  473. {
  474. return $this->behaviorCountStock;
  475. }
  476. public function setBehaviorCountStock(string $behaviorCountStock): self
  477. {
  478. $this->behaviorCountStock = $behaviorCountStock;
  479. return $this;
  480. }
  481. public function getBehaviorDisplaySale(): ?string
  482. {
  483. return $this->behaviorDisplaySale;
  484. }
  485. public function setBehaviorDisplaySale(string $behaviorDisplaySale): self
  486. {
  487. $this->behaviorDisplaySale = $behaviorDisplaySale;
  488. return $this;
  489. }
  490. //TODO move
  491. public function isPropertyNoveltyOnline(): ?bool
  492. {
  493. if ($this->getPropertyNoveltyExpirationDate()) {
  494. $now = new \DateTime();
  495. if ($now <= $this->getPropertyNoveltyExpirationDate()) {
  496. return true;
  497. }
  498. }
  499. return false;
  500. }
  501. public function getPropertyNoveltyExpirationDate(): ?\DateTimeInterface
  502. {
  503. return $this->propertyNoveltyExpirationDate;
  504. }
  505. public function setPropertyNoveltyExpirationDate(?\DateTimeInterface $propertyNoveltyExpirationDate): self
  506. {
  507. $this->propertyNoveltyExpirationDate = $propertyNoveltyExpirationDate;
  508. return $this;
  509. }
  510. public function getPropertyOrganicLabel(): ?string
  511. {
  512. return $this->propertyOrganicLabel;
  513. }
  514. public function setPropertyOrganicLabel(?string $propertyOrganicLabel): self
  515. {
  516. $this->propertyOrganicLabel = $propertyOrganicLabel;
  517. return $this;
  518. }
  519. public function getPropertyAllergens(): ?string
  520. {
  521. return $this->propertyAllergens;
  522. }
  523. public function setPropertyAllergens(?string $propertyAllergens): self
  524. {
  525. $this->propertyAllergens = $propertyAllergens;
  526. return $this;
  527. }
  528. public function getPropertyComposition(): ?string
  529. {
  530. return $this->propertyComposition;
  531. }
  532. public function setPropertyComposition(?string $propertyComposition): self
  533. {
  534. $this->propertyComposition = $propertyComposition;
  535. return $this;
  536. }
  537. public function getPropertyFragrances(): ?string
  538. {
  539. return $this->propertyFragrances;
  540. }
  541. public function setPropertyFragrances(?string $propertyFragrances): self
  542. {
  543. $this->propertyFragrances = $propertyFragrances;
  544. return $this;
  545. }
  546. //TODO move
  547. public function countProperties(): bool
  548. {
  549. $count = 0;
  550. $count += (int)strlen($this->getPropertyOrganicLabel()) > 0;
  551. $count += (int)strlen($this->getPropertyWeight()) > 0;
  552. $count += (int)strlen($this->getPropertyFragrances()) > 0;
  553. $count += (int)strlen($this->getPropertyComposition()) > 0;
  554. $count += (int)strlen($this->getPropertyAllergens()) > 0;
  555. $count += (int)strlen($this->getPropertyAlcoholLevel()) > 0;
  556. $count += (int)strlen($this->getPropertyCharacteristics()) > 0;
  557. $count += (int)strlen($this->getPropertyFeature()) > 0;
  558. $count += (int)strlen($this->getPropertyPackaging()) > 0;
  559. $count += (int)strlen($this->getPropertyQuantity()) > 0;
  560. $count += (int)strlen($this->getPropertyVariety()) > 0;
  561. $count += (int)($this->getPropertyExpirationDate() != null);
  562. return $count;
  563. }
  564. public function getBehaviorExpirationDate(): ?string
  565. {
  566. return $this->behaviorExpirationDate;
  567. }
  568. public function setBehaviorExpirationDate(?string $behaviorExpirationDate): self
  569. {
  570. $this->behaviorExpirationDate = $behaviorExpirationDate;
  571. return $this;
  572. }
  573. public function getTypeExpirationDate(): ?string
  574. {
  575. return $this->typeExpirationDate;
  576. }
  577. public function setTypeExpirationDate(?string $typeExpirationDate): self
  578. {
  579. $this->typeExpirationDate = $typeExpirationDate;
  580. return $this;
  581. }
  582. public function getPropertyWeight(): ?string
  583. {
  584. return $this->propertyWeight;
  585. }
  586. public function setPropertyWeight(?string $propertyWeight): self
  587. {
  588. $this->propertyWeight = $propertyWeight;
  589. return $this;
  590. }
  591. public function getPropertyQuantity(): ?string
  592. {
  593. return $this->propertyQuantity;
  594. }
  595. public function setPropertyQuantity(?string $propertyQuantity): self
  596. {
  597. $this->propertyQuantity = $propertyQuantity;
  598. return $this;
  599. }
  600. public function getPropertyVariety(): ?string
  601. {
  602. return $this->propertyVariety;
  603. }
  604. public function setPropertyVariety(?string $propertyVariety): self
  605. {
  606. $this->propertyVariety = $propertyVariety;
  607. return $this;
  608. }
  609. public function getPropertyFeature(): ?string
  610. {
  611. return $this->propertyFeature;
  612. }
  613. public function setPropertyFeature(?string $propertyFeature): self
  614. {
  615. $this->propertyFeature = $propertyFeature;
  616. return $this;
  617. }
  618. public function getPropertyAlcoholLevel(): ?string
  619. {
  620. return $this->propertyAlcoholLevel;
  621. }
  622. public function setPropertyAlcoholLevel(?string $propertyAlcoholLevel): self
  623. {
  624. $this->propertyAlcoholLevel = $propertyAlcoholLevel;
  625. return $this;
  626. }
  627. public function getPropertyPackaging(): ?string
  628. {
  629. return $this->propertyPackaging;
  630. }
  631. public function setPropertyPackaging(?string $propertyPackaging): self
  632. {
  633. $this->propertyPackaging = $propertyPackaging;
  634. return $this;
  635. }
  636. public function getPropertyCharacteristics(): ?string
  637. {
  638. return $this->propertyCharacteristics;
  639. }
  640. public function setPropertyCharacteristics(?string $propertyCharacteristics): self
  641. {
  642. $this->propertyCharacteristics = $propertyCharacteristics;
  643. return $this;
  644. }
  645. public function getBehaviorAddToCart(): ?string
  646. {
  647. return $this->behaviorAddToCart;
  648. }
  649. public function setBehaviorAddToCart(?string $behaviorAddToCart): self
  650. {
  651. $this->behaviorAddToCart = $behaviorAddToCart;
  652. return $this;
  653. }
  654. public function getBehaviorPrice(): ?string
  655. {
  656. return $this->behaviorPrice;
  657. }
  658. //TODO move
  659. public function getBehaviorPriceInherited()
  660. {
  661. return $this->getBehaviorPrice();
  662. }
  663. public function setBehaviorPrice(?string $behaviorPrice): self
  664. {
  665. $this->behaviorPrice = $behaviorPrice;
  666. return $this;
  667. }
  668. //TODO move
  669. public function hasProductsWithVariousWeight()
  670. {
  671. if ($this->getActiveProducts()) {
  672. $arrayCountProducts = [];
  673. $products = $this->getProductsOnline();
  674. foreach ($products as $product) {
  675. $titleProduct = $product->getTitleInherited();
  676. if (!isset($arrayCountProducts[$titleProduct])) {
  677. $arrayCountProducts[$titleProduct] = [];
  678. }
  679. if (!in_array($product->getQuantityLabelInherited(), $arrayCountProducts[$titleProduct])) {
  680. $arrayCountProducts[$titleProduct][] = $product->getQuantityLabelInherited();
  681. }
  682. if (count($arrayCountProducts[$titleProduct]) > 1) {
  683. return true;
  684. }
  685. }
  686. }
  687. return false;
  688. }
  689. //TODO move
  690. public function getProductsGroupByTitle()
  691. {
  692. $arrayProductsGroupByTitle = [];
  693. $products = $this->getProductsOnline();
  694. foreach ($products as $product) {
  695. if ($product->getStatus() == 1) {
  696. $titleProduct = $product->getTitleInherited();
  697. if (!isset($arrayProductsGroupByTitle[$titleProduct])) {
  698. $arrayProductsGroupByTitle[$titleProduct] = [];
  699. }
  700. $arrayProductsGroupByTitle[$titleProduct][] = $product;
  701. }
  702. }
  703. return $arrayProductsGroupByTitle;
  704. }
  705. //TODO move
  706. public function getOriginProduct()
  707. {
  708. $products = $this->getProducts();
  709. foreach ($products as $product) {
  710. if ($product->getOriginProduct()) {
  711. return $product;
  712. }
  713. }
  714. }
  715. //TODO move
  716. public function getOriginProductOnline()
  717. {
  718. $originProduct = $this->getOriginProduct();
  719. if ($originProduct->getStatus() == 1) {
  720. return $originProduct;
  721. } else {
  722. return false;
  723. }
  724. }
  725. //TODO move
  726. public function hasOneProductOnline()
  727. {
  728. if (($this->getActiveProducts() && count($this->getProductsOnline()) > 0)
  729. || (!$this->getActiveProducts() && $this->getOriginProduct())) {
  730. return true;
  731. }
  732. return false;
  733. }
  734. public function getSaleStatus(): ?bool
  735. {
  736. return $this->saleStatus;
  737. }
  738. public function setSaleStatus(bool $saleStatus): self
  739. {
  740. $this->saleStatus = $saleStatus;
  741. return $this;
  742. }
  743. //TODO move
  744. public function getFieldBuyingPrice()
  745. {
  746. if ($this->getBehaviorPrice() === self::BEHAVIOR_PRICE_BY_PIECE) {
  747. return 'buyingPrice';
  748. } elseif ($this->getBehaviorPrice() === self::BEHAVIOR_PRICE_BY_REFERENCE_UNIT) {
  749. return 'buyingPriceByRefUnit';
  750. }
  751. }
  752. //TODO move
  753. public function getFieldPrice()
  754. {
  755. if ($this->getBehaviorPrice() === self::BEHAVIOR_PRICE_BY_PIECE) {
  756. return 'price';
  757. } elseif ($this->getBehaviorPrice() === self::BEHAVIOR_PRICE_BY_REFERENCE_UNIT) {
  758. return 'priceByRefUnit';
  759. }
  760. }
  761. }