不幸的是,Magento的默认搜索功能是产品搜索,仅限于该范围.当您搜索"唯一"时,它会查看产品名称以及可能的描述,具体取决于您的配置.
一个快速的解决方案是显示匹配类别的列表以及产品结果.
<?php
$searchTerm = $this->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 "<div class=\"search-term-notice\">";
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 "<h3> > <a href='".$category->getUrl()."'>".$category->getName()."</a></h3></p>";
}
echo "</div>";
endif;?>
Run Code Online (Sandbox Code Playgroud)
资料来源:http://www.magentocommerce.com/boards/viewthread/74632/