Bestseller in magento
One of the most popular option, that each customer needs is the best selling/ best seller products. Each second e-commerce site that uses magento, needs a location where they can show products which are mostly purchased by customer and in the term e-commerce, we call that products as Best Seller Products. Now the question arise that how to show best seller products in magento. I also needed to implement this feature and as generally we do, I also searched best–seller module for magento, as I was also unkown from the little trick of showing products collection in magento.
we have to just call
Mage::getResourceModel(‘reports/product_collection’); //in our php file
returns the Products Collection for reporting purpose. We can add a few functions and get some useful data that we need for many customer’s e-commerce site.
Like when we want to get Best Seller Products in magento we just need to add one more filter to this collection.
$products = Mage::getResourceModel(‘reports/product_collection’)->addOrderedQty(); // retrieve Ordered qty of Products with Products collection.
Now a few more filter like
addAttributeToSelect(array(‘name’, ‘price’, ‘small_image’, ‘short_description’, ‘description’))
Above filter used to select required attributes/fields, we need with product collection. We can select the required attributes/ fields with this function by passing fields in array or we can also pass * when we need to take all fields
addStoreFilter($storeId) // add this to retrieve products collection related to specific store
Mostly Ordered products on top. Hence we with the help of all of above functions related to this model we can get the Best Seller Products in magento through the following PHP Code
$products = Mage::getResourceModel(‘reports/product_collection’)
->addAttributeToSelect(array(‘name’, ‘price’, ‘small_image’, ‘short_description’, ‘description’)) //edit to suit tastes
->setOrder(‘ordered_qty’, ‘desc’); //best sellers on top
So with the help of above collection we can create best seller module for magento. So, finally i think this code helps us to create magento best seller products extension.