1
我想在自動提示字段中顯示所有類別列表。所以我有一個像查詢代碼 -在magento中獲取帶類似查詢的類別集合
function res($cur_category){
$children_categories = Mage::getModel('catalog/category')->getCategories($cur_category->getId());
$children_categories->addAttributeToFilter('name', array('like' => '%a%'));
foreach($children_categories as $child){
$name = $child->getName();
$option.='<li onClick="fill(\''.addslashes($child->getName()).'\');">' .$child->getName(). "</li>";
$option.=res($child);
}
unset($children_categories);
return $option;
}
function GetTree(){
$rootcatId= Mage::app()->getStore()->getRootCategoryId();
$categories = Mage::getModel('catalog/category')->getCategories($rootcatId);
$categories->addAttributeToFilter('name', array('like' => '%a%'));
foreach($categories as $category)
{
$option.='<li onClick="fill(\''.addslashes($category->getName()).'\');">'.$category->getName()."</li>";
if($category->hasChildren()){
$option.= res($category);
}
}
unset($categories);
return $option;
}
echo $select = '<ul>'.GetTree().'</ul>';
但這種代碼是不一樣的查詢工作,而不會像查詢它是否工作正常罰款和顯示分類列表。請用like提供我的查詢。