/*Get overall Bestselling products*/
public function getBestsellingProducts()
{
// number of products to display
$productCount = 5;
// store ID
$storeId = Mage::app()->getStore()->getId();
// get most viewed products for current category
$products = Mage::getResourceModel('reports/product_collection')
->addAttributeToSelect('*')
->addOrderedQty()
->setStoreId($storeId)
->addStoreFilter($storeId)
->setOrder('ordered_qty', 'desc')
->setPageSize($productCount);
Mage::getSingleton('catalog/product_status')
->addVisibleFilterToCollection($products);
Mage::getSingleton('catalog/product_visibility')
->addVisibleInCatalogFilterToCollection($products);
return $products;
}
/*Get Bestselling products for current category*/
public function getBestsellingProducts()
{
// number of products to display
$productCount = 5;
// store ID
$storeId = Mage::app()->getStore()->getId();
// get most viewed products for current category
$products = Mage::getResourceModel('reports/product_collection')
->addAttributeToSelect('*')
->addOrderedQty()
->setStoreId($storeId)
->addStoreFilter($storeId)
->addCategoryFilter(Mage::registry('current_category'))
->setOrder('ordered_qty', 'desc')
->setPageSize($productCount);
Mage::getSingleton('catalog/product_status')
->addVisibleFilterToCollection($products);
Mage::getSingleton('catalog/product_visibility')
->addVisibleInCatalogFilterToCollection($products);
return $products;
}
/*Get Bestselling products for last 30 days*/
public function getBestsellingProducts()
{
// number of products to display
$productCount = 5;
// store ID
$storeId = Mage::app()->getStore()->getId();
// get today and last 30 days time
$today = time();
$last = $today - (60*60*24*30);
$from = date("Y-m-d", $last);
$to = date("Y-m-d", $today);
// get most viewed products for current category
$products = Mage::getResourceModel('reports/product_collection')
->addAttributeToSelect('*')
->addOrderedQty($from, $to)
->setStoreId($storeId)
->addStoreFilter($storeId)
->setOrder('ordered_qty', 'desc')
->setPageSize($productCount);
Mage::getSingleton('catalog/product_status')
->addVisibleFilterToCollection($products);
Mage::getSingleton('catalog/product_visibility')
->addVisibleInCatalogFilterToCollection($products);
return $products;
}