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.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. namespace Lc\CaracoleBundle\Controller\Merchant;
  3. use Lc\CaracoleBundle\Container\Merchant\MerchantContainer;
  4. use Lc\CaracoleBundle\Definition\MerchantSettingDefinition;
  5. use Lc\CaracoleBundle\Form\Merchant\SwitchMerchantFormType;
  6. use Lc\CaracoleBundle\Repository\Merchant\MerchantRepository;
  7. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  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(SwitchMerchantFormType::class);
  18. $form->handleRequest($request);
  19. if ($form->isSubmitted() && $form->isValid()) {
  20. $merchant = $form->get('merchant')->getData();
  21. $context = $form->get('context')->getData();
  22. if ($merchant) {
  23. $url = $this->get(MerchantContainer::class)->getSettingSolver()->getSettingValue(
  24. $merchant,
  25. MerchantSettingDefinition::SETTING_URL
  26. );
  27. if ($context == 'admin') {
  28. $url .= 'admin';
  29. }
  30. if ($url) {
  31. return $this->redirect($url);
  32. }
  33. }
  34. }
  35. }
  36. }