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.

ProductFamily.php 25KB

4 years ago
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860
  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="boolean", nullable=true)
  73. */
  74. protected $productsQuantityAsTitle;
  75. /**
  76. * @ORM\Column(type="string", length=255, nullable=true)
  77. */
  78. protected $quantityLabel;
  79. /**
  80. * @ORM\OneToMany(targetEntity="Lc\ShopBundle\Context\ProductInterface", mappedBy="productFamily", orphanRemoval=true, cascade={"persist"})
  81. * @ORM\OrderBy({"position" = "ASC"})
  82. */
  83. protected $products;
  84. /**
  85. * @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\TaxRateInterface")
  86. */
  87. protected $supplierTaxRate;
  88. /**
  89. * @ORM\Column(type="string", length=255, nullable=true)
  90. */
  91. protected $subtitle;
  92. /**
  93. * @ORM\Column(type="text", nullable=true)
  94. */
  95. protected $warningMessage;
  96. /**
  97. * @ORM\Column(type="string", length=255, nullable=true)
  98. */
  99. protected $warningMessageType;
  100. /**
  101. * @ORM\Column(type="text", nullable=true)
  102. */
  103. protected $note;
  104. /**
  105. * @ORM\Column(type="string", length=31, nullable=true)
  106. */
  107. protected $behaviorOutOfStock;
  108. /**
  109. * @ORM\Column(type="string", length=31)
  110. */
  111. protected $behaviorCountStock;
  112. /**
  113. * @ORM\Column(type="date", nullable=true)
  114. */
  115. protected $propertyNoveltyExpirationDate;
  116. /**
  117. * @ORM\Column(type="string", length=255, nullable=true)
  118. */
  119. protected $propertyOrganicLabel;
  120. /**
  121. * @ORM\Column(type="text", nullable=true)
  122. */
  123. protected $propertyAllergens;
  124. /**
  125. * @ORM\Column(type="text", nullable=true)
  126. */
  127. protected $propertyComposition;
  128. /**
  129. * @ORM\Column(type="text", nullable=true)
  130. */
  131. protected $propertyFragrances;
  132. /**
  133. * @ORM\Column(type="text", nullable=true)
  134. */
  135. protected $propertyPackaging;
  136. /**
  137. * @ORM\Column(type="text", nullable=true)
  138. */
  139. protected $propertyCharacteristics;
  140. /**
  141. * @ORM\Column(type="text", nullable=true)
  142. */
  143. protected $propertyWeight;
  144. /**
  145. * @ORM\Column(type="text", nullable=true)
  146. */
  147. protected $propertyQuantity;
  148. /**
  149. * @ORM\Column(type="text", nullable=true)
  150. */
  151. protected $propertyFeature;
  152. /**
  153. * @ORM\Column(type="text", nullable=true)
  154. */
  155. protected $propertyVariety;
  156. /**
  157. * @ORM\Column(type="text", nullable=true)
  158. */
  159. protected $propertyAlcoholLevel;
  160. /**
  161. * @ORM\Column(type="string", length=255, nullable=true)
  162. */
  163. protected $behaviorExpirationDate;
  164. /**
  165. * @ORM\Column(type="string", length=255, nullable=true)
  166. */
  167. protected $typeExpirationDate;
  168. /**
  169. * @ORM\Column(type="string", length=32, nullable=true)
  170. */
  171. protected $behaviorAddToCart;
  172. /**
  173. * @ORM\Column(type="string", length=31)
  174. */
  175. protected $behaviorPrice;
  176. /**
  177. * @ORM\Column(type="boolean")
  178. */
  179. protected $saleStatus;
  180. public function __construct()
  181. {
  182. $this->productCategories = new ArrayCollection();
  183. $this->products = new ArrayCollection();
  184. }
  185. public function __toString()
  186. {
  187. return $this->getTitle();
  188. }
  189. public function getAvailableQuantityInherited()
  190. {
  191. $availableQuantity = 0 ;
  192. switch ($this->getBehaviorCountStock()) {
  193. case self::BEHAVIOR_COUNT_STOCK_BY_MEASURE :
  194. case self::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY :
  195. $availableQuantity = $this->getAvailableQuantity() ;
  196. break;
  197. case self::BEHAVIOR_COUNT_STOCK_BY_PRODUCT :
  198. foreach($this->getProductsOnline() as $product) {
  199. $availableQuantity += $product->getAvailableQuantityInherited() ;
  200. }
  201. break ;
  202. case self::BEHAVIOR_COUNT_STOCK_UNLIMITED :
  203. $availableQuantity = false;
  204. break;
  205. }
  206. return $availableQuantity ;
  207. }
  208. public function getTaxRateInherited()
  209. {
  210. if ($this->getTaxRate()) {
  211. return $this->getTaxRate();
  212. } else {
  213. return $this->getMerchant()->getTaxRate();
  214. }
  215. }
  216. public function getMerchant(): ?Merchant
  217. {
  218. return $this->merchant;
  219. }
  220. public function setMerchant(?Merchant $merchant): self
  221. {
  222. $this->merchant = $merchant;
  223. return $this;
  224. }
  225. public function getActiveProducts(): ?bool
  226. {
  227. return $this->activeProducts;
  228. }
  229. public function setActiveProducts(bool $activeProducts): self
  230. {
  231. $this->activeProducts = $activeProducts;
  232. return $this;
  233. }
  234. public function getProductsQuantityAsTitle(): ?bool
  235. {
  236. return $this->productsQuantityAsTitle;
  237. }
  238. public function setProductsQuantityAsTitle(bool $productsQuantityAsTitle): self
  239. {
  240. $this->productsQuantityAsTitle = $productsQuantityAsTitle;
  241. return $this;
  242. }
  243. public function getProductsType(): ?string
  244. {
  245. return $this->productsType;
  246. }
  247. public function setProductsType(?string $productsType): self
  248. {
  249. $this->productsType = $productsType;
  250. return $this;
  251. }
  252. public function getQuantityLabel(): ?string
  253. {
  254. return $this->quantityLabel;
  255. }
  256. public function setQuantityLabel(?string $quantityLabel): self
  257. {
  258. $this->quantityLabel = $quantityLabel;
  259. return $this;
  260. }
  261. /**
  262. * @return Collection|ProductInterface[]
  263. */
  264. public function getProducts(): Collection
  265. {
  266. return $this->products;
  267. }
  268. public function getProductsOnline(): Collection
  269. {
  270. $products = $this->getProducts() ;
  271. $productsOnlineArray = new ArrayCollection() ;
  272. foreach($products as $product) {
  273. if($product->getStatus() == 1 && $product->getOriginProduct() !=true) {
  274. $productsOnlineArray[] = $product ;
  275. }
  276. }
  277. return $productsOnlineArray ;
  278. }
  279. public function addProduct(ProductInterface $product): self
  280. {
  281. if (!$this->products->contains($product)) {
  282. $this->products[] = $product;
  283. $product->setProductFamily($this);
  284. }
  285. return $this;
  286. }
  287. public function removeProduct(ProductInterface $product): self
  288. {
  289. if ($this->products->contains($product)) {
  290. $this->products->removeElement($product);
  291. // set the owning side to null (unless already changed)
  292. if ($product->getProductFamily() === $this) {
  293. $product->setProductFamily(null);
  294. }
  295. }
  296. return $this;
  297. }
  298. public function getReductionCatalog(): ?ReductionCatalog
  299. {
  300. return $this->reductionCatalog;
  301. }
  302. public function getReductionCatalogInherited(): ?ReductionCatalog
  303. {
  304. return $this->getReductionCatalog() ;
  305. }
  306. public function setReductionCatalog(?ReductionCatalog $reductionCatalog): self
  307. {
  308. $this->reductionCatalog = $reductionCatalog;
  309. return $this;
  310. }
  311. /**
  312. * @return Collection|ProductCategory[]
  313. */
  314. public function getProductCategories(): Collection
  315. {
  316. return $this->productCategories;
  317. }
  318. public function initProductCategories()
  319. {
  320. $this->productCategories = new ArrayCollection();
  321. }
  322. public function addProductCategory(ProductCategory $productCategory): self
  323. {
  324. if (!$this->productCategories->contains($productCategory)) {
  325. $this->productCategories[] = $productCategory;
  326. }
  327. return $this;
  328. }
  329. public function removeProductCategory(ProductCategory $productCategory): self
  330. {
  331. if ($this->productCategories->contains($productCategory)) {
  332. $this->productCategories->removeElement($productCategory);
  333. }
  334. return $this;
  335. }
  336. public function getProductCategoryParent()
  337. {
  338. $productCategories = $this->getProductCategories();
  339. if (count($productCategories) > 0) {
  340. return $productCategories[0]->getParent();
  341. }
  342. return false;
  343. }
  344. public function getProductCategoryChild()
  345. {
  346. $productCategories = $this->getProductCategories();
  347. foreach ($productCategories as $productCategory) {
  348. if ($productCategory->getParent()) {
  349. return $productCategory;
  350. }
  351. }
  352. return false;
  353. }
  354. public function getSupplierTaxRate(): ?TaxRate
  355. {
  356. return $this->supplierTaxRate;
  357. }
  358. public function setSupplierTaxRate(?TaxRate $supplierTaxRate): self
  359. {
  360. $this->supplierTaxRate = $supplierTaxRate;
  361. return $this;
  362. }
  363. public function getSubtitle(): ?string
  364. {
  365. return $this->subtitle;
  366. }
  367. public function setSubtitle(?string $subtitle): self
  368. {
  369. $this->subtitle = $subtitle;
  370. return $this;
  371. }
  372. public function getWarningMessage(): ?string
  373. {
  374. return $this->warningMessage;
  375. }
  376. public function setWarningMessage(?string $warningMessage): self
  377. {
  378. $this->warningMessage = $warningMessage;
  379. return $this;
  380. }
  381. public function getWarningMessageType(): ?string
  382. {
  383. return $this->warningMessageType;
  384. }
  385. public function setWarningMessageType(?string $warningMessageType): self
  386. {
  387. $this->warningMessageType = $warningMessageType;
  388. return $this;
  389. }
  390. public function getNote(): ?string
  391. {
  392. return $this->note;
  393. }
  394. public function setNote(?string $note): self
  395. {
  396. $this->note = $note;
  397. return $this;
  398. }
  399. public function getBehaviorOutOfStock(): ?string
  400. {
  401. return $this->behaviorOutOfStock;
  402. }
  403. public function setBehaviorOutOfStock(?string $behaviorOutOfStock): self
  404. {
  405. $this->behaviorOutOfStock = $behaviorOutOfStock;
  406. return $this;
  407. }
  408. public function getBehaviorCountStock(): ?string
  409. {
  410. return $this->behaviorCountStock;
  411. }
  412. public function setBehaviorCountStock(string $behaviorCountStock): self
  413. {
  414. $this->behaviorCountStock = $behaviorCountStock;
  415. return $this;
  416. }
  417. public function isPropertyNoveltyOnline(): ?bool
  418. {
  419. if ($this->getPropertyNoveltyExpirationDate()) {
  420. $now = new \DateTime();
  421. if ($now <= $this->getPropertyNoveltyExpirationDate()) {
  422. return true;
  423. }
  424. }
  425. return false;
  426. }
  427. public function getPropertyNoveltyExpirationDate(): ?\DateTimeInterface
  428. {
  429. return $this->propertyNoveltyExpirationDate;
  430. }
  431. public function setPropertyNoveltyExpirationDate(?\DateTimeInterface $propertyNoveltyExpirationDate): self
  432. {
  433. $this->propertyNoveltyExpirationDate = $propertyNoveltyExpirationDate;
  434. return $this;
  435. }
  436. public function getPropertyOrganicLabel(): ?string
  437. {
  438. return $this->propertyOrganicLabel;
  439. }
  440. public function setPropertyOrganicLabel(?string $propertyOrganicLabel): self
  441. {
  442. $this->propertyOrganicLabel = $propertyOrganicLabel;
  443. return $this;
  444. }
  445. public function getPropertyAllergens(): ?string
  446. {
  447. return $this->propertyAllergens;
  448. }
  449. public function setPropertyAllergens(?string $propertyAllergens): self
  450. {
  451. $this->propertyAllergens = $propertyAllergens;
  452. return $this;
  453. }
  454. public function getPropertyComposition(): ?string
  455. {
  456. return $this->propertyComposition;
  457. }
  458. public function setPropertyComposition(?string $propertyComposition): self
  459. {
  460. $this->propertyComposition = $propertyComposition;
  461. return $this;
  462. }
  463. public function getPropertyFragrances(): ?string
  464. {
  465. return $this->propertyFragrances;
  466. }
  467. public function setPropertyFragrances(?string $propertyFragrances): self
  468. {
  469. $this->propertyFragrances = $propertyFragrances;
  470. return $this;
  471. }
  472. public function countProperties(): bool
  473. {
  474. $count = 0;
  475. $count += (int)strlen($this->getPropertyOrganicLabel()) > 0;
  476. $count += (int)strlen($this->getPropertyWeight()) > 0;
  477. $count += (int)strlen($this->getPropertyFragrances()) > 0;
  478. $count += (int)strlen($this->getPropertyComposition()) > 0;
  479. $count += (int)strlen($this->getPropertyAllergens()) > 0;
  480. $count += (int)strlen($this->getPropertyAlcoholLevel()) > 0;
  481. $count += (int)strlen($this->getPropertyCharacteristics()) > 0;
  482. $count += (int)strlen($this->getPropertyFeature()) > 0;
  483. $count += (int)strlen($this->getPropertyPackaging()) > 0;
  484. $count += (int)strlen($this->getPropertyQuantity()) > 0;
  485. $count += (int)strlen($this->getPropertyVariety()) > 0;
  486. $count += (int)($this->getPropertyExpirationDate() != null);
  487. return $count;
  488. }
  489. public function getBehaviorExpirationDate(): ?string
  490. {
  491. return $this->behaviorExpirationDate;
  492. }
  493. public function setBehaviorExpirationDate(?string $behaviorExpirationDate): self
  494. {
  495. $this->behaviorExpirationDate = $behaviorExpirationDate;
  496. return $this;
  497. }
  498. public function getTypeExpirationDate(): ?string
  499. {
  500. return $this->typeExpirationDate;
  501. }
  502. public function setTypeExpirationDate(?string $typeExpirationDate): self
  503. {
  504. $this->typeExpirationDate = $typeExpirationDate;
  505. return $this;
  506. }
  507. public function getPropertyWeight(): ?string
  508. {
  509. return $this->propertyWeight;
  510. }
  511. public function setPropertyWeight(?string $propertyWeight): self
  512. {
  513. $this->propertyWeight = $propertyWeight;
  514. return $this;
  515. }
  516. public function getPropertyQuantity(): ?string
  517. {
  518. return $this->propertyQuantity;
  519. }
  520. public function setPropertyQuantity(?string $propertyQuantity): self
  521. {
  522. $this->propertyQuantity = $propertyQuantity;
  523. return $this;
  524. }
  525. public function getPropertyVariety(): ?string
  526. {
  527. return $this->propertyVariety;
  528. }
  529. public function setPropertyVariety(?string $propertyVariety): self
  530. {
  531. $this->propertyVariety = $propertyVariety;
  532. return $this;
  533. }
  534. public function getPropertyFeature(): ?string
  535. {
  536. return $this->propertyFeature;
  537. }
  538. public function setPropertyFeature(?string $propertyFeature): self
  539. {
  540. $this->propertyFeature = $propertyFeature;
  541. return $this;
  542. }
  543. public function getPropertyAlcoholLevel(): ?string
  544. {
  545. return $this->propertyAlcoholLevel;
  546. }
  547. public function setPropertyAlcoholLevel(?string $propertyAlcoholLevel): self
  548. {
  549. $this->propertyAlcoholLevel = $propertyAlcoholLevel;
  550. return $this;
  551. }
  552. public function getPropertyPackaging(): ?string
  553. {
  554. return $this->propertyPackaging;
  555. }
  556. public function setPropertyPackaging(?string $propertyPackaging): self
  557. {
  558. $this->propertyPackaging = $propertyPackaging;
  559. return $this;
  560. }
  561. public function getPropertyCharacteristics(): ?string
  562. {
  563. return $this->propertyCharacteristics;
  564. }
  565. public function setPropertyCharacteristics(?string $propertyCharacteristics): self
  566. {
  567. $this->propertyCharacteristics = $propertyCharacteristics;
  568. return $this;
  569. }
  570. public function getBehaviorAddToCart(): ?string
  571. {
  572. return $this->behaviorAddToCart;
  573. }
  574. public function setBehaviorAddToCart(?string $behaviorAddToCart): self
  575. {
  576. $this->behaviorAddToCart = $behaviorAddToCart;
  577. return $this;
  578. }
  579. public function getBehaviorPrice(): ?string
  580. {
  581. return $this->behaviorPrice;
  582. }
  583. public function getBehaviorPriceInherited()
  584. {
  585. return $this->getBehaviorPrice() ;
  586. }
  587. public function setBehaviorPrice(?string $behaviorPrice): self
  588. {
  589. $this->behaviorPrice = $behaviorPrice;
  590. return $this;
  591. }
  592. public function hasProductsWithVariousWeight()
  593. {
  594. if ($this->getActiveProducts()) {
  595. $arrayCountProducts = [];
  596. $products = $this->getProductsOnline();
  597. foreach ($products as $product) {
  598. $titleProduct = $product->getTitleInherited();
  599. if (!isset($arrayCountProducts[$titleProduct])) {
  600. $arrayCountProducts[$titleProduct] = [];
  601. }
  602. if (!in_array($product->getQuantityLabelInherited(), $arrayCountProducts[$titleProduct])) {
  603. $arrayCountProducts[$titleProduct][] = $product->getQuantityLabelInherited();
  604. }
  605. if (count($arrayCountProducts[$titleProduct]) > 1) {
  606. return true;
  607. }
  608. }
  609. }
  610. return false;
  611. }
  612. public function getProductsGroupByTitle()
  613. {
  614. $arrayProductsGroupByTitle = [];
  615. $products = $this->getProductsOnline();
  616. foreach ($products as $product) {
  617. if($product->getStatus() == 1) {
  618. $titleProduct = $product->getTitleInherited();
  619. if (!isset($arrayProductsGroupByTitle[$titleProduct])) {
  620. $arrayProductsGroupByTitle[$titleProduct] = [];
  621. }
  622. $arrayProductsGroupByTitle[$titleProduct][] = $product;
  623. }
  624. }
  625. return $arrayProductsGroupByTitle;
  626. }
  627. public function getOriginProduct()
  628. {
  629. $products = $this->getProducts() ;
  630. foreach($products as $product) {
  631. if($product->getOriginProduct()) {
  632. return $product ;
  633. }
  634. }
  635. }
  636. public function getOriginProductOnline()
  637. {
  638. $originProduct = $this->getOriginProduct() ;
  639. if($originProduct->getStatus()==1){
  640. return $originProduct;
  641. }else{
  642. return false;
  643. }
  644. }
  645. public function hasOneProductOnline()
  646. {
  647. if( ($this->getActiveProducts() && count($this->getProductsOnline()) > 0)
  648. || (!$this->getActiveProducts() && $this->getOriginProduct())){
  649. return true ;
  650. }
  651. return false ;
  652. }
  653. public function getSaleStatus(): ?bool
  654. {
  655. return $this->saleStatus;
  656. }
  657. public function setSaleStatus(bool $saleStatus): self
  658. {
  659. $this->saleStatus = $saleStatus;
  660. return $this;
  661. }
  662. }