views:

322

answers:

2

I have the below code courtesy to Edmond's Ecommerce that converts Magento's standard mini-search form to a more detailed mini-search like the ones seen in Amazon and eBay. At this juncture, I'm able to get to the sub-categories of the root directory, but instead, I would like to pull out the array from the sub-sub-categories. Root Directory > Sub-Category > Sub-Sub-Category.

Tried to implement many permutations of getSubCategories including the following but kept getting errors.

$category->load(Mage::app()->getStore()->getRootCategoryId()->getSubCategories());

A hint that was shared hasn't been any help. Maybe I'm not able to peruse it.

if($this->getSubCategories($c)){
foreach($this->getSubCategories($c) as $sc){
foreach($this->getSubCategories($sc) as $ssc){
...
}
}
}

You may notice the $exclude_array option. The array of sub-sub-categories must be accurate for me to be able to exclude categories that are irrelevant to the mini-search. Any suggestions would be appreciated.

<?php
$category = Mage::getModel('catalog/category');
if(is_object(Mage::registry('current_category'))){
    $current_category_path=Mage::registry('current_category')->getPathIds();
}else{
    $current_category_path = array();
}
$category->load(Mage::app()->getStore()->getRootCategoryId());
$children_string = $category->getChildren();
$children = explode(',',$children_string);
$extra_options='';
$exclude_array=array(1,2,3);
foreach($children as $c){
if(in_array($c, $exclude_array)){continue;}
    $selected = (in_array($c, $current_category_path))?'SELECTED':'';
    $extra_options.= '<option value="' . $c . '" ' . $selected . '>' . $category->load($c)->getName() . '</option>' . "\n";    
}
?>

<form id="search_mini_form" action="<?php echo $this->helper('catalogSearch')->getResultUrl() ?>" method="get">
    <fieldset>
        <legend><?php echo $this->__('Search Site') ?></legend>
        <div class="mini-search">
                <?php echo $this->__('I am celebrating my') ?>
      <select name="cat" id="cat" class="input-text">
            <option value="">Any Occassion</option>
            <?= $extra_options ?>
           </select>
            <input id="search" type="text" class="input-text" name="<?php echo $this->helper('catalogSearch')->getQueryParamName() ?>" value="<?php echo $this->helper('catalogSearch')->getEscapedQueryText() ?>" />
            <input class="search-box" type="submit" value="Go" alt="<?php echo $this->__('Search') ?>" />
            <div id="search_autocomplete" class="search-autocomplete"></div>
            <script type="text/javascript">
            //<![CDATA[
                var searchForm = new Varien.searchForm('search_mini_form', 'search', '<?php echo $this->__('and looking for...') ?>');
                searchForm.initAutocomplete('<?php echo $this->helper('catalogSearch')->getSuggestUrl() ?>', 'search_autocomplete');
            //]]>
            </script>
        </div>
    </fieldset>
</form>
A: 

Here's a simpler solution I've been able to put together that works fine. If anyone is able condense this even more, it would be appreciated.

<?php
$category = Mage::getModel('catalog/category')->load(enter category id here);
if(is_object(Mage::registry('current_category'))){
    $current_category_path=Mage::registry('current_category')->getPathIds();
}else{
    $current_category_path = array();
}
$children_string = $category->getChildren();
$children = explode(',',$children_string);
$extra_options='';
$exclude_array=array(1,2,3); /* exclude categories */
foreach($children as $c){
if(in_array($c, $exclude_array)){continue;}
    $selected = (in_array($c, $current_category_path))?'SELECTED':'';
    $extra_options.= '<option value="' . $c . '" ' . $selected . '>' . $category->load($c)->getName() . '</option>' . "\n";    
}
?>
monocat
A: 

I'am not programmer. Not know whether to put code. Where this section. Thank you

krite
app/design/frontend/default/your-theme/template/catalogsearch/form.mini.pthml
monocat