Search by category name

后端 未结 3 607
春和景丽
春和景丽 2021-01-14 05:19

When I try to do search by Category Name it reurns nothing. For Eg, I have Organic, Unique, Sprots etc.as categories and in search I type Unique. But I get no results.

3条回答
  •  耶瑟儿~
    2021-01-14 05:42

    Unfortunately, Magento's default search function is a product search and is limited to that scope. When you search "Unique" it's looking in the products name and perhaps the description depending on your configuration.

    A quick solution would be to display a listing of matching categories along with the product results.

    helper('catalogSearch')->getEscapedQueryText();
        $categories = $this->helper('catalog/category')->getStoreCategories(false, true);
        $count = 0;
        foreach ($categories as $count_category) {
            if ($this->helper('catalog/category')->canShow($count_category) && stripos($count_category->getName(), $searchTerm) !== false) 
                   $count++;
        }
    
        if ($count > 0):
    
        echo "
    "; echo "The following product categories matched your search:"; foreach ($categories as $category) { if ($this->helper('catalog/category')->canShow($category) && stripos($category->getName(), $searchTerm) !== false) echo "

    > ".$category->getName()."

    "; } echo "
    "; endif;?>

    Source: http://www.magentocommerce.com/boards/viewthread/74632/

提交回复
热议问题