Mage_Catalog_Helper_Category Class Reference

Inheritance diagram for Mage_Catalog_Helper_Category:

Mage_Core_Helper_Abstract

List of all members.

Public Member Functions

 getStoreCategories ($sorted=false, $asCollection=false, $toLoad=true)
 getCategoryUrl ($category)
 canShow ($category)
 getCategoryUrlSuffix ($storeId=null)
 getCategoryUrlPath ($urlPath, $slash=false, $storeId=null)

Public Attributes

const XML_PATH_CATEGORY_URL_SUFFIX = 'catalog/seo/category_url_suffix'

Protected Attributes

 $_storeCategories = array()
 $_categoryUrlSuffix = array()


Detailed Description

Definition at line 34 of file Category.php.


Member Function Documentation

canShow ( category  ) 

Check if a category can be shown

Parameters:
Mage_Catalog_Model_Category|int $category
Returns:
boolean

Definition at line 108 of file Category.php.

00109     {
00110         if (is_int($category)) {
00111             $category = Mage::getModel('catalog/category')->load($category);
00112         }
00113 
00114         if (!$category->getId()) {
00115             return false;
00116         }
00117 
00118         if (!$category->getIsActive()) {
00119             return false;
00120         }
00121         if (!$category->isInRootCategoryList()) {
00122             return false;
00123         }
00124 
00125         return true;
00126     }

getCategoryUrl ( category  ) 

Retrieve category url

Parameters:
Mage_Catalog_Model_Category $category
Returns:
string

Definition at line 92 of file Category.php.

00093     {
00094         if ($category instanceof Mage_Catalog_Model_Category) {
00095             return $category->getUrl();
00096         }
00097         return Mage::getModel('catalog/category')
00098             ->setData($category->getData())
00099             ->getUrl();
00100     }

getCategoryUrlPath ( urlPath,
slash = false,
storeId = null 
)

Retrieve clear url for category as parrent

Parameters:
string $url
bool $slash
int $storeId
Returns:
string

Definition at line 155 of file Category.php.

00156     {
00157         if (!$this->getCategoryUrlSuffix($storeId)) {
00158             return $urlPath;
00159         }
00160 
00161         if ($slash) {
00162             $regexp     = '#('.preg_quote($this->getCategoryUrlSuffix($storeId), '#').')/$#i';
00163             $replace    = '/';
00164         }
00165         else {
00166             $regexp     = '#('.preg_quote($this->getCategoryUrlSuffix($storeId), '#').')$#i';
00167             $replace    = '';
00168         }
00169 
00170         return preg_replace($regexp, $replace, $urlPath);
00171     }

getCategoryUrlSuffix ( storeId = null  ) 

Retrieve category rewrite sufix for store

Parameters:
int $storeId
Returns:
string

Definition at line 134 of file Category.php.

00135     {
00136         if (is_null($storeId)) {
00137             $storeId = Mage::app()->getStore()->getId();
00138         }
00139 
00140         if (!isset($this->_categoryUrlSuffix[$storeId])) {
00141             $this->_categoryUrlSuffix[$storeId] = Mage::getStoreConfig(self::XML_PATH_CATEGORY_URL_SUFFIX, $storeId);
00142         }
00143         return $this->_categoryUrlSuffix[$storeId];
00144     }

getStoreCategories ( sorted = false,
asCollection = false,
toLoad = true 
)

Retrieve current store categories

Parameters:
boolean|string $sorted
boolean $asCollection
Returns:
Varien_Data_Tree_Node_Collection|Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Collection|array

Check if parent node of the store still exists

Definition at line 59 of file Category.php.

00060     {
00061         $parent     = Mage::app()->getStore()->getRootCategoryId();
00062         $cacheKey   = sprintf('%d-%d-%d-%d', $parent, $sorted, $asCollection, $toLoad);
00063         if (isset($this->_storeCategories[$cacheKey])) {
00064             return $this->_storeCategories[$cacheKey];
00065         }
00066 
00067         /**
00068          * Check if parent node of the store still exists
00069          */
00070         $category = Mage::getModel('catalog/category');
00071         /* @var $category Mage_Catalog_Model_Category */
00072         if (!$category->checkId($parent)) {
00073             if ($asCollection) {
00074                 return new Varien_Data_Collection();
00075             }
00076             return array();
00077         }
00078 
00079         $recursionLevel  = max(0, (int) Mage::app()->getStore()->getConfig('catalog/navigation/max_depth'));
00080         $storeCategories = $category->getCategories($parent, $recursionLevel, $sorted, $asCollection, $toLoad);
00081 
00082         $this->_storeCategories[$cacheKey] = $storeCategories;
00083         return $storeCategories;
00084     }


Member Data Documentation

$_categoryUrlSuffix = array() [protected]

Definition at line 50 of file Category.php.

$_storeCategories = array() [protected]

Definition at line 43 of file Category.php.

const XML_PATH_CATEGORY_URL_SUFFIX = 'catalog/seo/category_url_suffix'

Definition at line 36 of file Category.php.


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

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