2009-12-10 69 views
0

帮助我有下面的代码礼貌Edmond's Ecommerce是Magento的标准mini-搜索表单转换为像亚马逊和eBay看到的那些更详细的迷你搜索。在这个时候,我能够到达根目录的子类别,但是我想从子子类别中取出数组。根目录>子类别>子子类别。需要与Magento的迷你搜索

试图执行getSubCategories包括以下内容的多少排列,但继续得到错误。

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

被共享的提示没有任何帮助。也许我无法仔细阅读。

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

您可能会注意到$ exclude_array选项。子分类数组必须准确,才能排除与迷你搜索无关的分类。任何建议,将不胜感激。

<?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> 

回答

0

这里有一个简单的解决方案,我已经能够放在一起正常工作。如果有人能够更加浓缩这一点,将不胜感激。

<?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";  
} 
?>