Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Page 1 of 9
[ How do I ] Display random products from category on homepage? 
 
Giorgi
Member
 
Total Posts:  53
Joined:  2007-10-21
 

Hello, I’ve read that this code:

{{block type="catalog/product_list" category_id="123"}}

will display products from that category, if you put it in CMS, but how to pull out random products from random categories?

Thank you

 
Magento Community Magento Community
Magento Community
Magento Community
 
JoshBelke
Member
 
Total Posts:  64
Joined:  2008-02-12
NY, NY
 

While this isn’t “random” it will get you a change of products on the homepage.

If you have info on your current home page under CMS collect it all.. save it to a homepage static block.

Make a homepage category under your Root Category, assign the url: home , this will take over your current home page.

Assign the homepage static block with the: products and static block

Apply w/e products you want into the homepage category and you can move around the simple/configurable/grouped products as needed as highlights.

You get the same “effect.”

--------------------------------------

IMO ... having something like:

{{block type="catalog/product_list" category_id="1" category_id="4" random_id="1-100" display_results="{{product_number=’$number’}}" }}
Arg 1) - view type
where: catalog/product_list == list or grid view
Arg 2) - item type
where: category_id == argument of what category to draw items from
where: cateogry_id == a secondary master category to draw items from
or
where: random_id == random call with a range of product id if present to call from
Arg 3) - item amount
where: display_results == how many items to list

Would be nice.
~Josh

 
Magento Community Magento Community
Magento Community
Magento Community
 
Moshe
Magento Team
 
Avatar
Total Posts:  1770
Joined:  2007-08-07
Los Angeles
 

Try this:

{{block type="catalog/product_list_random" num_products="5"}}
 
Magento Community Magento Community
Magento Community
Magento Community
 
PitchOu
Member
 
Total Posts:  39
Joined:  2008-02-04
Villeneuve d'Ascq, France
 

We tried this, it’s ok but 5 products are always displayed, although we set the num_products parameter to 1, 2, or 4.....

 
Magento Community Magento Community
Magento Community
Magento Community
 
Moshe
Magento Team
 
Avatar
Total Posts:  1770
Joined:  2007-08-07
Los Angeles
 

@PitchOu: there’s no 5 hardcoded anywhere, so it’s hard to imagine why this would happen.. what about without num_products parameter at all?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Andrea, Argentina
Sr. Member
 
Total Posts:  164
Joined:  2007-12-05
Buenos Aires, Argentina
 

Hi, I have the same problem. Without num_products parameter, it shows all (for example 8 products that are the whole shopping now), and if I put the parameter, with any number it shows all too.

Thanks
Andrea

 
Magento Community Magento Community
Magento Community
Magento Community
 
Daynos
Sr. Member
 
Avatar
Total Posts:  98
Joined:  2008-02-12
Rennes, Bretagne
 

Need cache update ?

 
Magento Community Magento Community
Magento Community
Magento Community
 
PitchOu
Member
 
Total Posts:  39
Joined:  2008-02-04
Villeneuve d'Ascq, France
 

I tried to refresh the cache but it didn’t solve the problem.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Pablo Lopez
Member
 
Avatar
Total Posts:  51
Joined:  2008-01-17
 

Hi, I have the same problem.
With the type="catalog/product_list_random" seems like the “num_product” parameter does not work.
Also, if I try to filter by category with category_id="someid" , doesn’t seem to filter by that either.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Giorgi
Member
 
Total Posts:  53
Joined:  2007-10-21
 

Yep strange problem with product number… anyone figured that out?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Giorgi
Member
 
Total Posts:  53
Joined:  2007-10-21
 

anything...?

 
Magento Community Magento Community
Magento Community
Magento Community
 
AkyRhO2
Jr. Member
 
Total Posts:  6
Joined:  2008-03-12
Belgium
 

I tried this code too :

{{block type="catalog/product_list_random" num_products="5"}}

The good things are that : first, it effectivly does a random on products. Second : the num_products parameter is correctly sets and passes to the setPage() function. But obviously, this function doesn’t take care of…

If anyone could explain me…

 
Magento Community Magento Community
Magento Community
Magento Community
 
cornernote
Jr. Member
 
Total Posts:  16
Joined:  2008-03-11
 

I tried this code:

{{block type="catalog/product_list_random" num_products="5"}}

It did not display anything.  No products, no error, just the standard home page with no products.  Any tips or suggestions would be appreciated.

 
Magento Community Magento Community
Magento Community
Magento Community
 
cornernote
Jr. Member
 
Total Posts:  16
Joined:  2008-03-11
 

Ok, I am starting to get the hang of this.

This code gives me the home page as per the demo site:

{{block type="catalog/product_list" category_id="1" template="catalog/home.phtml"}}

So, I opened up the home.phtml template and I see it has hard-coded products.  So I created my own theme and copied home.phtml, and modified it so that it was more like list.phtml.

I also changed the type to product_list_random and removed category_id so that I could see random items.

I am still not sure how to limit the items, other than something dodgey in the template like if($i>X).

In any case, this is looking really good.  Can’t wait to see some more documentation and examples.

 
Magento Community Magento Community
Magento Community
Magento Community
 
cornernote
Jr. Member
 
Total Posts:  16
Joined:  2008-03-11
 

Here is the code i hacked up for the home page listing incase anybody cares to try it:

<?$_productCollection=$this->getLoadedProductCollection()?>
<?if
(!$_productCollection->getSize()):?>
<div class="note-msg">
    
<?=$this->__('There are no products matching the selection.')?>
</div>
<?else:?>

<div class="home-spot">
    <
div class="box best-selling">
        <
h3><?=$this->__('Home Page Products')?></h3>
        <
table cellspacing="0">
            
<?$i=0;$j=0; foreach ($_productCollection as $_product): ?>
            <?if 
($i%2==0):?>
            
<tr class="<?=($j++%2==0)?'even':'odd'?>">
            
<?endif?>
                
<td>                                           
                    <
a href="<?=$_product->getProductUrl()?>"><img src="<?=$this->helper('catalog/image')->init($_product, 'small_image')->resize(95, 95);?>" width="95" height="95" alt="<?=$this->htmlEscape($_product->getName())?>"/></a>
                    <
div class="product-description">
                        <
p><a href="<?=$_product->getProductUrl()?>" class="product-name"><?=$this->htmlEscape($_product->getName())?></a></p>
                    </
div>
                </
td>
            
<?if ($i%2!=0):?>
            
</tr>
            
<?endif?>
            <?$i
++?>
            <?php endforeach?>
        
</table>
       </
div>
</
div>

<?endif;?>
 
Magento Community Magento Community
Magento Community
Magento Community
 
Giorgi
Member
 
Total Posts:  53
Joined:  2007-10-21
 

On fresh 1.0 stable install, I am getting this error, on that code:

Fatal errorCall to a member function getId() on a non-object in /home/mycardg/domains/mydomain.ge/public_html/app/code/core/Mage/Catalog/Model/Layer.php on line 80

any help? :(

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top
Page 1 of 9