My Cart

You have no items in your shopping cart. Buy products from our webshop

Display special priced products on your Magento homepage

In my previous blogpost, I covered how you can create a €1 Bargain page in Magento. To do so, we learned how to create a custom block on wich we applied price as a filter on the product collection and how to create a XML Layout update for a random CMS page. The main advantage of this method for creating custom catalog pages in Magento is that the toolbar, pagination, navigation layered, caches & indexes all continue to function correctly. In this post, I want to show you how you can use this same method to display all products with a special price on the frontpage of your Magento webshop

Step one
Open your homepage CMS page and click on the design tab. Paste the following:

Because my frontpage has 3 columns, you can see I have set the amount of columns in the grid view to 3 using the action method "addColumnCountLayoutDepend".  I have set 2 as the categoryId, because this the id of my root category. Be sure that you use the correct id of the category you want to display and be sure that it's set to be an Anchor (or it won't display any products in the first place).

Step two
In the XML update above, you can see we call catalog/product_specials as the block type. What we are going to do now, is creating a custom block where we actually apply our custom pricefilters. To do so, make a copy of /app/code/core/Mage/Catalog/Block/Product/List.php, create the directory /app/code/local/Mage/Catalog/Block/Product and place it there. Rename this file to Specials.php

Step three
Edit Specials.php and change the class definition (the first line of actual code, line number 35):

to

Scroll to around line 89, and you'll find the following definition

After this definition, we can do some magic. Place the following code just below it:

As you can see, we just define today's date and tomorrow's date and then apply the special_from_date and special_to_date as attribute's to filter. Because we can imagine you will not always set a 'to' date when giving your products a special price, we use Zend_DB_Expr to say it should also add products to the product collection that don't have a 'to' date configured. If you do wan't to display only the products that have a value for both the from and to date, use this code instead:

How to limit the amount of products to display

Imagine you want to display not ALL products in a certain category, but want to limit the amount to let's say 5 (randoms if you want). For example: you want to create a featured products block in Magento. To do so, you can use this exact same method (copy the List.php, name it Featured.php' etc. etc) and you will only have to make some small changes to your XML:

Now, pay attention to what I'm doing here, because this example won't just work when you copy paste it. First, you'll see that I indeed call my custom block catalog/product_featured and use a custom template to display the results: catalog/product/featured.phtml. You can use list.phtml here if you want to do a quick test. Now on line 4, you'll see that I give the toolbar a custom name: product_featured_toolbar and that I use an action method on the next line to set the addPageLimit for listview to limit the results to 5 products. If you want to use a custom gridview, you can change the mode to grid. Last but not least, on line 7 I use the action method setToolbarBlockName to identify the custom toolbar so that my addPagerLimit will only affect the toolbar from this specific block. If you don't use a custom name for your toolbar, you'll see that all other listviews on the page will be affected and in most cases you probably do not want that.

Erwin Otten

Erwin Otten is a Web Designer / Graphic Designer from Oude Wetering (The Netherlands) and co-founder of Hachmang & Otten. With an education in communication & multimedia design, he is passionate about web design at all levels including (information) architecture, interaction, code, and graphic design. Contact Erwin Otten

Comments
  • Derek Johnson

    (nov 17)
    Reply to this comment

    Works well, thank you. I needed to correct a typo in the XML. It should say type=“catalog/product_specials” not type=“catalog/product_bargains”

  • Admin

    (nov 20)
    Reply to this comment

    Thanks, fixed it!

  • Kay Beissert

    (dec 15)
    Reply to this comment

    Thank you verry much. This works perfect. Is possible to disply the filter-block on the left side to filter the displayed products?

    Thanks

  • ktsixit

    (mar 02)
    Reply to this comment

    I did exactly what you suggested but no products appear.
    I did’t add the last part (“How to limit the amount of products to display”) but I guess that it would be enough.

    • Erwin Otten

      (mar 03)
      Reply to this comment

      That is correct, you don’t have to add the addPagerLimit in to see products showing up. Have you used the correct categoryId of your parent category? Have you actually gave some products a special date?

      • Conor

        (mei 06)
        Reply to this comment

        I have the same problem and I can not get them to show on the home page at all, please help. I am running 1.4.2.0

  • Katapofatico

    (mei 25)
    Reply to this comment

    Thaks for your contribution, Erwin. And… what about catalog rules special priced products? Have you any idea on how to list them, or even include them in this module?
    Thanks again!

  • izdelava spletnih strani

    (jun 28)
    Reply to this comment

    TNX for this great article!

  • Tjerco

    (jul 29)
    Reply to this comment

    Hi Guys,

    This working fine for me (release 1.5). I do have a small question? In which statement of the new specials.php is the number of products given back? I have a dubble statement on the frontend now.

    Thanks,
    Tjerco

    • Paul Hachmang

      (jul 30)
      Reply to this comment

      Could you please provide a screenshot?

    • Paul Hachmang

      (aug 01)
      Reply to this comment

      I received the following screenshot: http://cl.ly/8wpL

      You could try and remove from the XML

      < block type=“catalog/product_list_toolbar” name=“product_list_toolbar” template=“catalog/product/list/toolbar.phtml” >
        < block type=“page/html_pager” name=“product_list_toolbar_pager” >       
      </ block >

      If that doesn’t work, look in your list.phtml template.

  • Francesco

    (nov 17)
    Reply to this comment

    Hello,
    this is a great tutorial, thanks! I have used it to create a static “Promotions” page.
    For the home page, I would rather like to diplay the two last products with a special price using a custom block.
    But it is not clear to me where the XML code must be inserted…can you please explain me the last part of your tutorial?

    Thanks a lot in advance,
    Francesco

  • amadex

    (dec 31)
    Reply to this comment

    Very, very good tutorial!!!! One doubt still: layered navigation keeps “considering” all the products of the category and not only the “bargain” ones. Any help?

  • Marko

    (mei 06)
    Reply to this comment

    Thanks. This code is working perfect!

Comment and contribute