Skip to content

Commit 346e544

Browse files
issue/26384 Fix store switcher when using different base url on stores
1 parent 0ac3443 commit 346e544

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

app/code/Magento/Store/Controller/Store/Redirect.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Magento\Store\Api\StoreRepositoryInterface;
1616
use Magento\Store\Api\StoreResolverInterface;
1717
use Magento\Store\Model\Store;
18+
use Magento\Store\Model\StoreManagerInterface;
1819
use Magento\Store\Model\StoreResolver;
1920
use Magento\Store\Model\StoreSwitcher\HashGenerator;
2021

@@ -38,13 +39,19 @@ class Redirect extends Action implements HttpGetActionInterface, HttpPostActionI
3839
*/
3940
private $hashGenerator;
4041

42+
/**
43+
* @var \Magento\Store\Model\StoreManagerInterface
44+
*/
45+
private $storeManager;
46+
4147
/**
4248
* @param Context $context
4349
* @param StoreRepositoryInterface $storeRepository
4450
* @param StoreResolverInterface $storeResolver
4551
* @param \Magento\Framework\Session\Generic $session
4652
* @param \Magento\Framework\Session\SidResolverInterface $sidResolver
4753
* @param HashGenerator $hashGenerator
54+
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
4855
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
4956
*/
5057
public function __construct(
@@ -53,12 +60,14 @@ public function __construct(
5360
StoreResolverInterface $storeResolver,
5461
\Magento\Framework\Session\Generic $session,
5562
\Magento\Framework\Session\SidResolverInterface $sidResolver,
56-
HashGenerator $hashGenerator
63+
HashGenerator $hashGenerator,
64+
StoreManagerInterface $storeManager
5765
) {
5866
parent::__construct($context);
5967
$this->storeRepository = $storeRepository;
6068
$this->storeResolver = $storeResolver;
6169
$this->hashGenerator = $hashGenerator;
70+
$this->storeManager = $storeManager;
6271
}
6372

6473
/**
@@ -81,6 +90,8 @@ public function execute()
8190
try {
8291
/** @var Store $fromStore */
8392
$fromStore = $this->storeRepository->get($fromStoreCode);
93+
/** @var Store $targetStore */
94+
$targetStore = $this->storeRepository->get($targetStoreCode);
8495
} catch (NoSuchEntityException $e) {
8596
$error = __('Requested store is not found');
8697
}
@@ -104,6 +115,7 @@ public function execute()
104115
'_nosid' => true,
105116
'_query' => $query
106117
];
118+
$this->storeManager->setCurrentStore($targetStore);
107119
$this->_redirect->redirect($this->_response, 'stores/store/switch', $arguments);
108120
}
109121

0 commit comments

Comments
 (0)