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.

44 line
1.4KB

  1. <?php
  2. namespace Lc\CaracoleBundle\Controller\Merchant;
  3. use Doctrine\ORM\EntityManagerInterface;
  4. use Lc\CaracoleBundle\Definition\MerchantSettingDefinition;
  5. use Lc\CaracoleBundle\Form\Merchant\SwitchMerchantFormType;
  6. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  7. use Symfony\Component\HttpFoundation\Request;
  8. use Symfony\Component\Security\Core\Security;
  9. use Symfony\Component\Routing\Annotation\Route;
  10. class FavoriteMerchantController extends AbstractController
  11. {
  12. /**
  13. * @Route("/merchant/favorite", name="carac_merchant_favorite")
  14. */
  15. public function favoriteMerchant(Request $request, Security $security, EntityManagerInterface $em)
  16. {
  17. $user = $security->getUser() ;
  18. if($user) {
  19. $form = $this->createForm(SwitchMerchantFormType::class);
  20. $form->handleRequest($request);
  21. if ($form->isSubmitted() && $form->isValid()) {
  22. $merchant = $form->get('merchant')->getData();
  23. if ($merchant) {
  24. $user->setFavoriteMerchant($merchant) ;
  25. $em->update($user) ;
  26. $em->flush() ;
  27. $url = $merchant->getSettingValue(MerchantSettingDefinition::SETTING_URL).'admin';
  28. if ($url) {
  29. return $this->redirect($url);
  30. }
  31. }
  32. }
  33. }
  34. }
  35. }