createAvailableOptions($entity) ; parent::persistEntity($entity); } public function updateEntity($entity) { $this->createAvailableOptions($entity) ; parent::updateEntity($entity); } public function createAvailableOptions($entity) { $merchantConfigs = $entity->getMerchantConfigs() ; $availableOptions = MerchantConfig::getAvailableOptions() ; foreach($availableOptions as $key => $option) { $optionExist = false ; foreach($merchantConfigs as $merchantConfig) { if($merchantConfig->getName() == $key) { $optionExist = true ; } } if(!$optionExist) { $merchantConfig = new MerchantConfig(); $merchantConfig->setName($key)->setValue($merchantConfig->getOptionValue('default'))->setMerchant($entity) ; $this->em->persist($merchantConfig); } } $this->em->flush() ; } public function editAction() { // paramètres (admin) $isSettings = $this->request->query->get('is_settings') ; if($isSettings) { $idMerchant = $this->security->getUser()->getMerchant()->getId() ; $this->request->query->set('id', $idMerchant) ; $easyadmin = $this->request->attributes->get('easyadmin'); $merchant = $this->getDoctrine() ->getRepository(MerchantInterface::class) ->find($idMerchant); $easyadmin['item'] = $merchant; $this->request->attributes->set('easyadmin', $easyadmin) ; $response = parent::editAction() ; if ($response instanceof RedirectResponse) { $referer = $this->request->headers->get('referer'); return new RedirectResponse($referer); } else { return $response ; } } // édition des Merchant (super admin) else { return parent::editAction() ; } } public function switchMerchantAction(Request $request): RedirectResponse { $em = $this->getDoctrine()->getManager(); $user = $this->security->getUser() ; if($user->hasRole('ROLE_SUPER_ADMIN')) { $idMerchant = $request->request->get('id_merchant'); $merchant = $this->getDoctrine() ->getRepository(MerchantInterface::class) ->find($idMerchant); if ($merchant) { $user->setMerchant($merchant); $em->persist($user); $em->flush(); } } return $this->redirect('admin/dashboard') ; } }