In my case i have create featured product list with product 10 and it display randomaly.
Please copy past following code in your collection block file.
protected function _getProductCollection()
{
if (is_null($this->_productCollection)) {
$collection = Mage::getModel('catalog/product')->getCollection();
$collection
->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
->addMinimalPrice()
->addFinalPrice()
->addAttributeToFilter('featured_product', 1)
->addTaxPercents();
$collection->getSelect()->order(new Zend_Db_Expr('RAND()'));
$collection->setPage(1, 10)->load();
Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);
Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($collection);
$this->_productCollection = $collection;
}
return $this->_productCollection;
}
Please copy past following code in your collection block file.
protected function _getProductCollection()
{
if (is_null($this->_productCollection)) {
$collection = Mage::getModel('catalog/product')->getCollection();
$collection
->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
->addMinimalPrice()
->addFinalPrice()
->addAttributeToFilter('featured_product', 1)
->addTaxPercents();
$collection->getSelect()->order(new Zend_Db_Expr('RAND()'));
$collection->setPage(1, 10)->load();
Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);
Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($collection);
$this->_productCollection = $collection;
}
return $this->_productCollection;
}
No comments:
Post a Comment