entityManager = $entityManager; $this->productFamilySectionPropertyFactory = $productFamilySectionPropertyFactory; $this->productFamilySectionPropertyStore = $productFamilySectionPropertyStore; } public function enable(ProductFamilyInterface $productFamily, SectionInterface $section, bool $flush = true): 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); } if($flush) { $this->entityManager->flush(); } } }