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.

931 lines
27KB

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