答案 0 :(得分:1)
这是代码,您可以在模块的块或帮助器下创建波纹管功能。
function getCategoriesTreeView() {
// Get category collection
$categories = Mage::getModel('catalog/category')
->getCollection()
->addAttributeToSelect('name')
->addAttributeToSort('path', 'asc')
->addFieldToFilter('is_active', array('eq'=>'1'))
->load()
->toArray();
// Arrange categories in required array
$categoryList = array();
foreach ($categories as $catId => $category) {
if (isset($category['name'])) {
$categoryList[] = array(
'label' => $category['name'],
'level' =>$category['level'],
'value' => $catId
);
}
}
return $categoryList;
}
现在是设计时间,下面是代码,它会给你下拉类别。
<select id="categorylist" name="categorylist">
<option value="">Select Category</option>
<?php
$categoriesTreeView = getCategoriesTreeView();
foreach($categoriesTreeView as $value)
{
$catName = $value['label'];
$catId = $value['value'];
$catLevel = $value['level'];
$space = ' ';
for($i=1; $i<$catLevel; $i++){
$space = $space." ";
}
$catName = $space.$catName;
?>
<option value="<?php echo $catIdIs; ?>"><?php echo $catName ?></option>
<?php
}
?>
</select>