Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

48 lines
1.7KB

  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. }