magento limiting number of returned items in product collection call

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

    As was mentioned, the productCollection already has page size set. There is another way to get the collection though; via the catalog/product Model:

    $productCollection = Mage::getModel('catalog/product')
        ->getCollection()
        ->addAttributeToSelect(
            array('name', 'image', 'price')
        )
        ->addIdFilter( 
            array('1', '2')
        )
        ->setPageSize( 2 )
        ->load();
    ;
    
    return $productCollection->getSelect()->__toString();
    

    The resulting query (and ultimately object) contains the LIMIT syntax:

    SELECT `e`.* ... WHERE (`e`.`entity_id` IN('1', '2')) LIMIT 2;
    

    Is that what you were asking?

提交回复
热议问题