English 中文(简体)
Magento - Load Products Collection with Pagin
原标题:Magento - Load Product Collection with Pagination

我曾试图装上产品收集,然后通过在审查中把ids打成阵列然后将这种过滤器应用到中来过滤产品。

我随附名单上的以下法典。 phtml that I m mît through atom拷贝 of the list. phtml

<block type="catalog/product_list" name="sale" template="reviewsList/index.phtml">

好消息是,收集工作将负荷,但打破了想象。 如果有的话,任何人都会有伟大的想法。

全文如下。

任何帮助都受到高度赞赏。

<?php
$reviewCollection = Mage::getModel( review/review )->getCollection()->addStoreFilter(Mage::app()->getStore()->getId())->addRateVotes()->setDateOrder();
$reviewArray = array();
foreach ($reviewCollection->getItems() as $thisReview):         
    array_push($reviewArray, $thisReview->getEntityPkValue());
endforeach;

$_productCollection = Mage::getModel( catalog/product )->getCollection()->addAttributeToFilter( entity_id , array( in  => $reviewArray))->addAttributeToSelect( * )->setPageSize(5);

$_productCollection = $_productCollection->load();

//$_productCollection=$this->getLoadedProductCollection();
$_helper = $this->helper( catalog/output );
?>
问题回答

展示想象力,你可以增加一种列入清单的工具。 我在这里为品牌做这项工作,这是按类别收集的。 你可以修改这一法典,以适合你们的收集工作。

class Mage_Catalog_Block_Product_Brandsnew extends Mage_Catalog_Block_Product_Abstract
{
protected $_productsCount = null;

const DEFAULT_PRODUCTS_COUNT = 5;

/**
 * Initialize block s cache
 */
protected function _construct()
{
    parent::_construct();

    $this->addColumnCountLayoutDepend( empty , 6)
        ->addColumnCountLayoutDepend( one_column , 5)
        ->addColumnCountLayoutDepend( two_columns_left , 4)
        ->addColumnCountLayoutDepend( two_columns_right , 4)
        ->addColumnCountLayoutDepend( three_columns , 3);

    $this->addData(array(
         cache_lifetime     => 86400,
         cache_tags         => array(Mage_Catalog_Model_Product::CACHE_TAG),
    ));
}

/**
 * Get Key pieces for caching block content
 *
 * @return array
 */
public function getCacheKeyInfo()
{
    return array(
        CATALOG_PRODUCT_NEW ,
       Mage::app()->getStore()->getId(),
       Mage::getDesign()->getPackageName(),
       Mage::getDesign()->getTheme( template ),
       Mage::getSingleton( customer/session )->getCustomerGroupId(),
        template  => $this->getTemplate(),
       $this->getProductsCount()
    );
}

/**
 * Prepare collection with new products and applied page limits.
 *
 * return Mage_Catalog_Block_Product_New
 */
protected function _beforeToHtml()
{
$toolbar = $this->getToolbarBlock();
//$todayDate  = Mage::app()->getLocale()->date()->toString(Varien_Date::DATETIME_INTERNAL_FORMAT);
   $collection = Mage::getResourceModel( catalog/product_collection )
        ->addAttributeToSelect(Mage::getSingleton( catalog/config )->getProductAttributes())
        ->addMinimalPrice()
        ->addStoreFilter()
       ->addAttributeToFilter( manufacturer ,$this->getRequest()->manufacturer);
    Mage::getSingleton( catalog/product_status )->addVisibleFilterToCollection($collection);
    Mage::getSingleton( catalog/product_visibility )->addVisibleInSearchFilterToCollection($collection);

    //$collection->addAttributeToFilter( special_price  ,array( neq  =>   ));

    // use sortable parameters
    if ($orders = $this->getAvailableOrders()) {
        $toolbar->setAvailableOrders($orders);
    }
    if ($sort = $this->getSortBy()) {
        $toolbar->setDefaultOrder($sort);
    }
        if (isset($_GET[ p ])) {

        $toolbar->setLimit($toolbar->getLimit());
    }

    $this->setProductCollection($collection);

    $toolbar->setCollection($collection);

    $this->setChild( toolbar , $toolbar);
    Mage::dispatchEvent( catalog_block_product_list_collection , array(
         collection =>$collection,
    ));

    $collection->load();  
    return parent::_beforeToHtml();


}

/**
 * Set how much product should be displayed at once.
 *
 * @param $count
 * @return Mage_Catalog_Block_Product_New
 */
public function setProductsCount($count)
{
    $this->_productsCount = $count;
    return $this;
}

/**
 * Get how much products should be displayed at once.
 *
 * @return int
 */
public function getProductsCount()
{
    if (null === $this->_productsCount) {
        $this->_productsCount = self::DEFAULT_PRODUCTS_COUNT;
    }
    return $this->_productsCount;
}


/**
 * Retrieve Toolbar block
 *
 * @return Mage_Catalog_Block_Product_List_Toolbar
 */
public function getToolbarBlock()
{
    if ($blockName = $this->getToolbarBlockName()) {
        if ($block = $this->getLayout()->getBlock($blockName)) {
            return $block;
        }
    }
    $block = $this->getLayout()->createBlock($this->_defaultToolbarBlock, microtime());
    return $block;
}

public function setCollection($collection)
{
    $this->_productCollection = $collection;
    return $this;
} 

}




相关问题
Magento addFieldToFilter allow NULLs

When using the Magento collection method addFieldToFilter is it possible to allow filtering by NULL values? I want to select all the products in a collection that have a custom attribute even if no ...

Get product link from Magento API

I am new to Magento and using their API. I need to be able to get the product url from the API call. I see that I can access the url_key and url_path, but unfortunately that s not necessarily what ...

magento extension installation

I want to install a Magento extension in WAMP, but not from the Magento connect system. How can I do this? I have the module (extension) code and I already installed the sample data in the Magento ...

Link to a specific step in onepage checkout

Is it possible to redirect the browser to nth step in the onepage checkout? If so, how would one go about doing it? I m working on a payment module and have a sort of "cancel" action that i would ...

How do I filter a collection by a YesNo type attribute?

I have a ‘featured’ attribute, which has a Yes/No select-list as the admin input. I presume that the values for Yes and No are 1 and 0, as they are for every other Yes/No list. However, if I try and ...

热门标签