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.

951 line
23KB

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