我在“选择更改”上添加了一个搜索按钮,但它仅适用于一个级别的magento

我在“选择更改”上添加了一个搜索按钮,但它仅适用于一个级别的magento,magento,Magento,参考: 在助手类中 } phtml文件 var children=$H(); 功能显示Cat(obj,级别){ var catId=对象值; 级别+=1; if($('cat_容器+液位)){ $('cat_container_'+level).remove(); } if(children.get(catId)){ var options=children.get(catId); var html=''; 对于(变量i=0;i

参考:

在助手类中

}

phtml文件


var children=$H();
功能显示Cat(obj,级别){
var catId=对象值;
级别+=1;
if($('cat_容器+液位)){
$('cat_container_'+level).remove();
}
if(children.get(catId)){
var options=children.get(catId);
var html='';
对于(变量i=0;ipublic function getCategoriesDropdown() {
$categories = Mage::getModel('catalog/category')
    ->getCollection()
    ->addAttributeToSelect('name')
    ->addAttributeToSort('path', 'asc')
    ->addFieldToFilter('is_active', array('eq'=>'1'));

$first = array();
$children = array();
foreach ($categories->getItems() as $cat) {
    if ($cat->getLevel() == 2) {
        $first[$cat->getId()] = $cat;
    } else if ($cat->getParentId()) {
        $children[$cat->getParentId()][] = $cat->getData();
    }
}

return array('first' => $first, 'children' => $children);
 <?php $tree = $this->helper('xxx')->getCategoriesDropdown(); ?>
<script type="text/javascript">
    var children = $H(<?php echo json_encode($tree['children']) ?>);

    function showCat(obj, level) {
        var catId = obj.value;
        level += 1;
        if ($('cat_container_' + level)) {
            $('cat_container_' + level).remove();
        }
        if (children.get(catId)) {
            var options = children.get(catId);
            var html = '<select id="cat_' + catId + '" onchange="showCat(this, ' + level + ')">';
            for (var i = 0; i < options.length; i++) {
                html += '<option value="' + options[i].entity_id + '">' + options[i].name + '</option>';
            }
            html += '</select>';
            html = '<div id="cat_container_' + level + '">' + html + '</div>';

            $('sub_cat').insert(html);
        }
    }
</script>


<?php

$catalogSearchHelper =  $this->helper('catalogsearch');
?>

   
<form id="search_mini_form" action="<?php echo $catalogSearchHelper->getResultUrl() ?>" method="get">

  <select id="first_cat" onchange="showCat(this, 2)" name="<?php echo $catalogSearchHelper->getQueryParamName() ?>" value="<?php echo $catalogSearchHelper->getEscapedQueryText() ?>"  >
    <?php foreach ($tree['first'] as $cat): ?>
        <option value="<?php echo $cat->getId() ?>"><?php echo $cat->getName() ?></option>
    <?php endforeach ?>
</select>

<button type="submit" title="<?php echo $this->__('Search') ?>" class="button"><span><span><?php echo $this->__('Search') ?></span></span></button>