Home >How to Display Best Seller Products in Magento 1

How to Display Best Seller Products in Magento 1

How do store owners display best seller products in thousands of items at their online store?

This is a popular question, we have had over recent days from our customers when they need to show the most highlighted products on their Homepage, Category View page, Product page… Unfortunately, there’s no such default feature in Magento 1.

Today we will introduce how to create best seller products by ownself at the article.

Create module

First of all, we need to create module to list best seller products.

Create block file with path app/code/local/Bss/Bestseller/Block/Bestsellers.php:

class Bss_Bestseller_Block_Bestsellers extends Mage_Core_Block_Template
    public function getBestsellerProducts($limit = 10)
        if($limit == "") $limit = 10;
        $storeId = (int) Mage::app()->getStore()->getId();
        $collection = Mage::getResourceModel('catalog/product_collection')
                array('aggregation' => $collection->getResource()->getTable('sales/bestsellers_aggregated_monthly')),
                "e.entity_id = aggregation.product_id AND aggregation.store_id={$storeId}",
                array('SUM(aggregation.qty_ordered) AS sold_quantity')
            ->order('sold_quantity DESC');
        return $collection;

Create config file with path app/code/local/Bss/Bestseller/etc/config.xml:

<?xml version="1.0"?>
      <version> 0.1.0</version> 
            <class> Bss_Bestseller_Block</class> 

Create define file with path app/etc/ modules/Bss_Bestseller.xml:

<?xml version="1.0"?>


After completing module, we need to display the best seller products on the frontend. We can set them at everywhere we want by creating cms page. Go to CMS -> select Pages -> Add New Page.

In the content section of the cms page, we fill in:

{{block type="bestseller/bestsellers" template="catalog/product/bestseller.phtml"}}

For the new Magento version, you need to add the catalog/product_list to the System section. Select Permissions -> Blocks -> Add New Block.

Go to app/code/design/frontend/vendor_name/theme_name/template/catalog/product/ and create bestseller.phtml:

foreach ($_productCollection as $product):            

In which:

  • The function getBestsellerProducts(10) – 10 is limited product.
  • Add template which you want to display (you can use the list product template from catalog/product/list.phtml).

The result

Let’s see the result we just created:

< Previous Post
Next Post >
+ posts