scopeConfig = $scopeConfig; $this->storeManager = $storeManager; $this->queryParamsResolver = $queryParamsResolver; } /** * Process scope query parameters. * * @param \Magento\Framework\Url\RouteParamsResolver $subject * @param array $data * @param bool $unsetOldParams * @throws \Magento\Framework\Exception\NoSuchEntityException * * @return array */ public function beforeSetRouteParams( \Magento\Framework\Url\RouteParamsResolver $subject, array $data, $unsetOldParams = true ) { if (isset($data['_scope'])) { $subject->setScope($data['_scope']); unset($data['_scope']); } if (isset($data['_scope_to_url']) && (bool)$data['_scope_to_url'] === true) { /** @var StoreInterface $currentScope */ $currentScope = $subject->getScope(); $storeCode = $currentScope && $currentScope instanceof StoreInterface ? $currentScope->getCode() : $this->storeManager->getStore()->getCode(); $useStoreInUrl = $this->scopeConfig->getValue( Store::XML_PATH_STORE_IN_URL, StoreScopeInterface::SCOPE_STORE, $storeCode ); if (!$useStoreInUrl && !$this->storeManager->hasSingleStore()) { $this->queryParamsResolver->setQueryParam('___store', $storeCode); } } unset($data['_scope_to_url']); return [$data, $unsetOldParams]; } }