|
|
@@ -30,11 +30,11 @@ abstract class UserMerchantAdminController extends AbstractAdminController |
|
|
|
|
|
|
|
public function new(AdminContext $context): Response |
|
|
|
{ |
|
|
|
$entityManager = $this->get('em'); |
|
|
|
$userFactory = $this->get('user_factory'); |
|
|
|
$userMerchantFactory = $this->get('user_merchant_factory'); |
|
|
|
$userRepository = $this->em->getRepository(UserInterface::class); |
|
|
|
$userRepository = $entityManager->getRepository(UserInterface::class); |
|
|
|
$merchantResolver = $this->get('merchant_resolver'); |
|
|
|
|
|
|
|
$userMerchant = $userMerchantFactory->create(); |
|
|
|
|
|
|
|
$form = $this->createForm(UserMerchantFormType::class, $userMerchant); |
|
|
@@ -42,6 +42,7 @@ abstract class UserMerchantAdminController extends AbstractAdminController |
|
|
|
$form->handleRequest($context->getRequest()); |
|
|
|
|
|
|
|
if ($form->isSubmitted() && $form->isValid()) { |
|
|
|
|
|
|
|
$userMerchant = $form->getData(); |
|
|
|
|
|
|
|
$existingUser = $userRepository->findOneByEmail($form->get('email')->getData()); |
|
|
@@ -54,11 +55,11 @@ abstract class UserMerchantAdminController extends AbstractAdminController |
|
|
|
|
|
|
|
$user = $userFactory->create($param); |
|
|
|
|
|
|
|
$this->em->create($user); |
|
|
|
$entityManager->create($user); |
|
|
|
$userMerchant->setUser($user); |
|
|
|
$this->em->create($userMerchant); |
|
|
|
$this->em->flush(); |
|
|
|
$this->addFlash('success', $this->translatorAdmin->trans('form.user_merchant.create')); |
|
|
|
$entityManager->create($userMerchant); |
|
|
|
$entityManager->flush(); |
|
|
|
$this->addFlash('success', $this->get('translator_admin')->trans('form.user_merchant.create')); |
|
|
|
$url = $this->get(AdminUrlGenerator::class)->setAction(Action::INDEX)->generateUrl(); |
|
|
|
|
|
|
|
return $this->redirect($url); |
|
|
@@ -67,15 +68,15 @@ abstract class UserMerchantAdminController extends AbstractAdminController |
|
|
|
$existingUserMerchant = $merchantResolver->getUserMerchant($existingUser); |
|
|
|
if ($existingUserMerchant == null) { |
|
|
|
$userMerchant->setUser($existingUser); |
|
|
|
$this->em->create($userMerchant); |
|
|
|
$this->em->flush(); |
|
|
|
$entityManager->create($userMerchant); |
|
|
|
$entityManager->flush(); |
|
|
|
|
|
|
|
$this->addFlash('success', $this->translatorAdmin->trans('form.user_merchant.linked')); |
|
|
|
$this->addFlash('success', $this->get('translator_admin')->trans('form.user_merchant.linked')); |
|
|
|
$url = $this->get(AdminUrlGenerator::class)->setAction(Action::INDEX)->generateUrl(); |
|
|
|
|
|
|
|
return $this->redirect($url); |
|
|
|
} else { |
|
|
|
$this->addFlash('error', $this->translatorAdmin->trans('form.user_merchant.already_exist')); |
|
|
|
$this->addFlash('error', $this->get('translator_admin')->trans('form.user_merchant.already_exist')); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@@ -91,7 +92,8 @@ abstract class UserMerchantAdminController extends AbstractAdminController |
|
|
|
|
|
|
|
public function edit(AdminContext $context): Response |
|
|
|
{ |
|
|
|
$userRepository = $this->em->getRepository(UserInterface::class); |
|
|
|
$entityManager = $this->get('em'); |
|
|
|
$userRepository = $entityManager->getRepository(UserInterface::class); |
|
|
|
$merchantResolver = $this->get('merchant_resolver'); |
|
|
|
|
|
|
|
$userMerchant = $context->getEntity()->getInstance(); |
|
|
@@ -107,10 +109,10 @@ abstract class UserMerchantAdminController extends AbstractAdminController |
|
|
|
$userMerchant->getUser()->setLastName($form->get('lastname')->getData()); |
|
|
|
$userMerchant->getUser()->setFirstname($form->get('firstname')->getData()); |
|
|
|
|
|
|
|
$this->em->update($userMerchant); |
|
|
|
$this->em->update($userMerchant->getUser()); |
|
|
|
$this->em->flush(); |
|
|
|
$this->addFlash('success', $this->translatorAdmin->trans('form.user_merchant.update')); |
|
|
|
$entityManager->update($userMerchant); |
|
|
|
$entityManager->update($userMerchant->getUser()); |
|
|
|
$entityManager->flush(); |
|
|
|
$this->addFlash('success', $this->get('translator_admin')->trans('form.user_merchant.update')); |
|
|
|
$url = $this->get(AdminUrlGenerator::class)->setAction(Action::INDEX)->generateUrl(); |
|
|
|
|
|
|
|
return $this->redirect($url); |