Mage_Catalog_Model_Product_Url Class Reference

Inheritance diagram for Mage_Catalog_Model_Product_Url:

Varien_Object

List of all members.

Public Member Functions

 getUrlInstance ()
 getUrlRewrite ()
 getProductUrl ($product, $useSid=null)
 formatUrlKey ($str)
 getUrlPath ($product, $category=null)

Public Attributes

const CACHE_TAG = 'url_rewrite'

Protected Member Functions

 _validImage ($image)

Static Protected Attributes

static $_url
static $_urlRewrite


Detailed Description

Product Url model

Author:
Magento Core Team <core@magentocommerce.com>

Definition at line 33 of file Url.php.


Member Function Documentation

_validImage ( image  )  [protected]

'no_selection' shouldn't be a valid image attribute value

Parameters:
string $image
Returns:
string

Definition at line 67 of file Url.php.

00068     {
00069         if($image == 'no_selection') {
00070             $image = null;
00071         }
00072         return $image;
00073     }

formatUrlKey ( str  ) 

Definition at line 150 of file Url.php.

00151     {
00152         $urlKey = preg_replace('#[^0-9a-z]+#i', '-', Mage::helper('catalog/product_url')->format($str));
00153         $urlKey = strtolower($urlKey);
00154         $urlKey = trim($urlKey, '-');
00155 
00156         return $urlKey;
00157     }

getProductUrl ( product,
useSid = null 
)

Get product url

Parameters:
Mage_Catalog_Model_Product $product
bool $useSid
Returns:
string

Definition at line 82 of file Url.php.

00083     {
00084         if ($useSid === null) {
00085             $useSid = Mage::app()->getUseSessionInUrl();
00086         }
00087 
00088         $categoryId = $product->getCategoryId() && !$product->getDoNotUseCategoryId() ? $product->getCategoryId() : 0;
00089 
00090         $cacheUrlKey = sprintf('url_%d_%d', $categoryId, $useSid);
00091         $url = $product->getData($cacheUrlKey);
00092 
00093         if (is_null($url)) {
00094             if ($product->getStoreId()) {
00095                 $this->getUrlInstance()->setStore($product->getStoreId());
00096             }
00097 
00098             // auto add SID to URL
00099             $originalSid = $this->getUrlInstance()->getUseSession();
00100             if ($originalSid != $useSid) {
00101                 $this->getUrlInstance()->setUseSession($useSid);
00102             }
00103 
00104             if ($product->hasData('request_path') && $product->getRequestPath() != '') {
00105                 $this->setData($cacheUrlKey, $this->getUrlInstance()->getDirectUrl($product->getRequestPath()));
00106                 $this->getUrlInstance()->setUseSession($originalSid);
00107                 return $this->getData($cacheUrlKey);
00108             }
00109 
00110             Varien_Profiler::start('REWRITE: '.__METHOD__);
00111 
00112             $rewrite = $this->getUrlRewrite();
00113             if ($product->getStoreId()) {
00114                 $rewrite->setStoreId($product->getStoreId());
00115             }
00116             else {
00117                 $rewrite->setStoreId(Mage::app()->getStore()->getId());
00118             }
00119 
00120             $idPath = 'product/'.$product->getId();
00121             if ($product->getCategoryId() && !$product->getDoNotUseCategoryId() && Mage::getStoreConfig('catalog/seo/product_use_categories')) {
00122                 $idPath .= '/'.$product->getCategoryId();
00123             }
00124 
00125             $rewrite->loadByIdPath($idPath);
00126 //echo $this->getUrlInstance()->getBaseUrl();
00127             if ($rewrite->getId()) {
00128                 $this->setData($cacheUrlKey, $this->getUrlInstance()->getDirectUrl($rewrite->getRequestPath()));
00129                 Varien_Profiler::stop('REWRITE: '.__METHOD__);
00130                 $this->getUrlInstance()->setUseSession($originalSid);
00131                 return $this->getData($cacheUrlKey);
00132             }
00133 
00134             Varien_Profiler::stop('REWRITE: '.__METHOD__);
00135             Varien_Profiler::start('REGULAR: '.__METHOD__);
00136 
00137             $url = $this->getUrlInstance()->getUrl('catalog/product/view', array(
00138                 'id'        => $product->getId(),
00139                 's'         => $product->getUrlKey(),
00140                 'category'  => $product->getCategoryId()
00141             ));
00142 
00143             $this->getUrlInstance()->setUseSession($originalSid);
00144 
00145             Varien_Profiler::stop('REGULAR: '.__METHOD__);
00146         }
00147         return $url;
00148     }

getUrlInstance (  ) 

Returns:
Mage_Core_Model_Url

Definition at line 43 of file Url.php.

00044     {
00045         if (!self::$_url) {
00046             self::$_url = Mage::getModel('core/url');
00047         }
00048         return self::$_url;
00049     }

getUrlPath ( product,
category = null 
)

Retrieve Product Url path (with category if exists)

Parameters:
Mage_Catalog_Model_Product $product
Mage_Catalog_Model_Category $category
Returns:
string

Todo:
get default category

Definition at line 167 of file Url.php.

00168     {
00169         $path = $product->getData('url_path');
00170 
00171         if (is_null($category)) {
00172             /** @todo get default category */
00173             return $path;
00174         } elseif (!$category instanceof Mage_Catalog_Model_Category) {
00175             Mage::throwException('Invalid category object supplied');
00176         }
00177 
00178         return Mage::helper('catalog/category')->getCategoryUrlPath($category->getUrlPath())
00179             . '/' . $path;
00180     }

getUrlRewrite (  ) 

Returns:
Mage_Core_Model_Url_Rewrite

Definition at line 54 of file Url.php.

00055     {
00056         if (!self::$_urlRewrite) {
00057             self::$_urlRewrite = Mage::getModel('core/url_rewrite');
00058         }
00059         return self::$_urlRewrite;
00060     }


Member Data Documentation

$_url [static, protected]

Definition at line 35 of file Url.php.

$_urlRewrite [static, protected]

Definition at line 36 of file Url.php.

const CACHE_TAG = 'url_rewrite'

Definition at line 38 of file Url.php.


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:23:42 2009 for Magento by  doxygen 1.5.8