Display Promotion & Random Products in Magento

35 Comments 25th AUG 2009 | Posted by Ivan Weiler 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 …

If you like what you read, please share it.

  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Yahoo! Bookmarks
  • Reddit
  • Technorati
  • Twitter
  • StumbleUpon
  • LinkedIn
  • Netvibes
  • NewsVine
  • Sphinn
  • Tumblr
  • Posterous

To post code in comments, place your code inside [code] and [/code] tags.

There are 35 comments (Add Yours +)

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

  • 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?

  • 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 :)

  • 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”}}

  • How would you make it so that only promotions from a specific category show up?

  • Man… congrats… nice tuto!

  • 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?

  • 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 :

  • Thanks for helping!
    But you haven’t posted your code..

  • 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” />

  • 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?

  • Works great, thanks !! Who knew it was built in :)

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

  • 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?

  • Good job that’s greate

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

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

  • 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… ;)

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

  • @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?

  • 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?

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

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

  • Hi!
    I try everything but not a sigle product appera on my homepage.
    Please Help me!

  • 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

  • I want to display promotion products into home page magento. How it to do?

  • 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

  • Hello
    Thank you for great tutorial but I have one question, how to change display order?

  • - IT WORKS!!! Thanks!

  • Frank Hamm Says

    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

  • Frank Hamm Says

    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

  • 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

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

  • 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”}}

  • gr8, i was looking for something like this

Leave a Comment

Please wrap all source codes with [code][/code] tags.
Magento Design and Development | Magento SEO | iPhone Application Development Web Application Development with ZEND | WordPress Ecommerce | WordPress development
Sitemap

Inchoo - webappsolutions | 2009