Mage::getResourceModel(‘reports/product_collection’)
->addOrderedQty()
->addAttributeToSelect(‘*’)
->setPage(1, 5)
->load();
Printable View
Mage::getResourceModel(‘reports/product_collection’)
->addOrderedQty()
->addAttributeToSelect(‘*’)
->setPage(1, 5)
->load();
You can get it by this simple line
Or you may look at this extensionPHP Code:
$_productCollection = Mage::getResourceModel('sales/report_bestsellers_collection')
->setModel('catalog/product')
;
http://www.magentocommerce.com/magen...extension.html
Maybe this article can help you too :)
http://inchoo.net/magento/bestseller...ts-in-magento/
Thank you for help peter :)
$storeId = (int) Mage::app()->getStore()->getId();
// Date
$date = new Zend_Date();
$toDate = $date->setDay(1)->getDate()->get('Y-MM-DD');
$fromDate = $date->subMonth(1)->getDate()->get('Y-MM-DD');
$collection = Mage::getResourceModel('catalog/product_collection')
->addAttributeToSelect(Mage::getSingleton('catalo g/config')->getProductAttributes())
->addStoreFilter()
->addPriceData()
->addTaxPercents()
->addUrlRewrite()
->setPageSize(5);
$collection->getSelect()
->joinLeft(
array('aggregation' => $collection->getResource()->getTable('sales/bestsellers_aggregated_monthly')),
"e.entity_id = aggregation.product_id AND aggregation.store_id={$storeId} AND aggregation.period BETWEEN '{$fromDate}' AND '{$toDate}'",
array('SUM(aggregation.qty_ordered) AS sold_quantity')
)
->group('e.entity_id')
->order(array('sold_quantity DESC', 'e.created_at'));
Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);
Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($collection );
$collection = $collection->getData();
$collection will give 5 bestseller products.
Regards,
Knowband Plugins | Buy Best Magento Extensions
<!--?php
Mega::getResourceModel('reports/product_collection')-->addOrderedQty()->addAttributeToSelect('*')->setPage(1,5)->load();
?>