|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function new(AdminContext $context): Response |
|
|
public function new(AdminContext $context): Response |
|
|
{ |
|
|
{ |
|
|
|
|
|
$entityManager = $this->get('em'); |
|
|
$userFactory = $this->get('user_factory'); |
|
|
$userFactory = $this->get('user_factory'); |
|
|
$userMerchantFactory = $this->get('user_merchant_factory'); |
|
|
$userMerchantFactory = $this->get('user_merchant_factory'); |
|
|
$userRepository = $this->em->getRepository(UserInterface::class); |
|
|
|
|
|
|
|
|
$userRepository = $entityManager->getRepository(UserInterface::class); |
|
|
$merchantResolver = $this->get('merchant_resolver'); |
|
|
$merchantResolver = $this->get('merchant_resolver'); |
|
|
|
|
|
|
|
|
$userMerchant = $userMerchantFactory->create(); |
|
|
$userMerchant = $userMerchantFactory->create(); |
|
|
|
|
|
|
|
|
$form = $this->createForm(UserMerchantFormType::class, $userMerchant); |
|
|
$form = $this->createForm(UserMerchantFormType::class, $userMerchant); |
|
|
|
|
|
|
|
|
$form->handleRequest($context->getRequest()); |
|
|
$form->handleRequest($context->getRequest()); |
|
|
|
|
|
|
|
|
if ($form->isSubmitted() && $form->isValid()) { |
|
|
if ($form->isSubmitted() && $form->isValid()) { |
|
|
|
|
|
|
|
|
$userMerchant = $form->getData(); |
|
|
$userMerchant = $form->getData(); |
|
|
|
|
|
|
|
|
$existingUser = $userRepository->findOneByEmail($form->get('email')->getData()); |
|
|
$existingUser = $userRepository->findOneByEmail($form->get('email')->getData()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$user = $userFactory->create($param); |
|
|
$user = $userFactory->create($param); |
|
|
|
|
|
|
|
|
$this->em->create($user); |
|
|
|
|
|
|
|
|
$entityManager->create($user); |
|
|
$userMerchant->setUser($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(); |
|
|
$url = $this->get(AdminUrlGenerator::class)->setAction(Action::INDEX)->generateUrl(); |
|
|
|
|
|
|
|
|
return $this->redirect($url); |
|
|
return $this->redirect($url); |
|
|
|
|
|
|
|
|
$existingUserMerchant = $merchantResolver->getUserMerchant($existingUser); |
|
|
$existingUserMerchant = $merchantResolver->getUserMerchant($existingUser); |
|
|
if ($existingUserMerchant == null) { |
|
|
if ($existingUserMerchant == null) { |
|
|
$userMerchant->setUser($existingUser); |
|
|
$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(); |
|
|
$url = $this->get(AdminUrlGenerator::class)->setAction(Action::INDEX)->generateUrl(); |
|
|
|
|
|
|
|
|
return $this->redirect($url); |
|
|
return $this->redirect($url); |
|
|
} else { |
|
|
} 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')); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function edit(AdminContext $context): Response |
|
|
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'); |
|
|
$merchantResolver = $this->get('merchant_resolver'); |
|
|
|
|
|
|
|
|
$userMerchant = $context->getEntity()->getInstance(); |
|
|
$userMerchant = $context->getEntity()->getInstance(); |
|
|
|
|
|
|
|
|
$userMerchant->getUser()->setLastName($form->get('lastname')->getData()); |
|
|
$userMerchant->getUser()->setLastName($form->get('lastname')->getData()); |
|
|
$userMerchant->getUser()->setFirstname($form->get('firstname')->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(); |
|
|
$url = $this->get(AdminUrlGenerator::class)->setAction(Action::INDEX)->generateUrl(); |
|
|
|
|
|
|
|
|
return $this->redirect($url); |
|
|
return $this->redirect($url); |