Display Promotion & Random Products in Magento
35 Comments 25th AUG 2009 | Posted by Ivan Weiler in Magento

There are two unused product list blocks in Magento which can be very useful if you push a few buttons, edit few layouts ..
1. Promotion
Block located in app\code\core\Mage\Catalog\Block\Product\List\Promotion.php
This is basically built in featured product functionality. It reacts to “promotion” attribute which needs to be created, so let’s click
Catalog->Attributes->Manage Attributes->Create New Attribute
Attribute Code: promotion
Scope: Global
Catalog Input Type for Store Owner: Yes/No

Label: Promotion (second tab)
Other params can be left alone, but it’s up to you of course. I also labeled it Promotion just for this article.
Now we need to add created attribute to attribute set, so navigate to
Catalog->Attributes->Manage Attribute Sets
select attribute set you’re using and drag promotion to General group for example.

Now when you’re editing your products, there is new “Promotion” option under General tab.

Products on which you select Yes will be shown on promotion block which can be displayed through layouts with
<block type="catalog/product_list_promotion" name="product_promotion" template="catalog/product/list.phtml"/>
or as cms content with
{{block type='catalog/product_list_promotion' template='catalog/product/list.phtml'}}
This attribute should really be included in default attribute set or in Magento sample data.
2. Random
Block located in app\code\core\Mage\Catalog\Block\Product\List\Random.php
This block loads random product collection from current store.
The fastest way to display it would also be something like
<block type="catalog/product_list_random" name="product_random" template="catalog/product/list.phtml"/>
since it also extends product_list block, however, since it is random product listing, that toolbar has no purpose here, so create phtml that will suit your shop needs, based on catalog/product/list.phtml. For example, i’m using similar Random block to display random products in sidebar.
So long, take care, i’m off …
To post code in comments, place your code inside [code] and [/code] tags.


















August 25th, 2009 at 13:53
Hi, nice tutorial, but it doesn’t print anything in my homepage :\ I make everything related above and paste {{block type=’catalog/product_list_promotion’ template=’catalog/product/list.phtml’ }} on my home with the CMS manager.
August 25th, 2009 at 16:26
Hi.
Did all of the above and got something showing on home page, but i shows all of my products not the promo products. What can i be doing wrong?
August 25th, 2009 at 18:48
It seems that WordPress changed single quotes in that cms directive, so please delete them and type them manually, or try to copy paste again from this post cause i think i fixed the problem.
Also note that you need to edit few products and set “Promotion” option under General tab to “Yes”.
Thank you both for reporting
August 25th, 2009 at 19:03
Now it works, i changed
{{block type=’catalog/product_list_promotion’ template=’catalog/product/list.phtml’}}
for
{{block type=”catalog/product_list_promotion” template=”catalog/product/list.phtml”}}
August 26th, 2009 at 8:45
How would you make it so that only promotions from a specific category show up?
September 2nd, 2009 at 15:05
Man… congrats… nice tuto!
September 8th, 2009 at 12:50
Hi,
I did everything mentioned for adding the promotion on the Home CMS page (including trying what’s on the other comments), yet it displays all the products on the catalog.
I have two products that are marked as promotion=yes, and have the following at the home CMS page:
{{block type=”catalog/product_list_promotion” template=”catalog/product/list.phtml”}}
Can anybody help?
September 9th, 2009 at 7:47
Hi,
I had some problems with the code (the block appears 2 times on the page : in my content and after all other htmls).
My code which resolves the problem :
September 9th, 2009 at 11:09
Thanks for helping!
But you haven’t posted your code..
September 9th, 2009 at 12:58
Here it is :
<block type=”catalog/product_list_promotion” template=”catalog/product/list.phtml” name=”home.catalog.product.promo” alias=”product_promo” after=”product_new” />
September 9th, 2009 at 13:56
Thanks
But it still displays all the products the catalog instead those that have the attribute “promotion” set to “Yes”.
Is there another solution to the problem?
September 10th, 2009 at 22:06
Works great, thanks !! Who knew it was built in
September 11th, 2009 at 19:43
This is not working for me despite trying everything in this page.
Any help would be appreciated..
September 14th, 2009 at 14:03
Hi,
I can’t get the promotion thing to work.
I’ve setup the attribute, assign some products a “yes” value to the attribute, but the block shows all products in my catalog.
Any idea why this happens?
September 18th, 2009 at 11:22
Good job that’s greate
September 28th, 2009 at 17:10
THANK YOU!! This tutorial saved my life, and me about $90 on that extension. I just needed something really simple, and with Magento being the clusterf**k that it is of code, this really saved my life as well as some other tutorials.
October 2nd, 2009 at 12:55
It looks like that some people can’t get this working, including me.
We all put the code as described, set some products with attribute promotion = “yes”, and all the products in the catalog are displayed.
Any help will be appreciated, this is really annoying.
October 19th, 2009 at 23:28
This is to all of you who try to make Promotion.php work, and get the entire catalog displayed (instead of those products which have the attribute promotion set to “yes”):
After a little research, it turns out that the builtin Promotion.php file doesn’t work when flat category/product is turned on. I think the reason is the fact that Promotion.php uses an attribute named “promotion” that is not copied to the flat tables (e.g. not in the default list of attributes that Magento uses..)
I have setup the promotion attribute, assigned a couple of products to it, and all I got was a display of my entire catalog. Only when I disabled flat catalog/product it started working…
October 24th, 2009 at 13:41
Hi Ivan, thanks for sharing your knowledge with us!
I made a sidebar to show random products on my site as per your instruction above, it works great but one problem there are 9 items show in the random sidebar i think that’s my default setting for products list page, how can i just show 2 items there?
You can see them here : http://www.gowaa.com, thank you!!
October 26th, 2009 at 23:02
@He Hong Jun : You can simply add the following param to your code:
limit=all or limit=20 or whatever
Example:
{{block type=”catalog/product_list_promotion” limit=”all” template=”catalog/product/list.phtml”}}
—
My issue is that I am trying to display this code on a NON-magento page (outside of the store), and would like to set the limit to ALL.
I have the following code:
—
require_once ‘app/Mage.php’;
umask(0);
Mage::app(‘default’);
// get layout object
$layout = Mage::getSingleton(‘core/layout’);
$block = $layout->createBlock(‘catalog/product_list_promotion’);
$block->setTemplate(‘catalog/product/featured.phtml’);
echo $block->toHtml();
—
How can I set the limit like I do in a CMS block by using PHP code like above?
It currently only pulls the default 9 products. I don’t want to change this default setting elsewhere which affects the rest of my site. Since I determined in the block that simply setting: limit=”all” works, how can I set that same thru PHP?
October 29th, 2009 at 11:52
Hi Ivan, I have tried random products code. But it doesn’t works for me.I even off the caches in admin. I put it in Home page content in admin. should I anything work on my list.phtml file?
October 29th, 2009 at 12:21
Hi Ivan, now it works for me in home page. But i want to add it in right side bar. Pls help me how to do this.
November 7th, 2009 at 16:19
Hello ! Great tutorial !
I have a question, how can i change the number of products per column or per line. I would like to diplay 4 products in 1 line ?
Thank you for your help !!!
November 13th, 2009 at 18:26
Hi!
I try everything but not a sigle product appera on my homepage.
Please Help me!
November 26th, 2009 at 16:22
Virgil, Instead of the above codes, you should enter following code in the content of your CMS page:
{{block type=”catalog/product_list_promotion” name=”product_promotion” template=”catalog/product/list.phtml”}}
It works.
Hamed
December 9th, 2009 at 16:52
I want to display promotion products into home page magento. How it to do?
December 9th, 2009 at 18:07
I try everything but not a sigle product appera on my homepage to! I try paste {{block type=”catalog/product_list_promotion” name=”product_promotion” template=”catalog/product/list.phtml”}} in my page content, but still not a sigle product appera on my homepage! I tried paste in layout/catalog.xml – it works in catalog! But when i pasted this code into layout/page.xml – it didn’t work
December 10th, 2009 at 11:12
Hello
Thank you for great tutorial but I have one question, how to change display order?
December 14th, 2009 at 18:14
- IT WORKS!!! Thanks!
January 30th, 2010 at 13:22
Hi everybody
I have a problem limiting the output of my promotions.
I showing my promotions in the right sidebar by calling
in catalog.xml.
But I got allways listet all artikels marked as “promotion=yes”
limit=”4″ doesn´t work.
Any hints to get it working??
Thanks from germany and also for this great tutorial
Reagrds Frank Hamm
February 1st, 2010 at 15:57
Still my problem
I build in the promotion funktion in my right sidebar, where I want to show max. 4 Produkts.
But I have a problem limiting the output of my promotions.
I showing my promotions in the right sidebar by calling
in catalog.xml.
Remark – promotionlist.phtml ist a customized version of list.phtml
But I got allways listet all artikels marked as “promotion=yes”
limit=”4? doesn´t work.
Any hints to get it working??
I think the problem seems to be the standard number of produkts normaly shown in list.phtml.
Can you please help me. I am testing for 3 days but without success.
Kind regards from Germany
February 1st, 2010 at 16:31
I have done the “similar” effect with another way..
I created a category named “Promotion” and disabled it, associated a few products to it and in the page block added:
{{block type=”catalog/product_list” category_id=”51″ template=”catalog/product/list.phtml”}}
Note: the number 51 is the ID of the category
February 24th, 2010 at 0:38
In response to the flat catalog issue when the entire catalog is displayed instead of just items set to Promotion. When you set up the “promotion” attribute, set the “Used in product listing” to yes. Then refresh the flat catalog and you’ll be good to go.
May 19th, 2010 at 14:26
Guys, I have 3 products showing up per line on my homepage and I want to be able to have 4 products per line. There is something that can be added in here?
{{block type=”catalog/product_list_promotion” template=”catalog/product/list.phtml”}}
June 6th, 2010 at 12:45
gr8, i was looking for something like this