選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

66 行
2.7KB

  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. use Lc\CaracoleBundle\Solver\Product\ProductFamilySectionPropertySolver;
  9. class ProductFamilySectionPropertyBuilder
  10. {
  11. protected EntityManagerInterface $entityManager;
  12. protected ProductFamilySectionPropertyFactory $productFamilySectionPropertyFactory;
  13. protected ProductFamilySectionPropertySolver $productFamilySectionPropertySolver;
  14. public function __construct(
  15. EntityManagerInterface $entityManager,
  16. ProductFamilySectionPropertyFactory $productFamilySectionPropertyFactory,
  17. ProductFamilySectionPropertySolver $productFamilySectionPropertySolver
  18. ) {
  19. $this->entityManager = $entityManager;
  20. $this->productFamilySectionPropertyFactory = $productFamilySectionPropertyFactory;
  21. $this->productFamilySectionPropertySolver = $productFamilySectionPropertySolver;
  22. }
  23. public function enable(ProductFamilyInterface $productFamily, SectionInterface $section, bool $flush = true): void
  24. {
  25. $productFamilySectionProperty = $this->productFamilySectionPropertySolver->getProductFamilySectionProperty($productFamily, $section);
  26. if ($productFamilySectionProperty) {
  27. if (!$productFamilySectionProperty->getStatus()) {
  28. $productFamilySectionProperty->setStatus(1);
  29. $this->entityManager->update($productFamilySectionProperty);
  30. }
  31. } else {
  32. $productFamilySectionProperty = $this->productFamilySectionPropertyFactory->create($section, $productFamily);
  33. $productFamilySectionProperty->setStatus(1);
  34. $productFamily->addProductFamilySectionProperty($productFamilySectionProperty);
  35. $this->entityManager->create($productFamilySectionProperty);
  36. $this->entityManager->update($productFamily);
  37. }
  38. if($flush) {
  39. $this->entityManager->flush();
  40. }
  41. }
  42. public function disable(ProductFamilyInterface $productFamily, SectionInterface $section, bool $flush = true): void
  43. {
  44. $productFamilySectionProperty = $this->productFamilySectionPropertySolver->getProductFamilySectionProperty($productFamily, $section);
  45. if ($productFamilySectionProperty) {
  46. $productFamilySectionProperty->setStatus(0);
  47. $this->entityManager->update($productFamilySectionProperty);
  48. }
  49. if($flush) {
  50. $this->entityManager->flush();
  51. }
  52. }
  53. }