No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

50 líneas
2.0KB

  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. }