当前位置: 首页>>代码示例>>PHP>>正文


PHP Product::getUrlKey方法代码示例

本文整理汇总了PHP中Magento\Catalog\Model\Product::getUrlKey方法的典型用法代码示例。如果您正苦于以下问题:PHP Product::getUrlKey方法的具体用法?PHP Product::getUrlKey怎么用?PHP Product::getUrlKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Magento\Catalog\Model\Product的用法示例。


在下文中一共展示了Product::getUrlKey方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getUrl

 /**
  * The only rewritten line in this method is the return statement
  */
 public function getUrl(\Magento\Catalog\Model\Product $product, $params = [])
 {
     $routePath = '';
     $routeParams = $params;
     $storeId = $product->getStoreId();
     $categoryId = null;
     if (!isset($params['_ignore_category']) && $product->getCategoryId() && !$product->getDoNotUseCategoryId()) {
         $categoryId = $product->getCategoryId();
     }
     if ($product->hasUrlDataObject()) {
         $requestPath = $product->getUrlDataObject()->getUrlRewrite();
         $routeParams['_scope'] = $product->getUrlDataObject()->getStoreId();
     } else {
         $requestPath = $product->getRequestPath();
         if (empty($requestPath) && $requestPath !== false) {
             $filterData = [UrlRewrite::ENTITY_ID => $product->getId(), UrlRewrite::ENTITY_TYPE => \Magento\CatalogUrlRewrite\Model\ProductUrlRewriteGenerator::ENTITY_TYPE, UrlRewrite::STORE_ID => $storeId];
             if ($categoryId) {
                 $filterData[UrlRewrite::METADATA]['category_id'] = $categoryId;
             }
             $rewrite = $this->urlFinder->findOneByData($filterData);
             if ($rewrite) {
                 $requestPath = $rewrite->getRequestPath();
                 $product->setRequestPath($requestPath);
             } else {
                 $product->setRequestPath(false);
             }
         }
     }
     if (isset($routeParams['_scope'])) {
         $storeId = $this->storeManager->getStore($routeParams['_scope'])->getId();
     }
     if ($storeId != $this->storeManager->getStore()->getId()) {
         $routeParams['_scope_to_url'] = true;
     }
     if (!empty($requestPath)) {
         $routeParams['_direct'] = $requestPath;
     } else {
         $routePath = 'catalog/product/view';
         $routeParams['id'] = $product->getId();
         $routeParams['s'] = $product->getUrlKey();
         if ($categoryId) {
             $routeParams['category'] = $categoryId;
         }
     }
     // reset cached URL instance GET query params
     if (!isset($routeParams['_query'])) {
         $routeParams['_query'] = [];
     }
     /*
      * This is the only line changed from the default method.
      * For reference, the original line: $this->getUrlInstance()->setScope($storeId)->getUrl($routePath, $routeParams);
      * getUrlInstance() is a private method, so a new method has been written that will create a frontend Url object if
      * the store scope is not the admin scope.
      */
     return $this->getStoreScopeUrlInstance($storeId)->getUrl($routePath, $routeParams);
 }
开发者ID:algolia,项目名称:algoliasearch-magento-2,代码行数:59,代码来源:Url.php

示例2: getUrl

 /**
  * Retrieve Product URL using UrlDataObject
  *
  * @param \Magento\Catalog\Model\Product $product
  * @param array $params
  * @return string
  */
 public function getUrl(\Magento\Catalog\Model\Product $product, $params = array())
 {
     $routePath = '';
     $routeParams = $params;
     $storeId = $product->getStoreId();
     if (isset($params['_ignore_category'])) {
         unset($params['_ignore_category']);
         $categoryId = null;
     } else {
         $categoryId = $product->getCategoryId() && !$product->getDoNotUseCategoryId() ? $product->getCategoryId() : null;
     }
     if ($product->hasUrlDataObject()) {
         $requestPath = $product->getUrlDataObject()->getUrlRewrite();
         $routeParams['_scope'] = $product->getUrlDataObject()->getStoreId();
     } else {
         $requestPath = $product->getRequestPath();
         if (empty($requestPath) && $requestPath !== false) {
             $idPath = sprintf('product/%d', $product->getEntityId());
             if ($categoryId) {
                 $idPath = sprintf('%s/%d', $idPath, $categoryId);
             }
             $rewrite = $this->getUrlRewrite();
             $rewrite->setStoreId($storeId)->loadByIdPath($idPath);
             if ($rewrite->getId()) {
                 $requestPath = $rewrite->getRequestPath();
                 $product->setRequestPath($requestPath);
             } else {
                 $product->setRequestPath(false);
             }
         }
     }
     if (isset($routeParams['_scope'])) {
         $storeId = $this->_storeManager->getStore($routeParams['_scope'])->getId();
     }
     if ($storeId != $this->_storeManager->getStore()->getId()) {
         $routeParams['_scope_to_url'] = true;
     }
     if (!empty($requestPath)) {
         $routeParams['_direct'] = $requestPath;
     } else {
         $routePath = 'catalog/product/view';
         $routeParams['id'] = $product->getId();
         $routeParams['s'] = $product->getUrlKey();
         if ($categoryId) {
             $routeParams['category'] = $categoryId;
         }
     }
     // reset cached URL instance GET query params
     if (!isset($routeParams['_query'])) {
         $routeParams['_query'] = array();
     }
     return $this->getUrlInstance()->setScope($storeId)->getUrl($routePath, $routeParams);
 }
开发者ID:pavelnovitsky,项目名称:magento2,代码行数:60,代码来源:Url.php

示例3: prepareProductUrlKey

 /**
  * Prepare url key for product
  *
  * @param \Magento\Catalog\Model\Product $product
  * @return string
  */
 protected function prepareProductUrlKey(\Magento\Catalog\Model\Product $product)
 {
     $urlKey = $product->getUrlKey();
     return $product->formatUrlKey($urlKey === '' || $urlKey === null ? $product->getName() : $urlKey);
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:11,代码来源:ProductUrlPathGenerator.php

示例4: getUrl

 /**
  * Retrieve Product URL using UrlDataObject
  *
  * @param \Magento\Catalog\Model\Product $product
  * @param array $params
  * @return string
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function getUrl(\Magento\Catalog\Model\Product $product, $params = [])
 {
     $routePath = '';
     $routeParams = $params;
     $storeId = $product->getStoreId();
     if (isset($params['_ignore_category'])) {
         unset($params['_ignore_category']);
         $categoryId = null;
     } else {
         $categoryId = $product->getCategoryId() && !$product->getDoNotUseCategoryId() ? $product->getCategoryId() : null;
     }
     if ($product->hasUrlDataObject()) {
         $requestPath = $product->getUrlDataObject()->getUrlRewrite();
         $routeParams['_scope'] = $product->getUrlDataObject()->getStoreId();
     } else {
         $requestPath = $product->getRequestPath();
         if (empty($requestPath) && $requestPath !== false) {
             $filterData = [UrlRewrite::ENTITY_ID => $product->getId(), UrlRewrite::ENTITY_TYPE => \Magento\CatalogUrlRewrite\Model\ProductUrlRewriteGenerator::ENTITY_TYPE, UrlRewrite::STORE_ID => $storeId];
             if ($categoryId) {
                 $filterData[UrlRewrite::METADATA]['category_id'] = $categoryId;
             }
             $rewrite = $this->urlFinder->findOneByData($filterData);
             if ($rewrite) {
                 $requestPath = $rewrite->getRequestPath();
                 $product->setRequestPath($requestPath);
             } else {
                 $product->setRequestPath(false);
             }
         }
     }
     if (isset($routeParams['_scope'])) {
         $storeId = $this->_storeManager->getStore($routeParams['_scope'])->getId();
     }
     if ($storeId != $this->_storeManager->getStore()->getId()) {
         $routeParams['_scope_to_url'] = true;
     }
     if (!empty($requestPath)) {
         $routeParams['_direct'] = $requestPath;
     } else {
         $routePath = 'catalog/product/view';
         $routeParams['id'] = $product->getId();
         $routeParams['s'] = $product->getUrlKey();
         if ($categoryId) {
             $routeParams['category'] = $categoryId;
         }
     }
     // reset cached URL instance GET query params
     if (!isset($routeParams['_query'])) {
         $routeParams['_query'] = [];
     }
     return $this->getUrlInstance()->setScope($storeId)->getUrl($routePath, $routeParams);
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:61,代码来源:Url.php

示例5: generateProductUrlKeyPath

 /**
  * Generate product url key path
  *
  * @param \Magento\Catalog\Model\Product $product
  * @return string
  */
 public function generateProductUrlKeyPath($product)
 {
     $urlKey = $product->getUrlKey() == '' ? $product->formatUrlKey($product->getName()) : $product->formatUrlKey($product->getUrlKey());
     return $urlKey;
 }
开发者ID:pavelnovitsky,项目名称:magento2,代码行数:11,代码来源:Data.php

示例6: generateUrlKey

 /**
  * Generate product url key based on url_key entered by merchant or product name
  *
  * @param \Magento\Catalog\Model\Product $product
  * @return string
  */
 public function generateUrlKey($product)
 {
     $urlKey = $product->getUrlKey();
     return $product->formatUrlKey($urlKey === '' || $urlKey === null ? $product->getName() : $urlKey);
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:11,代码来源:ProductUrlPathGenerator.php


注:本文中的Magento\Catalog\Model\Product::getUrlKey方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。