Definition at line 35 of file Category.php.
_beforeDelete | ( | ) | [protected] |
Before delete process
Reimplemented from Mage_Core_Model_Abstract.
Definition at line 653 of file Category.php.
00654 { 00655 $this->_protectFromNonAdmin(); 00656 if ($this->getResource()->isForbiddenToDelete($this->getId())) { 00657 Mage::throwException("Can't delete root category."); 00658 } 00659 return parent::_beforeDelete(); 00660 }
_construct | ( | ) | [protected] |
Initialize resource mode
Reimplemented from Varien_Object.
Definition at line 112 of file Category.php.
00113 { 00114 if (Mage::helper('catalog/category_flat')->isEnabled()) { 00115 $this->_init('catalog/category_flat'); 00116 $this->_useFlatResource = true; 00117 } else { 00118 $this->_init('catalog/category'); 00119 } 00120 }
checkId | ( | $ | id | ) |
Check category id exising
int | $id |
Definition at line 573 of file Category.php.
00574 { 00575 return $this->_getResource()->checkId($id); 00576 }
formatUrlKey | ( | $ | str | ) |
Format URL key from name or defined key
string | $str |
Definition at line 380 of file Category.php.
00381 { 00382 $str = Mage::helper('core')->removeAccents($str); 00383 $urlKey = preg_replace('#[^0-9a-z]+#i', '-', $str); 00384 $urlKey = strtolower($urlKey); 00385 $urlKey = trim($urlKey, '-'); 00386 return $urlKey; 00387 }
getAllChildren | ( | $ | asArray = false |
) |
Get all children categories IDs
boolean | $asArray return resul as array instead of comma-separated list of IDs |
Definition at line 509 of file Category.php.
00510 { 00511 $children = $this->getResource()->getAllChildren($this); 00512 if ($asArray) { 00513 return $children; 00514 } 00515 else { 00516 return implode(',', $children); 00517 } 00518 00519 // $this->getTreeModelInstance()->load(); 00520 // $children = $this->getTreeModelInstance()->getChildren($this->getId()); 00521 // 00522 // $myId = array($this->getId()); 00523 // if (is_array($children)) { 00524 // $children = array_merge($myId, $children); 00525 // } 00526 // else { 00527 // $children = $myId; 00528 // } 00529 // if ($asArray) { 00530 // return $children; 00531 // } 00532 // else { 00533 // return implode(',', $children); 00534 // } 00535 }
getAnchorsAbove | ( | ) |
Retrieve anchors above
Definition at line 667 of file Category.php.
00668 { 00669 $anchors = array(); 00670 $path = $this->getPathIds(); 00671 00672 if (in_array($this->getId(), $path)) { 00673 unset($path[array_search($this->getId(), $path)]); 00674 } 00675 00676 if ($this->_useFlatResource) { 00677 $anchors = $this->_getResource()->getAnchorsAbove($path, $this->getStoreId()); 00678 } 00679 else { 00680 if (!Mage::registry('_category_is_anchor_attribute')) { 00681 $model = $this->_getAttribute('is_anchor'); 00682 Mage::register('_category_is_anchor_attribute', $model); 00683 } 00684 00685 if ($isAnchorAttribute = Mage::registry('_category_is_anchor_attribute')) { 00686 $anchors = $this->getResource()->findWhereAttributeIs($path, $isAnchorAttribute, 1); 00687 } 00688 } 00689 return $anchors; 00690 }
getAttributes | ( | $ | noDesignAttributes = false |
) |
Retrieve all customer attributes
Definition at line 213 of file Category.php.
00214 { 00215 $result = $this->getResource() 00216 ->loadAllAttributes($this) 00217 ->getSortedAttributes(); 00218 00219 if ($noDesignAttributes){ 00220 foreach ($result as $k=>$a){ 00221 if (in_array($k, $this->_designAttributes)) { 00222 unset($result[$k]); 00223 } 00224 } 00225 } 00226 00227 return $result; 00228 }
getAvailableSortBy | ( | ) |
Retrieve Available int Product Listing sort by
Definition at line 758 of file Category.php.
00759 { 00760 $available = $this->getData('available_sort_by'); 00761 if (empty($available)) { 00762 return array(); 00763 } 00764 if ($available && !is_array($available)) { 00765 $available = split(',', $available); 00766 } 00767 return $available; 00768 }
getAvailableSortByOptions | ( | ) |
Retrieve Available Product Listing Sort By code as key, value - name
Definition at line 776 of file Category.php.
00776 { 00777 $availableSortBy = array(); 00778 $defaultSortBy = Mage::getSingleton('catalog/config') 00779 ->getAttributeUsedForSortByArray(); 00780 if ($this->getAvailableSortBy()) { 00781 foreach ($this->getAvailableSortBy() as $sortBy) { 00782 if (isset($defaultSortBy[$sortBy])) { 00783 $availableSortBy[$sortBy] = $defaultSortBy[$sortBy]; 00784 } 00785 } 00786 } 00787 00788 if (!$availableSortBy) { 00789 $availableSortBy = $defaultSortBy; 00790 } 00791 00792 return $availableSortBy; 00793 }
getCategories | ( | $ | parent, | |
$ | recursionLevel = 0 , |
|||
$ | sorted = false , |
|||
$ | asCollection = false , |
|||
$ | toLoad = true | |||
) |
Retrieve categories by parent
int | $parent | |
int | $recursionLevel | |
bool | $sorted | |
bool | $asCollection | |
bool | $toLoad |
Definition at line 716 of file Category.php.
00717 { 00718 $categories = $this->getResource() 00719 ->getCategories($parent, $recursionLevel, $sorted, $asCollection, $toLoad); 00720 return $categories; 00721 }
getCategoryIdUrl | ( | ) |
Retrieve category id URL
Definition at line 362 of file Category.php.
00363 { 00364 Varien_Profiler::start('REGULAR: '.__METHOD__); 00365 $urlKey = $this->getUrlKey() ? $this->getUrlKey() : $this->formatUrlKey($this->getName()); 00366 $url = $this->getUrlInstance()->getUrl('catalog/category/view', array( 00367 's'=>$urlKey, 00368 'id'=>$this->getId(), 00369 )); 00370 Varien_Profiler::stop('REGULAR: '.__METHOD__); 00371 return $url; 00372 }
getChildren | ( | ) |
Retrieve children ids comma separated
Definition at line 542 of file Category.php.
00543 { 00544 return implode(',', $this->getResource()->getChildren($this, false)); 00545 }
getChildrenCategories | ( | ) |
Retuen children categories of current category
Definition at line 738 of file Category.php.
00739 { 00740 return $this->getResource()->getChildrenCategories($this); 00741 }
getCustomDesignDate | ( | ) |
getDefaultAttributeSetId | ( | ) |
Move category
int
Definition at line 189 of file Category.php.
00190 { 00191 return $this->getResource()->getEntityType()->getDefaultAttributeSetId(); 00192 }
getDefaultSortBy | ( | ) |
Retrieve Product Listing Default Sort By
Definition at line 800 of file Category.php.
00800 { 00801 if (!$sortBy = $this->getData('default_sort_by')) { 00802 $sortBy = Mage::getSingleton('catalog/config') 00803 ->getProductListDefaultSortBy($this->getStoreId()); 00804 } 00805 $available = $this->getAvailableSortByOptions(); 00806 if (!isset($available[$sortBy])) { 00807 $sortBy = array_keys($available); 00808 $sortBy = $sortBy[0]; 00809 } 00810 00811 return $sortBy; 00812 }
getDesignAttributes | ( | ) |
getImageUrl | ( | ) |
Retrieve image URL
Definition at line 394 of file Category.php.
00395 { 00396 $url = false; 00397 if ($image = $this->getImage()) { 00398 $url = Mage::getBaseUrl('media').'catalog/category/'.$image; 00399 } 00400 return $url; 00401 }
getLayoutUpdateHandle | ( | ) |
Retrieve Layout Update Handle name
Definition at line 275 of file Category.php.
00276 { 00277 $layout = 'catalog_category_'; 00278 if ($this->getIsAnchor()) { 00279 $layout .= 'layered'; 00280 } 00281 else { 00282 $layout .= 'default'; 00283 } 00284 return $layout; 00285 }
getLevel | ( | ) |
Retrieve level
Definition at line 599 of file Category.php.
00600 { 00601 if (!$this->hasLevel()) { 00602 return count(explode('/', $this->getPath())) - 1; 00603 } 00604 return $this->getData('level'); 00605 }
getName | ( | ) |
Retrieve Name data wraper
Definition at line 643 of file Category.php.
00644 { 00645 return $this->_getData('name'); 00646 }
getParentCategories | ( | ) |
Return parent categories of current category
Definition at line 728 of file Category.php.
00729 { 00730 return $this->getResource()->getParentCategories($this); 00731 }
getParentCategory | ( | ) |
Get parent category object
Definition at line 431 of file Category.php.
00432 { 00433 return Mage::getModel('catalog/category')->load($this->getParentId()); 00434 }
getParentId | ( | ) |
Get parent category identifier
Definition at line 441 of file Category.php.
00442 { 00443 $parentIds = $this->getParentIds(); 00444 return intval(array_pop($parentIds)); 00445 }
getParentIds | ( | ) |
Get all parent categories ids
Definition at line 452 of file Category.php.
00453 { 00454 return array_diff($this->getPathIds(), array($this->getId())); 00455 }
getPathIds | ( | ) |
Get array categories ids which are part of category path Result array contain id of current category because it is part of the path
Definition at line 584 of file Category.php.
00585 { 00586 $ids = $this->getData('path_ids'); 00587 if (is_null($ids)) { 00588 $ids = explode('/', $this->getPath()); 00589 $this->setData('path_ids', $ids); 00590 } 00591 return $ids; 00592 }
getPathInStore | ( | ) |
Retrieve Stores where isset category Path Return comma separated string
Definition at line 553 of file Category.php.
00554 { 00555 $result = array(); 00556 //$path = $this->getTreeModelInstance()->getPath($this->getId()); 00557 $path = array_reverse($this->getPathIds()); 00558 foreach ($path as $itemId) { 00559 if ($itemId == Mage::app()->getStore()->getRootCategoryId()) { 00560 break; 00561 } 00562 $result[] = $itemId; 00563 } 00564 return implode(',', $result); 00565 }
getProductCollection | ( | ) |
Get category products collection
Definition at line 199 of file Category.php.
00200 { 00201 $collection = Mage::getResourceModel('catalog/product_collection') 00202 ->setStoreId($this->getStoreId()) 00203 ->addCategoryFilter($this); 00204 return $collection; 00205 }
getProductCount | ( | ) |
Retrieve count products of category
Definition at line 697 of file Category.php.
00698 { 00699 if (!$this->hasProductCount()) { 00700 $count = $this->_getResource()->getProductCount($this); // load product count 00701 $this->setData('product_count', $count); 00702 } 00703 return $this->getData('product_count'); 00704 }
getProductsPosition | ( | ) |
Retrieve array of product id's for category
array($productId => $position)
Definition at line 237 of file Category.php.
00238 { 00239 if (!$this->getId()) { 00240 return array(); 00241 } 00242 00243 $array = $this->getData('products_position'); 00244 if (is_null($array)) { 00245 $array = $this->getResource()->getProductsPosition($this); 00246 $this->setData('products_position', $array); 00247 } 00248 return $array; 00249 }
getRequestPath | ( | ) |
Retrieve Request Path
Definition at line 633 of file Category.php.
00634 { 00635 return $this->_getData('request_path'); 00636 }
getStoreId | ( | ) |
Return store id.
If store id is underfined for category return current active store id
Definition at line 294 of file Category.php.
00295 { 00296 if ($this->hasData('store_id')) { 00297 return $this->_getData('store_id'); 00298 } 00299 return Mage::app()->getStore()->getId(); 00300 }
getStoreIds | ( | ) |
Retrieve array of store ids for category
Definition at line 256 of file Category.php.
00257 { 00258 if ($this->getInitialSetupFlag()) { 00259 return array(); 00260 } 00261 00262 if ($storeIds = $this->getData('store_ids')) { 00263 return $storeIds; 00264 } 00265 $storeIds = $this->getResource()->getStoreIds($this); 00266 $this->setData('store_ids', $storeIds); 00267 return $storeIds; 00268 }
getTreeModel | ( | ) |
Retrieve category tree model
Definition at line 153 of file Category.php.
00154 { 00155 return Mage::getResourceModel('catalog/category_tree'); 00156 }
getTreeModelInstance | ( | ) |
Enter description here...
Definition at line 163 of file Category.php.
00164 { 00165 if (is_null($this->_treeModel)) { 00166 $this->_treeModel = Mage::getResourceSingleton('catalog/category_tree'); 00167 } 00168 return $this->_treeModel; 00169 }
getUrl | ( | ) |
Get category url
Definition at line 323 of file Category.php.
00324 { 00325 $url = $this->_getData('url'); 00326 if (is_null($url)) { 00327 Varien_Profiler::start('REWRITE: '.__METHOD__); 00328 00329 if ($this->hasData('request_path') && $this->getRequestPath() != '') { 00330 $this->setData('url', $this->getUrlInstance()->getDirectUrl($this->getRequestPath())); 00331 return $this->getData('url'); 00332 } 00333 00334 Varien_Profiler::stop('REWRITE: '.__METHOD__); 00335 00336 $rewrite = $this->getUrlRewrite(); 00337 if ($this->getStoreId()) { 00338 $rewrite->setStoreId($this->getStoreId()); 00339 } 00340 $idPath = 'category/' . $this->getId(); 00341 $rewrite->loadByIdPath($idPath); 00342 00343 if ($rewrite->getId()) { 00344 $this->setData('url', $this->getUrlInstance()->getDirectUrl($rewrite->getRequestPath())); 00345 Varien_Profiler::stop('REWRITE: '.__METHOD__); 00346 return $this->getData('url'); 00347 } 00348 00349 Varien_Profiler::stop('REWRITE: '.__METHOD__); 00350 00351 $this->setData('url', $this->getCategoryIdUrl()); 00352 return $this->getData('url'); 00353 } 00354 return $url; 00355 }
getUrlInstance | ( | ) |
Retrieve URL instance
Definition at line 127 of file Category.php.
00128 { 00129 if (!self::$_url) { 00130 self::$_url = Mage::getModel('core/url'); 00131 } 00132 return self::$_url; 00133 }
getUrlPath | ( | ) |
Retrieve URL path
Definition at line 408 of file Category.php.
00409 { 00410 if ($path = $this->getData('url_path')) { 00411 return $path; 00412 } 00413 00414 $path = $this->getUrlKey(); 00415 00416 if ($this->getParentId()) { 00417 $parentPath = Mage::getModel('catalog/category')->load($this->getParentId())->getCategoryPath(); 00418 $path = $parentPath.'/'.$path; 00419 } 00420 00421 $this->setUrlPath($path); 00422 00423 return $path; 00424 }
getUrlRewrite | ( | ) |
Get url rewrite model
Definition at line 140 of file Category.php.
00141 { 00142 if (!self::$_urlRewrite) { 00143 self::$_urlRewrite = Mage::getModel('core/url_rewrite'); 00144 } 00145 return self::$_urlRewrite; 00146 }
hasChildren | ( | ) |
Retrieve Is Category has children flag
Definition at line 623 of file Category.php.
00624 { 00625 return $this->_getResource()->getChildrenAmount($this) > 0; 00626 }
isInRootCategoryList | ( | ) |
Check category is in Root Category list
Definition at line 748 of file Category.php.
00749 { 00750 return $this->getResource()->isInRootCategoryList($this); 00751 }
setStoreId | ( | $ | storeId | ) |
Set store id
integer | $storeId |
Definition at line 308 of file Category.php.
00309 { 00310 if (!is_numeric($storeId)) { 00311 $storeId = Mage::app($storeId)->getStore()->getId(); 00312 } 00313 $this->setData('store_id', $storeId); 00314 $this->getResource()->setStoreId($storeId); 00315 return $this; 00316 }
verifyIds | ( | array $ | ids | ) |
Verify category ids
array | $ids |
Definition at line 613 of file Category.php.
00614 { 00615 return $this->getResource()->verifyIds($ids); 00616 }
$_cacheTag = self::CACHE_TAG [protected] |
Model cache tag for clear cache in after save and after delete
Reimplemented from Mage_Core_Model_Abstract.
Definition at line 64 of file Category.php.
$_eventObject = 'category' [protected] |
$_eventPrefix = 'catalog_category' [protected] |
$_treeModel = null [protected] |
Definition at line 106 of file Category.php.
$_url [static, protected] |
Definition at line 71 of file Category.php.
$_urlRewrite [static, protected] |
Definition at line 78 of file Category.php.
$_useFlatResource = false [protected] |
Definition at line 85 of file Category.php.
const CACHE_TAG = 'catalog_category' |
Definition at line 45 of file Category.php.
const DM_MIXED = 'PRODUCTS_AND_PAGE' |
Definition at line 42 of file Category.php.
const DM_PAGE = 'PAGE' |
Definition at line 41 of file Category.php.
const DM_PRODUCT = 'PRODUCTS' |
Category display modes
Definition at line 40 of file Category.php.
const TREE_ROOT_ID = 1 |
Definition at line 43 of file Category.php.