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.

56 satır
1.6KB

  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. if(!$url) {
  36. $url = $request->headers->get('referer');
  37. }
  38. if($url) {
  39. return $this->redirect($url);
  40. }
  41. }
  42. $this->addFlashTranslator('error', ActionDefinition::SWITCH_MERCHANT, 'Merchant');
  43. return $this->redirectToRoute('frontend_home');
  44. }
  45. }