【问题标题】:Display specific category products on no results search page在无结果搜索页面上显示特定类别的产品
【发布时间】:2013-07-25 14:35:25
【问题描述】:

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

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

我的结果.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; ?>

【问题讨论】:

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


    【解决方案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; ?>
    

    【讨论】:

    • 感谢您的回复,但是按照您的建议添加后,再次显示没有符合您选择的产品。我认为它也在搜索该类别中的关键字。我已经更新了我的 result.phtml 是上面的问题。建议我。
    • system.log 或 exception.log 中有什么内容
    • 好的...所以我已经做了一些测试,目前在显示类别方面找不到解决方案。但我建议安装一个免费的特色产品扩展,可能是由 Inchoo 提供的。我可以让这些结果显示在块中
    • 你如何解决这个问题?我也有同样的问题。@pavankumar
    猜你喜欢
    • 1970-01-01
    • 2019-04-29
    • 2019-02-25
    • 1970-01-01
    • 2014-09-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多