entityManager = $entityManager; $this->productCategoryContainer = $productCategoryContainer; } public static function getSubscribedEvents() { return [ EntityManagerEvent::PRE_CREATE_EVENT => ['processBeforePersistProductFamilySectionInterface'], EntityManagerEvent::PRE_UPDATE_EVENT => ['processBeforePersistProductFamilySectionInterface'], ]; } public function processBeforePersistProductFamilySectionInterface(EntityManagerEvent $event) { if ($event->getEntity() instanceof ProductFamilySectionPropertyInterface) { $this->setProductCategoryByProductFamilySectionProperty($event->getEntity()); } else if ($event->getEntity() instanceof ProductFamilyInterface) { foreach ($event->getEntity()->getProductFamilySectionProperties() as $productFamilySectionProperty) { $this->setProductCategoryByProductFamilySectionProperty($productFamilySectionProperty); } } } protected function setProductCategoryByProductFamilySectionProperty($productFamilySectionProperty) { $productFamily = $productFamilySectionProperty->getProductFamily(); if ($productFamilySectionProperty->getStatus() == 1 && $productFamily->getStatus() == 1) { $section = $productFamilySectionProperty->getSection(); $productCategoryArray = $productFamilySectionProperty->getProductFamily()->getProductCategories(); foreach ($productCategoryArray as $productCategory) { if ($productCategory->getSection() === $section) { $this->productCategoryContainer->getBuilder()->setOnlineIfOnlineProductfamily($productCategory); } } } else if ($productFamilySectionProperty->getStatus() == 0 || $productFamily->getStatus() == 0) { $section = $productFamilySectionProperty->getSection(); $productCategoryArray = $productFamilySectionProperty->getProductFamily()->getProductCategories(); foreach ($productCategoryArray as $productCategory) { if ($productCategory->getSection() === $section) { $this->productCategoryContainer->getBuilder()->setOfflineIfOfflineProductfamily($productCategory); } } } } }