Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

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