在无结果搜索页面上显示特定类别产品

时间:2013-07-25 14:35:26

标签: magento magento-1.7 magento-1.4 magento-1.5 magento-1.6

当我们在magento网站中搜索错误的关键字“sdfsdf”时,会显示“您的搜索没有返回结果”。在这里,我想显示任何类别的产品,如“类似产品”类别,因为我们在主页上显示“畅销书”。我试过通过调用catalogsearch.xml中的块来尝试。 BUt catalogsearch.xml doent包含任何没有结果的块。那么如何在无结果页面上显示任何类别的产品。

我有一个想法,我们可以在.phtml页面上显示特定的类别产品吗?如果我们可以显示特定类别的产品,那么我们可以从“result.phtml”调用该类别。有什么帮助吗?

我的result.phtml

<?php if($this->getResultCount()): ?>
<?php echo $this->getMessagesBlock()->getGroupedHtml() ?>
<div class="page-title category-title">
    <?php if ($this->helper('rss/catalog')->getTagFeedUrl()): ?>
        <a href="<?php echo $this->helper('rss/catalog')->getTagFeedUrl() ?>" class="nobr link-rss"><?php echo $this->__('Subscribe to Feed') ?></a>
    <?php endif; ?>
    <h1><?php echo ($this->getHeaderText() || $this->getHeaderText() === false) ? $this->getHeaderText() : $this->__("Search results for '%s'", $this->helper('catalogsearch')->getEscapedQueryText()) ?></h1>
</div>
    <?php if ($messages = $this->getNoteMessages()):?>
    <p class="note-msg">
        <?php foreach ($messages as $message):?>
            <?php echo $message?><br />
        <?php endforeach;?>
    </p>
    <?php endif; ?>
    <?php echo $this->getProductListHtml() ?>
<?php else: ?>
<div class="page-title category-title">
    <h1><?php echo ($this->getHeaderText() || $this->getHeaderText() === false) ? $this->getHeaderText() : $this->__("Search results for '%s'", $this->helper('catalogsearch')->getEscapedQueryText()) ?></h1>
</div>
<p class="note-msg">
    <?php echo ($this->getNoResultText()) ? $this->getNoResultText() : $this->__('Your search returns no results.') ?>
    <?php if ($messages = $this->getNoteMessages()):?>
        <?php foreach ($messages as $message):?>
        <br /><?php echo $message?>
        <?php endforeach;?>

    <?php endif; ?>
 </p>
<div class="search-noresults">
<h1>Meanwhile, You may go through our featured categories:</h1>  
</div>
<?php echo $this->getLayout()->CreateBlock('catalog/product_list')->setCategoryId(18)->setTemplate('catalog/product/list.phtml')->toHtml();?>

<?php endif; ?>

1 个答案:

答案 0 :(得分:1)

一个简单的解决方案是在catalogsearch / result.phtml模板中,您需要设置在没有结果时会发生什么

<?php if($this->getResultCount()): ?>
SHOW RESULTS
LEAVE DEFAULT
<?php else: ?>
NO RESULTS
<?php echo $this->getLayout()->createBlock('catalog/product_list')->setCategoryId(4)->setTemplate('catalog/product/list.phtml')->toHtml() ?>
<?php endif; ?>