コード例 #1
0
ファイル: Router.php プロジェクト: pavelnovitsky/magento2
 /**
  * Validate and Match Cms Page and modify request
  *
  * @param \Magento\Framework\App\RequestInterface $request
  * @return mixed
  */
 public function match(\Magento\Framework\App\RequestInterface $request)
 {
     $identifier = trim($request->getPathInfo(), '/');
     $urlRewrite = $this->urlMatcher->match($identifier, $this->storeManager->getStore()->getId());
     if ($urlRewrite === null) {
         return null;
     }
     $redirectType = $urlRewrite->getRedirectType();
     if ($redirectType) {
         $redirectCode = $redirectType == \Magento\UrlRedirect\Model\OptionProvider::PERMANENT ? 301 : 302;
         $this->response->setRedirect($urlRewrite->getTargetPath(), $redirectCode);
         $request->setDispatched(true);
         return $this->actionFactory->createController('Magento\\Framework\\App\\Action\\Redirect', array('request' => $request));
     }
     $request->setPathInfo('/' . $urlRewrite->getTargetPath());
     return $this->actionFactory->createController('Magento\\Framework\\App\\Action\\Forward', array('request' => $request));
 }
コード例 #2
0
 /**
  * Generate permanent rewrites based on current rewrites
  *
  * @param int $storeId
  * @return array
  */
 protected function generateRewritesBasedOnCurrentRewrites($storeId)
 {
     $urls = [];
     foreach ($this->urlMatcher->findAllByFilter($this->createCurrentUrlRewritesFilter($storeId)) as $url) {
         $targetPath = null;
         if ($url->getRedirectType()) {
             $targetPath = str_replace($this->product->getOrigData('url_key'), $this->product->getData('url_key'), $url->getTargetPath());
             $redirectType = $url->getRedirectType();
         } elseif ($this->product->getData('save_rewrites_history')) {
             $targetPath = str_replace($this->product->getOrigData('url_key'), $this->product->getData('url_key'), $url->getRequestPath());
             $redirectType = OptionProvider::PERMANENT;
         }
         if ($targetPath && $url->getRequestPath() != $targetPath) {
             $urls[] = $this->createUrlRewrite($storeId, $url->getRequestPath(), $targetPath, $redirectType);
         }
     }
     return $urls;
 }