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