magento limiting number of returned items in product collection call

前端 未结 6 924
北荒
北荒 2021-02-04 11:10

Im trying to limit the number of returned results manually in a copy of the list.phtml template, but its turning out to be alot harder than I anticipated.

Ive tried man

6条回答
  •  没有蜡笔的小新
    2021-02-04 11:25

    unfortunately it doesn't work because in the _getProductCollection() method the Collection has been already initialized with a page size.

    A more flexible solution could be that of observing the catalog_product_collection_load_before event which, as the name suggests, is dispatched before the collection is loaded.

    Here follows an example (assuming to write a yourmodule extension under yourpackage):

    STEP 1: Define your observer in config.xml

    in the global section of your config.xml extension file insert something like:

    
      
        
          
            singleton
            yourpackage_yourmodule/catalog_observer
            limitPageSize
          
        
      
        
    

    STEP 2: Define your Observer class under the Model\Catalog folder:

    getEvent();
        $collection = $event->getCollection();
        $collection->setPageSize(3);
        return $this;
      }
    }
    

    Hope it helps. Sincerely, Alessandro Ronchi

提交回复
热议问题