Magento get best selling products Collection


Magento get best selling products Collection : Here simple and quick way to get the best selling products in magento. Mage::getResourceModel(‘reports/product_collection’) is used to get the most ordered items on the basis of ordered quantities. In this tutorial we are going to create simple collection which will give the most ordered ie. best selling products.


Magento get best selling products Collection

Here is syntax to get the collection of best selling products-

Magento get best selling products Collection

$storeId    = Mage::app()->getStore()->getId();

$productsCollection = Mage::getResourceModel('reports/product_collection')
            ->addOrderedQty()
            ->setStoreId($storeId)
            ->addStoreFilter($storeId)
            ->setOrder('ordered_qty', 'desc')//This tells the most ordered products
			->setPageSize(50); 

Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($productsCollection);
Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($productsCollection);

foreach($productsCollection as $product){
        $productIds[] = $product->getId();
}

The above example will give you the top 50 most selling products in magento. You can add your own filter and page size to get the collection of the product. Hope this will help you!


Advertisements

Add Comment

📖 Read More