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.

40 lines
1.2KB

  1. <?php
  2. namespace Lc\CaracoleBundle\Controller\Merchant;
  3. use Lc\CaracoleBundle\Definition\MerchantSettingDefinition;
  4. use Lc\CaracoleBundle\Form\Merchant\SwitchMerchantFormType;
  5. use Lc\CaracoleBundle\Repository\Merchant\MerchantRepository;
  6. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  7. use Symfony\Component\HttpFoundation\Request;
  8. use Symfony\Component\Routing\Annotation\Route;
  9. class SwitchMerchantController extends AbstractController
  10. {
  11. /**
  12. * @Route("/merchant/switch", name="carac_merchant_switch")
  13. */
  14. public function switchMerchant(Request $request)
  15. {
  16. $form = $this->createForm(SwitchMerchantFormType::class);
  17. $form->handleRequest($request);
  18. if ($form->isSubmitted() && $form->isValid()) {
  19. $merchant = $form->get('merchant')->getData();
  20. $context = $form->get('context')->getData();
  21. if ($merchant) {
  22. $url = $merchant->getSettingValue(MerchantSettingDefinition::SETTING_URL);
  23. if ($context == 'admin') {
  24. $url .= 'admin';
  25. }
  26. if ($url) {
  27. return $this->redirect($url);
  28. }
  29. }
  30. }
  31. }
  32. }