B-219 Sec-55 Noida, India
+918010221733

Best Seller Products in Magento

irst of All before writting about the best seller products in magento. Here is the file you can use to retrieve best seller products in magento. anywhere in your magento site. you jut need to place this file at correct location and use as your requirements. Either on home page or in any catalog page or at any other location as per your need. So here is the file contain code of showing best-seller products in magento.

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.

And I found some technical write-ups related to magento. Like the following Model Named Mage Reports model 

(Mage_Reports_Model_Mysql4_Product_Collection)

http://docs.magentocommerce.com/Mage_Reports/Mage_Reports_Model_Mysql4_Product_Collection.html#sec-methods

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’))
// or

addAttributeToSelect(‘*’)

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

setStoreId($storeId)
addStoreFilter($storeId) // add this to retrieve products collection related to specific store

setOrder(‘ordered_qty’, ‘desc’);

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’)

->addOrderedQty()

//->addAttributeToSelect(‘*’)

->addAttributeToSelect(array(‘name’, ‘price’, ‘small_image’, ‘short_description’, ‘description’)) //edit to suit tastes

->setStoreId($storeId)

->addStoreFilter($storeId)

->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.

(Visited 105 times, 1 visits today)

Leave a reply

You must be logged in to post a comment.