|
- <?php
-
- namespace Lc\CaracoleBundle\Builder\Product;
-
- use Doctrine\ORM\EntityManagerInterface;
- use Lc\CaracoleBundle\Factory\Product\ProductFamilySectionPropertyFactory;
- use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface;
- use Lc\CaracoleBundle\Model\Section\SectionInterface;
- use Lc\CaracoleBundle\Repository\Product\ProductFamilySectionPropertyStore;
- use Lc\CaracoleBundle\Solver\Product\ProductFamilySectionPropertySolver;
-
- class ProductFamilySectionPropertyBuilder
- {
- protected EntityManagerInterface $entityManager;
- protected ProductFamilySectionPropertyFactory $productFamilySectionPropertyFactory;
- protected ProductFamilySectionPropertySolver $productFamilySectionPropertySolver;
-
- public function __construct(
- EntityManagerInterface $entityManager,
- ProductFamilySectionPropertyFactory $productFamilySectionPropertyFactory,
- ProductFamilySectionPropertySolver $productFamilySectionPropertySolver
- ) {
- $this->entityManager = $entityManager;
- $this->productFamilySectionPropertyFactory = $productFamilySectionPropertyFactory;
- $this->productFamilySectionPropertySolver = $productFamilySectionPropertySolver;
- }
-
-
- public function enable(ProductFamilyInterface $productFamily, SectionInterface $section, bool $flush = true): void
- {
- $productFamilySectionProperty = $this->productFamilySectionPropertySolver->getProductFamilySectionProperty($productFamily, $section);
-
- if ($productFamilySectionProperty) {
- if (!$productFamilySectionProperty->getStatus()) {
- $productFamilySectionProperty->setStatus(1);
- $this->entityManager->update($productFamilySectionProperty);
- }
- } else {
- $productFamilySectionProperty = $this->productFamilySectionPropertyFactory->create($section, $productFamily);
- $productFamilySectionProperty->setStatus(1);
- $productFamily->addProductFamilySectionProperty($productFamilySectionProperty);
- $this->entityManager->create($productFamilySectionProperty);
- $this->entityManager->update($productFamily);
- }
-
- if($flush) {
- $this->entityManager->flush();
- }
- }
-
-
- public function disable(ProductFamilyInterface $productFamily, SectionInterface $section, bool $flush = true): void
- {
- $productFamilySectionProperty = $this->productFamilySectionPropertySolver->getProductFamilySectionProperty($productFamily, $section);
-
- if ($productFamilySectionProperty) {
- $productFamilySectionProperty->setStatus(0);
- $this->entityManager->update($productFamilySectionProperty);
- }
- if($flush) {
- $this->entityManager->flush();
- }
- }
-
- }
|