InMotion Hosting Support Center

 The more products you have on your Magento store, the better ways to ease the process making decision your shop should offer. One of the steps to perfection is to provide customers with options to sort products on different parameters (not only item attributes).

 Apart from sorting by price or discount, you can offer another popular option, which is showing bestseller products on any page (say, Home page or Category View page).

Why do you need to display bestsellers?

 

As it was previously said, sorting by bestsellers simplifies decision making. Basically, bestsellers are peoples’ choice: it’s the best combination of quality and price, and we all know people vote with their money. If a customer is unsure about the exact model of the item, he can browse through bestselling items and narrow the circle of choice.

This is all about trust; customers are more likely to believe their fellows rather than shop advice. Build and use this connection between customers to eventually give them what they want.

How to show bestselling products in Magento

 

1.       You need to create a new file for the future block.

Here’s the name of the new file and the path for it:

Magento_root/app/code/local/Mage/Catalog/Block/Product/Bestseller.php

  The aim of Bestseller.php is to return bestsellers product collection.

 You need to place the following code into this file:

 <?php

 /**

 * Catalog Product Bestseller Block

 *

 * @author Amasty Team

 */

 class Mage_Catalog_Block_Product_Bestseller extends Mage_Catalog_Block_Product_Abstract

 {

     public function getCollection()

     {

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

         $collection = Mage::getResourceModel('reports/product_collection')

             ->addOrderedQty()

             ->addAttributeToSelect('*')

             ->addAttributeToSelect(array('name', 'price', 'small_image'))

             ->setStoreId($storeId)

             ->addStoreFilter($storeId)

             ->setOrder('ordered_qty', 'desc');

         Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);

         Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($collection);

         $collection->setPage(1, $this->getLimit());

         return $collection;

     }

 }

 

          2.       Now you have the php file that returns bestsellers, the next step is to create a template file for this new block.

 Here’s the path for the template file:

 Magento_root/app/design/frontend/base/default/template/catalog/product/bestseller.phtml

  And that’s what you need to place inside bestseller.phtml:

 <?php

 /**

 * Bestseller Products block template

 *

 * @see Mage_Catalog_Block_Product_Bestseller

 */

 ?>

 <div class="block block-list block-viewed">

     <div class="block-title">

         <strong><span><?php echo $this->__($this->getHeader()) ?></span></strong>

     </div>

     <div class="block-content">

         <?php $products = $this->getCollection(); ?>

         <?php if (0 < $products->getSize()) { ?>

             <table class="bestseller-table">

                 <tr>

                     <?php foreach ($products as $p) { ?>

                         <td style="padding: 15px 15px 0px 15px;">

                             <a href="/support/<?php echo $p->getProductUrl() ?>" title="<?php echo $this->htmlEscape($p->getName()) ?>" class="product-image">

                                 <img src="/support/<?php echo $this->helper('catalog/image')->init($p, 'small_image')->resize(125) ?>" width="125" height="125" alt="<?php echo $this->htmlEscape($p->getName()) ?>" />

                             </a>

                             <h3 class="product-name">

                                 <a href="/support/<?php echo $p->getProductUrl() ?>" title="<?php echo $this->htmlEscape($p->getName())?>">

                                     <?php echo $this->htmlEscape($p->getName()) ?>

                                 </a>

                             </h3>

                             <?php echo $this->getPriceHtml($p, true) ?>

                         </td>

                     <?php } ?>

                 </tr>

                 <tr>

                     <?php foreach ($products as $p) { ?>

                     <td style="padding: 0px 15px 15px;">

                         <?php if($p->isSaleable()): ?>

                             <button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($p) ?>')">

                                 <span><span><?php echo $this->__('Add to Cart') ?></span></span>

                             </button>

                         <?php else: ?>

                             <p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>

                         <?php endif; ?>

                     </td>

                     <?php } ?>

                 </tr>

             </table>

        <?php } ?>

    </div>

</div>

 Important note: this template is an example, and to make bestseller products list look exactly like your normal website pages, use list.phtml from the theme you’ve installed on your Magento shop.

           3.       Almost done! To call the created and designed block, follow this path:

 Backend > CMS > Pages > Edit Page 'Home page'

 Simple as is, add these two lines of code to make it work:

{{block type="catalog/product_bestseller" template="catalog/product/bestseller.phtml" header="Bestsellers" limit=4}}

 Should you decide to add the block via layout update, make use of the following code:

<reference name="content">

        <block type="catalog/product_bestseller" name="bestseller" template="catalog/product/bestseller.phtml" before="-">

            <action method="setLimit"><limit>3</limit></action>

            <action method="setHeader"><header>Best Sellers</header></action>   

        </block>

</reference>

 And add it here if you want to update, say, the Category View page with the bestsellers block:

 Backend > Catalog > Manage Categories > Click needed category in the category tree > `Custom Design` horizontal tab > `Custom Layout Update` field

 

Utilize the header and the limit variables to get the needed result.

 Voila, now you can put a bestsellers block on any page you like. If you need sorting by more parameters, such as Most Viewed, Top Rated, Number of Reviews, feel free to have a look at Amasty Improved Sorting extension, which adds to customers experience and helps them find products according to their needs.

Support Center Login

Our Login page has moved, Click the button below to be taken to the login page.

Social Media Login

   
Social Login Joomla

Need more Help?

Search

Ask the Community!

Get help with your questions from our community of like-minded hosting users and InMotion Hosting Staff.

Current Customers

Chat: Click to Chat Now E-mail: support@InMotionHosting.com
Call: 888-321-HOST (4678) Ticket: Submit a Support Ticket

Not a Customer?

Get web hosting from a company that is here to help. Sign up today!