【问题标题】:Need Help with Magento Mini-Search在 Magento 迷你搜索方面需要帮助
【发布时间】:2009-12-10 23:18:38
【问题描述】:

我将以下代码提供给Edmond's Ecommerce,它将 Magento 的标准迷你搜索表单转换为更详细的迷你搜索,就像在 Amazon 和 eBay 中看到的那样。此时,我可以访问根目录的子类别,但我想从子子类别中提取数组。根目录 > 子类别 > 子子类别。

尝试实现 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>

【问题讨论】:

    标签: php search magento e-commerce search-form


    【解决方案1】:

    这是一个更简单的解决方案,我已经能够将它放在一起,效果很好。如果有人能够进一步浓缩这一点,将不胜感激。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-05-20
      • 2011-01-27
      • 2014-02-06
      • 2017-11-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多