get product collection
protected function getRandproduct() {
$homeProductNumber = 9;
$collection = $this->_getVisNoRandCol();
$tempCollection = $this->_addProductAttributesAndPrices($collection)
->addAttributeToSelect('*')
->addFieldToFilter(array(array('attribute'=>'page_accueil','eq'=>'1')))
->setPageSize($homeProductNumber)
->setCurPage(1);
if($tempCollection->getSize() <= 0){
$collection = $this->_getVisCol();
$tempCollection = $this->_addProductAttributesAndPrices($collection)
->addAttributeToSelect('*')
->setPageSize($homeProductNumber)
->setCurPage(1);
}
$collection = new Varien_Data_Collection();
foreach ($tempCollection as $item){
$product = Mage::getModel('catalog/product')->load($item->getEntityId());
$collection->addItem($product);
}
return $collection;
}
protected function _getVisCol(){
$collection = Mage::getResourceModel('catalog/product_collection');
$collection->getSelect()->order('rand()');
$collection->setVisibility(Mage::getSingleton('catalog/product_visibility')->getVisibleInCatalogIds());
return $collection;
}
protected function _getVisNoRandCol(){
$collection = Mage::getResourceModel('catalog/product_collection');
$collection->getSelect()->order('e.entity_id ASC');
$collection->setVisibility(Mage::getSingleton('catalog/product_visibility')->getVisibleInCatalogIds());
return $collection;
}