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.

пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
пре 4 година
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608
  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. /**
  11. * @ORM\MappedSuperclass()
  12. */
  13. abstract class ProductFamily extends AbstractDocumentEntity implements ProductPropertyInterface, PriceInterface, FilterMerchantInterface
  14. {
  15. use ProductPropertyTrait;
  16. //Champ hydraté par ProductFamilyUtils
  17. protected $reductionCatalog;
  18. /**
  19. * @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\MerchantInterface", inversedBy="productFamilies")
  20. * @ORM\JoinColumn(nullable=false)
  21. */
  22. protected $merchant;
  23. /**
  24. * @ORM\ManyToMany(targetEntity="Lc\ShopBundle\Context\ProductCategoryInterface", inversedBy="productFamilies")
  25. */
  26. protected $productCategories;
  27. /**
  28. * @ORM\Column(type="boolean")
  29. */
  30. protected $activeProducts;
  31. /**
  32. * @ORM\Column(type="string", length=255, nullable=true)
  33. */
  34. protected $productsType;
  35. /**
  36. * @ORM\OneToMany(targetEntity="Lc\ShopBundle\Context\ProductInterface", mappedBy="productFamily", orphanRemoval=true, cascade={"persist"}, fetch="EAGER")
  37. */
  38. protected $products;
  39. /**
  40. * @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\TaxRateInterface")
  41. */
  42. protected $supplierTaxRate;
  43. /**
  44. * @ORM\Column(type="string", length=255, nullable=true)
  45. */
  46. protected $subtitle;
  47. /**
  48. * @ORM\Column(type="text", nullable=true)
  49. */
  50. protected $warningMessage;
  51. /**
  52. * @ORM\Column(type="string", length=255, nullable=true)
  53. */
  54. protected $warningMessageType;
  55. /**
  56. * @ORM\Column(type="text", nullable=true)
  57. */
  58. protected $note;
  59. /**
  60. * @ORM\Column(type="string", length=31, nullable=true)
  61. */
  62. protected $behaviorOutOfStock;
  63. /**
  64. * @ORM\Column(type="string", length=31)
  65. */
  66. protected $behaviorCountStock;
  67. /**
  68. * @ORM\Column(type="date", nullable=true)
  69. */
  70. protected $propertyNoveltyExpirationDate;
  71. /**
  72. * @ORM\Column(type="string", length=255, nullable=true)
  73. */
  74. protected $propertyOrganicLabel;
  75. /**
  76. * @ORM\Column(type="text", nullable=true)
  77. */
  78. protected $propertyAllergens;
  79. /**
  80. * @ORM\Column(type="text", nullable=true)
  81. */
  82. protected $propertyComposition;
  83. /**
  84. * @ORM\Column(type="text", nullable=true)
  85. */
  86. protected $propertyFragrances;
  87. /**
  88. * @ORM\Column(type="text", nullable=true)
  89. */
  90. protected $propertyWeightQuantity;
  91. /**
  92. * @ORM\Column(type="text", nullable=true)
  93. */
  94. protected $propertyPackaging;
  95. /**
  96. * @ORM\Column(type="text", nullable=true)
  97. */
  98. protected $propertyCharacteristics;
  99. /**
  100. * @ORM\Column(type="string", length=255, nullable=true)
  101. */
  102. protected $behaviorExpirationDate;
  103. /**
  104. * @ORM\Column(type="string", length=255, nullable=true)
  105. */
  106. protected $typeExpirationDate;
  107. /**
  108. * @ORM\Column(type="string", length=32, nullable=true)
  109. */
  110. protected $behaviorAddToCart;
  111. /**
  112. * @ORM\Column(type="string", length=31)
  113. */
  114. protected $behaviorPrice;
  115. public function __construct()
  116. {
  117. $this->productCategories = new ArrayCollection();
  118. $this->products = new ArrayCollection();
  119. }
  120. public function __toString()
  121. {
  122. return $this->getTitle();
  123. }
  124. public function getTaxRateInherited()
  125. {
  126. if ($this->getTaxRate()) {
  127. return $this->getTaxRate();
  128. } else {
  129. return $this->getMerchant()->getTaxRate();
  130. }
  131. }
  132. public function getMerchant(): ?Merchant
  133. {
  134. return $this->merchant;
  135. }
  136. public function setMerchant(?Merchant $merchant): self
  137. {
  138. $this->merchant = $merchant;
  139. return $this;
  140. }
  141. public function getActiveProducts(): ?bool
  142. {
  143. return $this->activeProducts;
  144. }
  145. public function setActiveProducts(bool $activeProducts): self
  146. {
  147. $this->activeProducts = $activeProducts;
  148. return $this;
  149. }
  150. public function getProductsType(): ?string
  151. {
  152. return $this->productsType;
  153. }
  154. public function setProductsType(?string $productsType): self
  155. {
  156. $this->productsType = $productsType;
  157. return $this;
  158. }
  159. /**
  160. * @return Collection|ProductInterface[]
  161. */
  162. public function getProducts(): Collection
  163. {
  164. return $this->products;
  165. }
  166. public function addProduct(ProductInterface $product): self
  167. {
  168. if (!$this->products->contains($product)) {
  169. $this->products[] = $product;
  170. $product->setProductFamily($this);
  171. }
  172. return $this;
  173. }
  174. public function removeProduct(ProductInterface $product): self
  175. {
  176. if ($this->products->contains($product)) {
  177. $this->products->removeElement($product);
  178. // set the owning side to null (unless already changed)
  179. if ($product->getProductFamily() === $this) {
  180. $product->setProductFamily(null);
  181. }
  182. }
  183. return $this;
  184. }
  185. public function getReductionCatalog(): ?ReductionCatalog
  186. {
  187. return $this->reductionCatalog;
  188. }
  189. public function getReductionCatalogInherited(): ?ReductionCatalog
  190. {
  191. return $this->getReductionCatalog() ;
  192. }
  193. public function setReductionCatalog(?ReductionCatalog $reductionCatalog): self
  194. {
  195. $this->reductionCatalog = $reductionCatalog;
  196. return $this;
  197. }
  198. /**
  199. * @return Collection|ProductCategory[]
  200. */
  201. public function getProductCategories(): Collection
  202. {
  203. return $this->productCategories;
  204. }
  205. public function initProductCategories()
  206. {
  207. $this->productCategories = new ArrayCollection();
  208. }
  209. public function addProductCategory(ProductCategory $productCategory): self
  210. {
  211. if (!$this->productCategories->contains($productCategory)) {
  212. $this->productCategories[] = $productCategory;
  213. }
  214. return $this;
  215. }
  216. public function removeProductCategory(ProductCategory $productCategory): self
  217. {
  218. if ($this->productCategories->contains($productCategory)) {
  219. $this->productCategories->removeElement($productCategory);
  220. }
  221. return $this;
  222. }
  223. public function getProductCategoryParent()
  224. {
  225. $productCategories = $this->getProductCategories();
  226. if (count($productCategories) > 0) {
  227. return $productCategories[0]->getParent();
  228. }
  229. return false;
  230. }
  231. public function getProductCategoryChild()
  232. {
  233. $productCategories = $this->getProductCategories();
  234. foreach ($productCategories as $productCategory) {
  235. if ($productCategory->getParent()) {
  236. return $productCategory;
  237. }
  238. }
  239. return false;
  240. }
  241. public function getSupplierTaxRate(): ?TaxRate
  242. {
  243. return $this->supplierTaxRate;
  244. }
  245. public function setSupplierTaxRate(?TaxRate $supplierTaxRate): self
  246. {
  247. $this->supplierTaxRate = $supplierTaxRate;
  248. return $this;
  249. }
  250. public function getSubtitle(): ?string
  251. {
  252. return $this->subtitle;
  253. }
  254. public function setSubtitle(?string $subtitle): self
  255. {
  256. $this->subtitle = $subtitle;
  257. return $this;
  258. }
  259. public function getWarningMessage(): ?string
  260. {
  261. return $this->warningMessage;
  262. }
  263. public function setWarningMessage(?string $warningMessage): self
  264. {
  265. $this->warningMessage = $warningMessage;
  266. return $this;
  267. }
  268. public function getWarningMessageType(): ?string
  269. {
  270. return $this->warningMessageType;
  271. }
  272. public function setWarningMessageType(?string $warningMessageType): self
  273. {
  274. $this->warningMessageType = $warningMessageType;
  275. return $this;
  276. }
  277. public function getNote(): ?string
  278. {
  279. return $this->note;
  280. }
  281. public function setNote(?string $note): self
  282. {
  283. $this->note = $note;
  284. return $this;
  285. }
  286. public function getBehaviorOutOfStock(): ?string
  287. {
  288. return $this->behaviorOutOfStock;
  289. }
  290. public function setBehaviorOutOfStock(?string $behaviorOutOfStock): self
  291. {
  292. $this->behaviorOutOfStock = $behaviorOutOfStock;
  293. return $this;
  294. }
  295. public function getBehaviorCountStock(): ?string
  296. {
  297. return $this->behaviorCountStock;
  298. }
  299. public function setBehaviorCountStock(string $behaviorCountStock): self
  300. {
  301. $this->behaviorCountStock = $behaviorCountStock;
  302. return $this;
  303. }
  304. public function isPropertyNoveltyOnline(): ?bool
  305. {
  306. if ($this->getPropertyNoveltyExpirationDate()) {
  307. $now = new \DateTime();
  308. if ($now <= $this->getPropertyNoveltyExpirationDate()) {
  309. return true;
  310. }
  311. }
  312. return false;
  313. }
  314. public function getPropertyNoveltyExpirationDate(): ?\DateTimeInterface
  315. {
  316. return $this->propertyNoveltyExpirationDate;
  317. }
  318. public function setPropertyNoveltyExpirationDate(?\DateTimeInterface $propertyNoveltyExpirationDate): self
  319. {
  320. $this->propertyNoveltyExpirationDate = $propertyNoveltyExpirationDate;
  321. return $this;
  322. }
  323. public function getPropertyOrganicLabel(): ?string
  324. {
  325. return $this->propertyOrganicLabel;
  326. }
  327. public function setPropertyOrganicLabel(?string $propertyOrganicLabel): self
  328. {
  329. $this->propertyOrganicLabel = $propertyOrganicLabel;
  330. return $this;
  331. }
  332. public function getPropertyAllergens(): ?string
  333. {
  334. return $this->propertyAllergens;
  335. }
  336. public function setPropertyAllergens(?string $propertyAllergens): self
  337. {
  338. $this->propertyAllergens = $propertyAllergens;
  339. return $this;
  340. }
  341. public function getPropertyComposition(): ?string
  342. {
  343. return $this->propertyComposition;
  344. }
  345. public function setPropertyComposition(?string $propertyComposition): self
  346. {
  347. $this->propertyComposition = $propertyComposition;
  348. return $this;
  349. }
  350. public function getPropertyFragrances(): ?string
  351. {
  352. return $this->propertyFragrances;
  353. }
  354. public function setPropertyFragrances(?string $propertyFragrances): self
  355. {
  356. $this->propertyFragrances = $propertyFragrances;
  357. return $this;
  358. }
  359. public function countProperties(): bool
  360. {
  361. $count = 0;
  362. $count += (int)strlen($this->getPropertyAllergens()) > 0;
  363. $count += (int)strlen($this->getPropertyComposition()) > 0;
  364. $count += (int)strlen($this->getPropertyFragrances()) > 0;
  365. $count += (int)strlen($this->getPropertyOrganicLabel()) > 0;
  366. $count += (int)($this->getPropertyExpirationDate() != null);
  367. return $count;
  368. }
  369. public function getBehaviorExpirationDate(): ?string
  370. {
  371. return $this->behaviorExpirationDate;
  372. }
  373. public function setBehaviorExpirationDate(?string $behaviorExpirationDate): self
  374. {
  375. $this->behaviorExpirationDate = $behaviorExpirationDate;
  376. return $this;
  377. }
  378. public function getTypeExpirationDate(): ?string
  379. {
  380. return $this->typeExpirationDate;
  381. }
  382. public function setTypeExpirationDate(?string $typeExpirationDate): self
  383. {
  384. $this->typeExpirationDate = $typeExpirationDate;
  385. return $this;
  386. }
  387. public function getPropertyWeightQuantity(): ?string
  388. {
  389. return $this->propertyWeightQuantity;
  390. }
  391. public function setPropertyWeightQuantity(?string $propertyWeightQuantity): self
  392. {
  393. $this->propertyWeightQuantity = $propertyWeightQuantity;
  394. return $this;
  395. }
  396. public function getPropertyPackaging(): ?string
  397. {
  398. return $this->propertyPackaging;
  399. }
  400. public function setPropertyPackaging(?string $propertyPackaging): self
  401. {
  402. $this->propertyPackaging = $propertyPackaging;
  403. return $this;
  404. }
  405. public function getPropertyCharacteristics(): ?string
  406. {
  407. return $this->propertyCharacteristics;
  408. }
  409. public function setPropertyCharacteristics(?string $propertyCharacteristics): self
  410. {
  411. $this->propertyCharacteristics = $propertyCharacteristics;
  412. return $this;
  413. }
  414. public function getBehaviorAddToCart(): ?string
  415. {
  416. return $this->behaviorAddToCart;
  417. }
  418. public function setBehaviorAddToCart(?string $behaviorAddToCart): self
  419. {
  420. $this->behaviorAddToCart = $behaviorAddToCart;
  421. return $this;
  422. }
  423. public function getBehaviorPrice(): ?string
  424. {
  425. return $this->behaviorPrice;
  426. }
  427. public function getBehaviorPriceInherited()
  428. {
  429. return $this->getBehaviorPrice() ;
  430. }
  431. public function setBehaviorPrice(?string $behaviorPrice): self
  432. {
  433. $this->behaviorPrice = $behaviorPrice;
  434. return $this;
  435. }
  436. public function hasProductsWithVariousWeight()
  437. {
  438. if ($this->getActiveProducts()) {
  439. $arrayCountProducts = [];
  440. $products = $this->getProducts();
  441. foreach ($products as $product) {
  442. $titleProduct = $product->getTitleInherited();
  443. if (!isset($arrayCountProducts[$titleProduct])) {
  444. $arrayCountProducts[$titleProduct] = [];
  445. }
  446. if (!in_array($product->getQuantityLabelInherited(), $arrayCountProducts[$titleProduct])) {
  447. $arrayCountProducts[$titleProduct][] = $product->getQuantityLabelInherited();
  448. }
  449. if (count($arrayCountProducts[$titleProduct]) > 1) {
  450. return true;
  451. }
  452. }
  453. }
  454. return false;
  455. }
  456. public function getProductsGroupByTitle()
  457. {
  458. $arrayProductsGroupByTitle = [];
  459. $products = $this->getProducts();
  460. foreach ($products as $product) {
  461. $titleProduct = $product->getTitleInherited();
  462. if (!isset($arrayProductsGroupByTitle[$titleProduct])) {
  463. $arrayProductsGroupByTitle[$titleProduct] = [];
  464. }
  465. $arrayProductsGroupByTitle[$titleProduct][] = $product;
  466. }
  467. return $arrayProductsGroupByTitle;
  468. }
  469. }