Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

55 linhas
1.5KB

  1. <?php
  2. namespace Lc\CaracoleBundle\Controller\Merchant;
  3. use Lc\CaracoleBundle\Container\Merchant\MerchantContainer;
  4. use Lc\CaracoleBundle\Controller\AbstractController;
  5. use Lc\CaracoleBundle\Definition\ActionDefinition;
  6. use Lc\CaracoleBundle\Definition\MerchantSettingDefinition;
  7. use Lc\CaracoleBundle\Form\Merchant\SwitchMerchantFormType;
  8. use Symfony\Component\HttpFoundation\Request;
  9. use Symfony\Component\Routing\Annotation\Route;
  10. class SwitchMerchantController extends AbstractController
  11. {
  12. /**
  13. * @Route("/merchant/switch", name="carac_merchant_switch")
  14. */
  15. public function switchMerchant(Request $request)
  16. {
  17. $form = $this->createForm(
  18. SwitchMerchantFormType::class,
  19. null,
  20. array('csrf_protection' => false)
  21. );
  22. $form->handleRequest($request);
  23. if ($form->isSubmitted() && $form->isValid()) {
  24. $merchant = $form->get('merchant')->getData();
  25. $context = $form->get('context')->getData();
  26. if ($merchant) {
  27. $url = $this->getSettingValue(
  28. $merchant,
  29. MerchantSettingDefinition::SETTING_URL
  30. );
  31. if ($context == 'admin') {
  32. $url .= 'admin';
  33. }
  34. }
  35. }
  36. if ($url) {
  37. return $this->redirect($url);
  38. } else {
  39. $this->addFlashTranslator('error', ActionDefinition::SWITCH_MERCHANT, 'Merchant');
  40. return $this->redirect($request->headers->get('referer'));
  41. }
  42. }
  43. }