Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

FavoriteMerchantController.php 1.7KB

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