entityManager = $entityManager; $this->sectionContainer = $sectionContainer; } public function setMerchant(ProductFamilyInterface $productFamily, MerchantInterface $merchant): void { $sectionStore = $this->sectionContainer->getStore()->setMerchant($merchant); // Les ProductFamilySectionProperty sont créées en double, on rectifie ici $productFamilySectionPropertyArray = []; foreach($productFamily->getProductFamilySectionProperties() as $productFamilySectionProperty) { $productFamilySectionPropertyArray[$productFamilySectionProperty->getId()] = $productFamilySectionProperty; $productFamily->removeProductFamilySectionProperty($productFamilySectionProperty); } foreach($productFamilySectionPropertyArray as $productFamilySectionProperty) { $oldSection = $productFamilySectionProperty->getSection(); $newSection = $sectionStore->getOneByDevAlias($oldSection->getDevAlias()); if($newSection) { $productFamilySectionProperty->setProductFamily($productFamily); $productFamilySectionProperty->setSection($newSection); $productFamily->addProductFamilySectionProperty($productFamilySectionProperty); } else { $this->entityManager->remove($productFamilySectionProperty); $productFamily->removeProductFamilySectionProperty($productFamilySectionProperty); } } $productFamily->initProductCategories(); } }