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.

45 lines
1.5KB

  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 $entityManager)
  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. $entityManager->update($user) ;
  26. $entityManager->flush() ;
  27. // @TODO : à fignoler, hein gamin ?
  28. $url = $merchant->getSettingValue(MerchantSettingDefinition::SETTING_URL).'admin';
  29. if ($url) {
  30. return $this->redirect($url);
  31. }
  32. }
  33. }
  34. }
  35. }
  36. }