You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
1.0KB

  1. <?php
  2. namespace Lc\CaracoleBundle\Controller\Merchant;
  3. use Lc\CaracoleBundle\Form\Merchant\SwitchMerchantFormType;
  4. use Lc\SovBundle\Doctrine\EntityManager;
  5. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  6. use Symfony\Component\HttpFoundation\Request;
  7. use Symfony\Component\Security\Core\Security;
  8. class SwitchMerchantController extends AbstractController
  9. {
  10. public function switchMerchant(Request $request, Security $security, EntityManager $em)
  11. {
  12. $user = $security->getUser() ;
  13. if($user) {
  14. $form = $this->createForm(SwitchMerchantFormType::class);
  15. $form->handleRequest($request);
  16. if ($form->isSubmitted() && $form->isValid()) {
  17. $merchant = $form->get('merchants')->getData();
  18. $user->setFavoriteMerchant($merchant) ;
  19. $em->update($user) ;
  20. $em->flush() ;
  21. return $this->redirectToRoute('admin_dashboard') ;
  22. }
  23. }
  24. else {
  25. }
  26. }
  27. }