More Flexible Approach for Listing Sale Products in Magento
9 Comments 22nd DEC 2008 | Posted by Branko Ajzele in Magento

One of my recent articles was on the subject of sorting “On Sale” product in Magento. The following is a cleaner and more advanced look at how—with few tricks and smart moves—you can reuse existing Magento code and modify it to suit your needs.
Product can be “on sale” in two ways:
1. when an item has a special price assigned to it on the individual level, or
2. when a special promotion “covers” the item
It is important to remember that you don’t have to set up the special price on each product to get it to be on sale; you can simply create a promotion rule and say something like “Set all the products in Category X to be on sale.”
I provided few screenshots at the bottom of this article to provide a closer look at what I’m talking about. I will not go into too much details here since this is a bit more advanced HOW TO, but here is the process in a nutshell:
First, create a copy of /catalog/product/list.phtml file and name it onsale_list.phtml. Here is my version of onsale_list.phtml file.
Second, “activate” this new file. There are few ways you can do this. Let’s say you wish to assign this onsale_list.phtml on one of our categories, named “On Sale,” for instance.
We then go to Categories > Manage Categories > On Sale… select Custom design and under Custom layout update, place the following:
product_list_toolbar
If you now go to your category On Sale, it should only show products you have assigned to category “On sale” that have a special price set to them.
If you now wish to apply Promotion rules to entire “On sale” category, then you simply assign a rule to one item, and all the items assigned to the same “On sale” category (covered by promotion rules) will be automatically listed in the grid.
Basically, the magic is in one simple IF statement
< ?php if(($_product->special_price !== null) or ($_product->_rule_price !== null)): ?>
for each block that lists products.
Check out the screenshots, they explain a lot.


Hope you find a way to try this out. Feel free to provide some feedback or additional suggestions.
To post code in comments, place your code inside [code] and [/code] tags.


















January 16th, 2009 at 3:20
Hi, thanks for the article. I don’t understand how adding:
product_list_toolbar
to the custom layout calls up the file onsale_list.phtml. Could you please help?
January 24th, 2009 at 2:30
Hi,
Good article but is it possible to have same behavior without create an “On Sale” category, just to put a block in a CMS page which is listing all products with a special price ?
Thanks.
March 29th, 2009 at 23:05
I’ve tried to follow your instructions and am running into the same problem of assigning the new onsale_list.phtml file to the category. I changed the code in the page to see if the page is called, but it still displays the list.phtml file.
Please elaborate. Thanks.
November 26th, 2009 at 18:20
Hi. It is possible to put it just to CMS page like this:
{{block type=”catalog/product_list” name=”specials” as=”specials” template=”templatename.phtml”}}
but how can I handle number of products per page?
When I normally have 30 products pre page and 20 has no special price the result will show only 10 products. The worse thing is that the number of products is on every page different.
December 31st, 2009 at 14:36
@Marting and @Tony:
You have to tell Magento to use your new template, so what you want to place in the Custom Layout field is:
catalog/product/onsale_list.phtml
December 31st, 2009 at 14:37
Oops, the comment system didn’t like my code snippet. 2nd try:
catalog/product/list_sale.phtml
December 31st, 2009 at 14:41
Still no luck. Every line – except the path/to/template.phtml – should be enclosed in xml tags:
reference name=”product_list”
action method=”setTemplate”
template
catalog/product/list_sale.phtml
/template
/action
/reference
December 31st, 2009 at 14:43
PS: @Branko:
Thanks for sharing your knowledge.
It would be very helpful if you indicated which characters/tags are allowed in your comments or how to post code.
June 29th, 2010 at 15:30
didn’t realize you were allowed to access ‘protected’ data members of the product object within template code… i was previously parsing the result of $this->getPriceHtml($_product,true) for instances of class=”price”, “Special Price”, and “As Low As”… $_product->sale_price, $_product->min_price is so much easier!