示例#1
0
 /**
  * Process path info
  *
  * @param \Magento\Framework\App\RequestInterface $request
  * @param string $pathInfo
  * @return string
  */
 public function process(\Magento\Framework\App\RequestInterface $request, $pathInfo)
 {
     $pathParts = explode('/', ltrim($pathInfo, '/'), 2);
     $storeCode = $pathParts[0];
     $stores = $this->_storeManager->getStores(false, true);
     if (isset($stores[$storeCode]) && $stores[$storeCode]->isUseStoreInUrl()) {
         if (!$request->isDirectAccessFrontendName($storeCode)) {
             $this->_storeManager->setCurrentStore($storeCode);
             $pathInfo = '/' . (isset($pathParts[1]) ? $pathParts[1] : '');
             return $pathInfo;
         } elseif (!empty($storeCode)) {
             $request->setActionName('noroute');
             return $pathInfo;
         }
         return $pathInfo;
     }
     return $pathInfo;
 }
 /**
  * Process path info
  *
  * @param \Magento\Framework\App\RequestInterface $request
  * @param string $pathInfo
  * @return string
  */
 public function process(\Magento\Framework\App\RequestInterface $request, $pathInfo)
 {
     $pathParts = explode('/', ltrim($pathInfo, '/'), 2);
     $storeCode = $pathParts[0];
     try {
         /** @var \Magento\Store\Api\Data\StoreInterface $store */
         $store = $this->storeManager->getStore($storeCode);
     } catch (NoSuchEntityException $e) {
         return $pathInfo;
     }
     if ($store->isUseStoreInUrl()) {
         if (!$request->isDirectAccessFrontendName($storeCode)) {
             $this->storeManager->setCurrentStore($storeCode);
             $pathInfo = '/' . (isset($pathParts[1]) ? $pathParts[1] : '');
             return $pathInfo;
         } elseif (!empty($storeCode)) {
             $request->setActionName('noroute');
             return $pathInfo;
         }
         return $pathInfo;
     }
     return $pathInfo;
 }