From 346e544911827c379bdfed10f29ea40889d57078 Mon Sep 17 00:00:00 2001 From: Tobias Nilsson Date: Mon, 27 Jan 2020 11:19:27 +0100 Subject: [PATCH] issue/26384 Fix store switcher when using different base url on stores --- .../Magento/Store/Controller/Store/Redirect.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Store/Controller/Store/Redirect.php b/app/code/Magento/Store/Controller/Store/Redirect.php index 8f63a43f5db7c..c0488cc1698fc 100644 --- a/app/code/Magento/Store/Controller/Store/Redirect.php +++ b/app/code/Magento/Store/Controller/Store/Redirect.php @@ -15,6 +15,7 @@ use Magento\Store\Api\StoreRepositoryInterface; use Magento\Store\Api\StoreResolverInterface; use Magento\Store\Model\Store; +use Magento\Store\Model\StoreManagerInterface; use Magento\Store\Model\StoreResolver; use Magento\Store\Model\StoreSwitcher\HashGenerator; @@ -38,6 +39,11 @@ class Redirect extends Action implements HttpGetActionInterface, HttpPostActionI */ private $hashGenerator; + /** + * @var \Magento\Store\Model\StoreManagerInterface + */ + private $storeManager; + /** * @param Context $context * @param StoreRepositoryInterface $storeRepository @@ -45,6 +51,7 @@ class Redirect extends Action implements HttpGetActionInterface, HttpPostActionI * @param \Magento\Framework\Session\Generic $session * @param \Magento\Framework\Session\SidResolverInterface $sidResolver * @param HashGenerator $hashGenerator + * @param \Magento\Store\Model\StoreManagerInterface $storeManager * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function __construct( @@ -53,12 +60,14 @@ public function __construct( StoreResolverInterface $storeResolver, \Magento\Framework\Session\Generic $session, \Magento\Framework\Session\SidResolverInterface $sidResolver, - HashGenerator $hashGenerator + HashGenerator $hashGenerator, + StoreManagerInterface $storeManager ) { parent::__construct($context); $this->storeRepository = $storeRepository; $this->storeResolver = $storeResolver; $this->hashGenerator = $hashGenerator; + $this->storeManager = $storeManager; } /** @@ -81,6 +90,8 @@ public function execute() try { /** @var Store $fromStore */ $fromStore = $this->storeRepository->get($fromStoreCode); + /** @var Store $targetStore */ + $targetStore = $this->storeRepository->get($targetStoreCode); } catch (NoSuchEntityException $e) { $error = __('Requested store is not found'); } @@ -104,6 +115,7 @@ public function execute() '_nosid' => true, '_query' => $query ]; + $this->storeManager->setCurrentStore($targetStore); $this->_redirect->redirect($this->_response, 'stores/store/switch', $arguments); }