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(); } }