前台显示Category定制属性两例
因业务需要,Category增加了一个属性叫promo_name,进入Category列表页时希望将其显示出来,这里的情况具体分两种:
I. load方法访问自定义属性
$c = Mage::getModel('catalog/category');echo $c->getPromoName();
public function getCategoryNodes($parentId = null, $sorted=false, $asCollection=false, $toLoad=true) { $config = Mage::getModel('catalogue/joyconfig'); if(empty($parentId)) { $parentId = $config->getRootBrandId(); } $category = Mage::getModel('catalog/category'); /* @var $category Mage_Catalog_Model_Category */ if (!$category->checkId($parentId)) { if ($asCollection) { return new Varien_Data_Collection(); } return array(); } $recursionLevel = max(0, 0); $tree = $category->getTreeModel(); $nodes = $tree->loadNode($parentId) ->loadChildren($recursionLevel) ->getChildren(); $tree->addCollectionData(null, $sorted, $parentId, $toLoad, true); if ($asCollection) { return $tree->getCollection(); } else { return $nodes; } }
$tree->addCollectionData(null, $sorted, $parentId, $toLoad, true);
$tree->getCollection($sorted)->addAttributeToSelect('promot_name');