如何在magento中按类别搜索?

时间:2014-08-11 11:13:35

标签: magento magento-1.8

我想根据类别搜索数据,但不按类别搜索。标题中有一个类别下拉部分和搜索框,我想根据所选类别搜索关键字。但它不按类别搜索。

我在app/design/frontend/default/mytheme/template/catalogsearch/form.mini.phtml

中使用了代码
<?php
$catalogSearchHelper =  $this->helper('catalogsearch');
 $cats = Mage::getModel('catalog/category') -> load(2) -> getChildren();
    $catIds = explode(',', $cats);
    $categories = array();
    foreach ($catIds as $catId) {
        $category = Mage::getModel('catalog/category') -> load($catId);
        $categories[$category -> getName()] = array('name' => $category -> getName(), 'url' => $category -> getUrl(), 'img' => $category -> getImageUrl(), 'subcategories' => Mage::getModel('catalog/category') -> getCategories($catId));
    }
    ksort($categories, SORT_STRING);
?>
<form id="search_mini_form" action="<?php echo $catalogSearchHelper->getResultUrl() ?>" method="get">
 <div class="wrapper-demo">
  <div id="dd" class="wrapper-dropdown-3" tabindex="1">
                        <span>All Categories</span>
                        <ul class="dropdown content">
                            <?php foreach($categories as $name => $data): ?>
        <li><a><?php echo $data['name']; ?></a>
            </li>
    <?php endforeach; ?>
                        </ul>
                    </div>
    </div>
        <input id="search" type="search" placeholder="Enter your keyword" name="<?php echo $catalogSearchHelper->getQueryParamName() ?>" value="<?php echo $catalogSearchHelper->getEscapedQueryText() ?>" maxlength="<?php echo $catalogSearchHelper->getMaxQueryLength();?>" />
        <input type="image" name="myclicker" src="<?php echo $this->getSkinUrl('images/searchicon.png'); ?>" > 

        <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->__('Search entire store here...') ?>');
            searchForm.initAutocomplete('<?php echo $catalogSearchHelper->getSuggestUrl() ?>', 'search_autocomplete');
        //]]>
        </script>
</form>

如果有人知道,请帮助我。 谢谢!

1 个答案:

答案 0 :(得分:0)

您只需使用

即可

Catalog Category Search Plugin