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


PHP Mage_Catalog_Model_Product::getUrlKey方法代码示例

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


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

示例1: _validateUrlKey

 /**
  * Check unique url_key value in catalog_product_entity_url_key table.
  *
  * @param Mage_Catalog_Model_Product $object
  * @return Mage_Catalog_Model_Product_Attribute_Backend_Urlkey
  * @throws Mage_Core_Exception
  */
 protected function _validateUrlKey($object)
 {
     $connection = $object->getResource()->getReadConnection();
     $select = $connection->select()->from($this->getAttribute()->getBackendTable(), array('count' => new Zend_Db_Expr('COUNT(\'value_id\')')))->where($connection->quoteInto('entity_id <> ?', $object->getId()))->where($connection->quoteInto('value = ?', $object->getUrlKey()));
     $result = $connection->fetchOne($select);
     if ((int) $result) {
         throw new Mage_Core_Exception(Mage::helper('catalog')->__("Product with the '%s' url_key attribute already exists.", $object->getUrlKey()));
     }
     return $this;
 }
开发者ID:aaronleslie,项目名称:aaronunix,代码行数:17,代码来源:Urlkey.php

示例2: _initProductLayout

 /**
  * Initialize product view layout
  *
  * @param   Mage_Catalog_Model_Product $product
  * @return  Mage_Catalog_ProductController
  */
 protected function _initProductLayout($product)
 {
     $update = $this->getLayout()->getUpdate();
     $update->addHandle('default');
     $this->addActionLayoutHandles();
     $update->addHandle('PRODUCT_TYPE_' . $product->getTypeId());
     $update->addHandle('PRODUCT_' . $product->getId());
     if ($product->getPageLayout()) {
         $this->getLayout()->helper('page/layout')->applyHandle($product->getPageLayout());
     }
     $this->loadLayoutUpdates();
     $update->addUpdate($product->getCustomLayoutUpdate());
     $update->merge(strtolower($this->getFullActionName()) . '_FINAL');
     $this->generateLayoutXml()->generateLayoutBlocks();
     if ($product->getPageLayout()) {
         $this->getLayout()->helper('page/layout')->applyTemplate($product->getPageLayout());
     }
     $currentCategory = Mage::registry('current_category');
     if ($root = $this->getLayout()->getBlock('root')) {
         $root->addBodyClass('product-' . $product->getUrlKey());
         if ($currentCategory instanceof Mage_Catalog_Model_Category) {
             $root->addBodyClass('categorypath-' . $currentCategory->getUrlPath())->addBodyClass('category-' . $currentCategory->getUrlKey());
         }
     }
     return $this;
 }
开发者ID:Aerotexextintores,项目名称:novosite,代码行数:32,代码来源:IndexController.php

示例3: _initProductLayout

 /**
  * Initialize product view layout
  *
  * @param   Mage_Catalog_Model_Product $product
  * @return  Mage_Catalog_ProductController
  */
 protected function _initProductLayout($product)
 {
     $update = $this->getLayout()->getUpdate();
     $update->addHandle('default');
     $this->addActionLayoutHandles();
     $update->addHandle('PRODUCT_TYPE_' . $product->getTypeId());
     $update->addHandle('PRODUCT_' . $product->getId());
     $this->loadLayoutUpdates();
     $this->generateLayoutXml()->generateLayoutBlocks();
     $currentCategory = Mage::registry('current_category');
     if ($root = $this->getLayout()->getBlock('root')) {
         $root->addBodyClass('product-' . $product->getUrlKey());
         if ($currentCategory instanceof Mage_Catalog_Model_Category) {
             $root->addBodyClass('categorypath-' . $currentCategory->getUrlPath())->addBodyClass('category-' . $currentCategory->getUrlKey());
         }
     }
     return $this;
 }
开发者ID:guohuadeng,项目名称:sunpopPortoTheme,代码行数:24,代码来源:IndexController.php

示例4: getUrl

 /**
  * @param Mage_Catalog_Model_Product $product the product model
  * @return string URL
  */
 public function getUrl($product)
 {
     // New url rewrites with enterprise 1.13
     $magentoVersion = Mage::getVersion();
     if (version_compare($magentoVersion, '1.13', '>=')) {
         $requestPath = $product->getUrlKey();
         if ($requestPath) {
             return Mage::getUrl('', array('_direct' => $requestPath));
         }
     }
     $rewrite = null;
     if ($categories = $product->getCategoryIds()) {
         $rewrite = Mage::getModel('catalog/url')->getResource()->getRewriteByIdPath('product/' . $product->getId() . '/' . reset($categories), 1);
     }
     if (!$rewrite) {
         $rewrite = Mage::getModel('catalog/url')->getResource()->getRewriteByIdPath('product/' . $product->getId(), 1);
     }
     return Mage::getUrl('', array('_direct' => $rewrite->getRequestPath()));
 }
开发者ID:liip,项目名称:liip-magento-shared,代码行数:23,代码来源:Product.php

示例5: _initProductLayout

 /**
  * Initialize product view layout
  *
  * @param   Mage_Catalog_Model_Product $product
  * @return  Mage_Catalog_ProductController
  */
 protected function _initProductLayout($product)
 {
     $update = $this->getLayout()->getUpdate();
     $update->addHandle('default');
     $this->addActionLayoutHandles();
     $update->addHandle('PRODUCT_TYPE_' . $product->getTypeId());
     $update->addHandle('PRODUCT_' . $product->getId());
     if ($product->getPageLayout()) {
         $this->getLayout()->helper('page/layout')->applyHandle($product->getPageLayout());
     }
     $this->loadLayoutUpdates();
     $update->addUpdate($product->getCustomLayoutUpdate());
     $this->generateLayoutXml()->generateLayoutBlocks();
     if ($product->getPageLayout()) {
         $this->getLayout()->helper('page/layout')->applyTemplate($product->getPageLayout());
     }
     //$currentCategory = Mage::registry('current_category');
     if ($root = $this->getLayout()->getBlock('root')) {
         $root->addBodyClass('product-' . $product->getUrlKey());
     }
     return $this;
 }
开发者ID:axovel,项目名称:exqzt,代码行数:28,代码来源:IndexController.php

示例6: getProductUrl

 /**
  * Get product url
  *
  * @param  Mage_Catalog_Model_Product $product
  * @return string
  */
 public function getProductUrl($product)
 {
     Varien_Profiler::start('REWRITE: ' . __METHOD__);
     $rewrite = $this->getUrlRewrite();
     if ($product->getStoreId()) {
         $rewrite->setStoreId($product->getStoreId());
     }
     $idPath = 'product/' . $product->getId();
     if ($product->getCategoryId() && Mage::getStoreConfig('catalog/seo/product_use_categories')) {
         $idPath .= '/' . $product->getCategoryId();
     }
     $rewrite->loadByIdPath($idPath);
     if ($rewrite->getId()) {
         $url = $this->getUrlInstance()->getBaseUrl() . $rewrite->getRequestPath();
         Varien_Profiler::stop('REWRITE: ' . __METHOD__);
         return $url;
     }
     Varien_Profiler::stop('REWRITE: ' . __METHOD__);
     Varien_Profiler::start('REGULAR: ' . __METHOD__);
     $url = $this->getUrlInstance()->getUrl('catalog/product/view', array('id' => $product->getId(), 's' => $product->getUrlKey(), 'category' => $product->getCategoryId()));
     Varien_Profiler::stop('REGULAR: ' . __METHOD__);
     return $url;
 }
开发者ID:arslbbt,项目名称:mangentovies,代码行数:29,代码来源:Url.php

示例7: getUrl

 /**
  * Retrieve Product URL using UrlDataObject
  *
  * @param Mage_Catalog_Model_Product $product
  * @param array $params
  * @return string
  */
 public function getUrl(Mage_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['_store'] = $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['_store'])) {
         $storeId = Mage::app()->getStore($routeParams['_store'])->getId();
     }
     if ($storeId != Mage::app()->getStore()->getId()) {
         $routeParams['_store_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()->setStore($storeId)->getUrl($routePath, $routeParams);
 }
开发者ID:natxetee,项目名称:magento2,代码行数:60,代码来源:Url.php

示例8: _getProductUrl

 /**
  * Retrieve product URL based on requestPath param
  *
  * @param Mage_Catalog_Model_Product $product
  * @param string $requestPath
  * @param array $routeParams
  *
  * @return string
  */
 protected function _getProductUrl($product, $requestPath, $routeParams)
 {
     if (!empty($requestPath)) {
         return $this->getUrlInstance()->getDirectUrl($requestPath, $routeParams);
     }
     $routeParams['id'] = $product->getId();
     $routeParams['s'] = $product->getUrlKey();
     $categoryId = $this->_getCategoryIdForUrl($product, $routeParams);
     if ($categoryId) {
         $routeParams['category'] = $categoryId;
     }
     return $this->getUrlInstance()->getUrl('catalog/product/view', $routeParams);
 }
开发者ID:chucky515,项目名称:Magento-CE-Mirror,代码行数:22,代码来源:Url.php

示例9: _getUrlsForProduct

 /**
  * Returns all the urls related to product
  * 
  * Uses code from magneto-varnish.
  * 
  * @see https://github.com/madalinoprea/magneto-varnish/blob/master/code/Varnish/Model/Observer.php#L133
  * @param Mage_Catalog_Model_Product $product
  */
 protected function _getUrlsForProduct($product)
 {
     $urls = array();
     $store_id = $product->getStoreId();
     $routePath = 'catalog/product/view';
     $routeParams['id'] = $product->getId();
     $routeParams['s'] = $product->getUrlKey();
     $routeParams['_store'] = !$store_id ? 1 : $store_id;
     $url = Mage::getUrl($routePath, $routeParams);
     $urls[] = $url;
     // Collect all rewrites
     $rewrites = Mage::getModel('core/url_rewrite')->getCollection();
     if (!Mage::getConfig('catalog/seo/product_use_categories')) {
         $rewrites->getSelect()->where("id_path = 'product/{$product->getId()}'");
     } else {
         // Also show full links with categories
         $rewrites->getSelect()->where("id_path = 'product/{$product->getId()}' OR id_path like 'product/{$product->getId()}/%'");
     }
     foreach ($rewrites as $r) {
         unset($routeParams);
         $routePath = '';
         $routeParams['_direct'] = $r->getRequestPath();
         $routeParams['_store'] = $r->getStoreId();
         $url = Mage::getUrl($routePath, $routeParams);
         $urls[] = $url;
     }
     return $urls;
 }
开发者ID:finelinePG,项目名称:finelink-dev,代码行数:36,代码来源:VarnishObserver.php

示例10: getProductUrl

 /**
  * Get product url
  *
  * @param  Mage_Catalog_Model_Product $product
  * @param  bool $useSid
  * @return string
  */
 public function getProductUrl($product, $useSid = null)
 {
     if ($useSid === null) {
         $useSid = Mage::app()->getUseSessionInUrl();
     }
     $categoryId = $product->getCategoryId() && !$product->getDoNotUseCategoryId() ? $product->getCategoryId() : 0;
     $cacheUrlKey = sprintf('url_%d_%d', $categoryId, $useSid);
     $url = $product->getData($cacheUrlKey);
     if (is_null($url)) {
         if ($product->getStoreId()) {
             $this->getUrlInstance()->setStore($product->getStoreId());
         }
         // auto add SID to URL
         $originalSid = $this->getUrlInstance()->getUseSession();
         if ($originalSid != $useSid) {
             $this->getUrlInstance()->setUseSession($useSid);
         }
         if ($product->hasData('request_path') && $product->getRequestPath() != '') {
             $this->setData($cacheUrlKey, $this->getUrlInstance()->getDirectUrl($product->getRequestPath()));
             $this->getUrlInstance()->setUseSession($originalSid);
             return $this->getData($cacheUrlKey);
         }
         Varien_Profiler::start('REWRITE: ' . __METHOD__);
         $rewrite = $this->getUrlRewrite();
         if ($product->getStoreId()) {
             $rewrite->setStoreId($product->getStoreId());
         } else {
             $rewrite->setStoreId(Mage::app()->getStore()->getId());
         }
         $idPath = 'product/' . $product->getId();
         if ($product->getCategoryId() && !$product->getDoNotUseCategoryId() && Mage::getStoreConfig('catalog/seo/product_use_categories')) {
             $idPath .= '/' . $product->getCategoryId();
         }
         $rewrite->loadByIdPath($idPath);
         //echo $this->getUrlInstance()->getBaseUrl();
         if ($rewrite->getId()) {
             $this->setData($cacheUrlKey, $this->getUrlInstance()->getDirectUrl($rewrite->getRequestPath()));
             Varien_Profiler::stop('REWRITE: ' . __METHOD__);
             $this->getUrlInstance()->setUseSession($originalSid);
             return $this->getData($cacheUrlKey);
         }
         Varien_Profiler::stop('REWRITE: ' . __METHOD__);
         Varien_Profiler::start('REGULAR: ' . __METHOD__);
         $url = $this->getUrlInstance()->getUrl('catalog/product/view', array('id' => $product->getId(), 's' => $product->getUrlKey(), 'category' => $product->getCategoryId()));
         $this->getUrlInstance()->setUseSession($originalSid);
         Varien_Profiler::stop('REGULAR: ' . __METHOD__);
     }
     return $url;
 }
开发者ID:jauderho,项目名称:magento-mirror,代码行数:56,代码来源:Url.php


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