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.

SwitchMerchantController.php 1.5KB

3 년 전
3 년 전
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. }