|
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- <?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;
-
- class ProductFamilySectionPropertyBuilder
- {
- protected EntityManagerInterface $entityManager;
- protected ProductFamilySectionPropertyFactory $productFamilySectionPropertyFactory;
- protected ProductFamilySectionPropertyStore $productFamilySectionPropertyStore;
-
- public function __construct(
- EntityManagerInterface $entityManager,
- ProductFamilySectionPropertyFactory $productFamilySectionPropertyFactory,
- ProductFamilySectionPropertyStore $productFamilySectionPropertyStore
- ) {
- $this->entityManager = $entityManager;
- $this->productFamilySectionPropertyFactory = $productFamilySectionPropertyFactory;
- $this->productFamilySectionPropertyStore = $productFamilySectionPropertyStore;
- }
-
- public function enable(ProductFamilyInterface $productFamily, SectionInterface $section): void
- {
- $productFamilySectionProperty = $this->productFamilySectionPropertyStore
- ->setSection($section)
- ->getOneByProductFamily($productFamily);
-
- if ($productFamilySectionProperty) {
- if (!$productFamilySectionProperty->getStatus()) {
- $productFamilySectionProperty->setStatus(1);
- $this->entityManager->update($productFamilySectionProperty);
- }
- } else {
- $productFamilySectionProperty = $this->productFamilySectionPropertyFactory->create($section, $productFamily);
- $productFamilySectionProperty->setStatus(1);
- $this->entityManager->create($productFamilySectionProperty);
- }
-
- $this->entityManager->flush();
- }
-
- }
|