Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

ProductFamilySectionPropertyBuilder.php 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace Lc\CaracoleBundle\Builder\Product;
  3. use Doctrine\ORM\EntityManagerInterface;
  4. use Lc\CaracoleBundle\Factory\Product\ProductFamilySectionPropertyFactory;
  5. use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface;
  6. use Lc\CaracoleBundle\Model\Section\SectionInterface;
  7. use Lc\CaracoleBundle\Repository\Product\ProductFamilySectionPropertyStore;
  8. class ProductFamilySectionPropertyBuilder
  9. {
  10. protected EntityManagerInterface $entityManager;
  11. protected ProductFamilySectionPropertyFactory $productFamilySectionPropertyFactory;
  12. protected ProductFamilySectionPropertyStore $productFamilySectionPropertyStore;
  13. public function __construct(
  14. EntityManagerInterface $entityManager,
  15. ProductFamilySectionPropertyFactory $productFamilySectionPropertyFactory,
  16. ProductFamilySectionPropertyStore $productFamilySectionPropertyStore
  17. ) {
  18. $this->entityManager = $entityManager;
  19. $this->productFamilySectionPropertyFactory = $productFamilySectionPropertyFactory;
  20. $this->productFamilySectionPropertyStore = $productFamilySectionPropertyStore;
  21. }
  22. public function enable(ProductFamilyInterface $productFamily, SectionInterface $section, bool $flush = true): void
  23. {
  24. $productFamilySectionProperty = $this->productFamilySectionPropertyStore
  25. ->setSection($section)
  26. ->getOneByProductFamily($productFamily);
  27. if ($productFamilySectionProperty) {
  28. if (!$productFamilySectionProperty->getStatus()) {
  29. $productFamilySectionProperty->setStatus(1);
  30. $this->entityManager->update($productFamilySectionProperty);
  31. }
  32. } else {
  33. $productFamilySectionProperty = $this->productFamilySectionPropertyFactory->create($section, $productFamily);
  34. $productFamilySectionProperty->setStatus(1);
  35. $this->entityManager->create($productFamilySectionProperty);
  36. }
  37. if($flush) {
  38. $this->entityManager->flush();
  39. }
  40. }
  41. }