dongnai3960 2015-05-07 05:14
浏览 18

magento目录搜索在url中添加结果计数

I want to add result count in search url. The default url is like domain.com/catalogsearch/result/?q=queries But I want add result count in url like,

`domain.com/catalogsearch/result/?q=queries&count=50`

I tried with below event observer

controller_action_layout_render_before_catalogsearch_result_index

and Observer.php

 <?php
    class PackgeName_ModuleName_Model_Observer {
        // the product list block name in layout
        const RESULT_BLOCK_NAME = 'search_result_list';
        public function loadResult(Varien_Event_Observer $observer) {
            $currentUrl = Mage::helper ( 'core/url' )->getCurrentUrl ();

            $block = Mage::app ()->getLayout ()->getBlock ( self::RESULT_BLOCK_NAME );
            if ($block) {

                $collection = $block->getLoadedProductCollection ();

                /**
                 * @var Mage_Catalog_Model_Product $product
                 */
                $count = $collection->getSize ();

                $resultUrl = $currentUrl . '&count=' . $count;

                if ($resultUrl) {

                    Mage::app ()->getResponse ()->setRedirect ( $resultUrl );
                    exit (); // stop everything else
                }
            }
        }
    }

But the problem is its again triggered. So it go to endless loop. Any Idea's to fix this issue or Is there any way to achieve this ? Please help me..

  • 写回答

2条回答 默认 最新

  • dongzhang6021 2015-05-08 13:03
    关注

    Just add a check that the count is not in the request uri:

        public function loadResult(Varien_Event_Observer $observer) {
    
           $count = Mage::app()->getRequest()->getParam('count');
    
           if (!$count){
    
               $currentUrl = Mage::helper ( 'core/url' )->getCurrentUrl ();
    
               $block = Mage::app ()->getLayout ()->getBlock ( self::RESULT_BLOCK_NAME );
    
    评论

报告相同问题?

悬赏问题

  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用