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.

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