magento limiting number of returned items in product collection call

前端 未结 6 819
北荒
北荒 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:28

    A similar approach to @joseph is to override Mage_Catalog_Block_Product_List but insert the following code in your new class:

    const PAGE_SIZE = 3;
    
    protected function _getProductCollection(){
        $collection = parent::_getProductCollection();
        $yourCustomBoolean = someFunctionThatDetectsYourCustomPage();
        if($yourCustomBoolean) {
            $collection->setPageSize(self::PAGE_SIZE);
        }
        return $collection;
    }
    

    that way you will inherit any future changes in the Mage_Catalog code from the parent block but still set your page limits.

    Ideally you would use a system.xml node to create a field that can be edited by an administrator without hardcoding the page_size. The xml would look something like:

    
    
        
            
                
                    
                        
                            
                            text
                            9999
                            1
                            1
                            1
                        
                    
                
            
        
    
    
    

    Then retrieve that value in your code with:

    $page_size = Mage::getStoreConfig('catalog/frontend/custom_page_size');
    

    HTH,
    JD

提交回复
热议问题