Display Promotion & Random Products in Magento

Display Promotion & Random Products 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

promotion-and-random-1

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.

promotion-and-random-2

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

promotion-and-random-3

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 …

You made it all the way down here so you must have enjoyed this post! You may also like:

Adding gallery tab to a CMS page Antun Martinovic
, | 5

Adding gallery tab to a CMS page

Implementing javascript minifier Tomislav Nikcevski
, | 5

Implementing javascript minifier

How to set up a CDN (Amazon CloudFront) in Magento Dario Trbovic
Dario Trbovic, | 18

How to set up a CDN (Amazon CloudFront) in Magento

69 comments

  1. excellent post regarding the random products on magento, saved me time and money, thanks again.

  2. 😀 think I’m not getting it done correctly…to see the lines of code, please follow the link, they won’t get displayed here…

  3. Maybe this helps:

    If you are looking for the correct way to change how many columns your products are displayed in “grid view” in Magento, the solution is actually quite simple. Navigate down to your catalog.xml file in your theme under the “app” side of Magento and open that file.

    Then, what I did to make it simple is did a text search for the number of columns displayed, in this particular case, the column count is 4. The actual line of code looks like this:

    4

    Change that line to read:

    2

    Save the file. Then go into your Magento Admin section under “System>Cache Management”, select “Refresh”, then click “Save Cache Settings”.

    Now refresh your Magento catalog page in your browser and you should now see your products in “Grid View” appearing in 2 columns instead of 4, or whatever number you changed the catalog.xml file to.

    September 16th, 2009 | Category: Magento E-Commerce Help
    Source: http://www.imagedia.com/2009/09/how-do-you-change-number-of-product-columns-in-magento/

  4. I am having the same issue as Gareth O Neill, using:

    To display products in grid mode on cms homepage. Getting 3 products per line, want 4. Anyone know?

  5. ….it is not working 🙁

    so, I’ll post it without the brackets

    block type=”catalog/product_new” template=”catalog/product/new.phtml”
    action method=”setProductsCount” 5 /action

  6. Hey!

    Maybe anyone can help me:
    I’m trying to set a product limit for a modified list.phtml in combination with the promotion.php

    I need to call it via xml-layout in the backend. For the new.php I can easily set it via

    5...

    But this is not working for the list.phtml 🙁

    Or do you have another hint for me? I need to show max 6 products from a larger list of promoted products, best randomized on my homepage. and the template forces me to call it via XML, so I can not use the CMS variable line {{…}}.

    thanks in advance!

  7. Best you could change the webpage name title Display Promotion & Random Products in Magento • Inchoo to something more catching for your subject you write. I enjoyed the blog post nevertheless.

  8. okay … lost situations need desperate solutions … last chance: deleted the attribute “promotion” and started all over … and now it’s working again … but i guess noone can explain why how and whatever ?? 🙂

  9. OH SH***!!! So sorry ! *lol* was posting in two support boards and messed the english and the german version of my text *lol*?? okay in english … and again SO SORRY!

    i got a shop in setup now and already used this “promotion-hack” worked fine! and after that i installed a slider module and the promotionsstuff stopped working. After some tries to fix it, i decided to uninstall the slider (before just tried to dactivate) but nothing still happens with that “promotion” thingy 🙁

    Has anyone a guess on what to do or try ? it’s always saing that there are no items to show for this …

    and sorry again for the language mistake xD

  10. Also ich völlig am verzweifeln 🙁 Hatte diesen “Hack” ^^ eingebaut und alles hat funktioniert. Danach dann einen Slider installiert und nichts hat mehr funktioniert. Den Slider daktiviert und inzwischen auch deinstalliert, aber ich bekomme nur noch angezeigt, dass keine Produkte zur Anzeige vorhanden seien. Habe zwischenzeitlich einiges andere versucht, aber ich bekomme die Anzeige nicht mehr hin :-/

    Version: 1.4.1.1

    bin für jeden Tipp, den ich vielleicht übersehen haben könnte ^^

  11. Please tell me where to add the code . I have created that attribute..then later what to do .. i am not getting..am very new to magento

    Thanks

  12. 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”}}

  13. 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.

  14. 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

  15. 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

  16. 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

  17. 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

  18. 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

  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 !!!

  20. 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.

  21. 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?

  22. @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?

  23. 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!!

  24. 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… 😉

  25. 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.

  26. 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.

  27. 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?

  28. This is not working for me despite trying everything in this page.
    Any help would be appreciated..

  29. 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?

  30. 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” />

  31. 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 :

  32. 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?

  33. 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”}}

  34. 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 🙂

  35. 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.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <blockquote cite=""> <code> <del datetime=""> <em> <s> <strike> <strong>. You may use following syntax for source code: <pre><code>$current = "Inchoo";</code></pre>.

Tell us about your project

Drop us a line. We'd love to know more about your project.