Skip to content

Commit

Permalink
issue/26384 Fix store switcher when using different base url on stores
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiasLufinity committed Jan 27, 2020
1 parent 0ac3443 commit 346e544
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion app/code/Magento/Store/Controller/Store/Redirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

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

/**
* @var \Magento\Store\Model\StoreManagerInterface
*/
private $storeManager;

/**
* @param Context $context
* @param StoreRepositoryInterface $storeRepository
* @param StoreResolverInterface $storeResolver
* @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(
Expand All @@ -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;
}

/**
Expand All @@ -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');
}
Expand All @@ -104,6 +115,7 @@ public function execute()
'_nosid' => true,
'_query' => $query
];
$this->storeManager->setCurrentStore($targetStore);
$this->_redirect->redirect($this->_response, 'stores/store/switch', $arguments);
}

Expand Down

0 comments on commit 346e544

Please sign in to comment.