How can I show 12 random products in my Magento 1.9.0.1 homepage every time it is reloaded?
-
4You don't want to do this. Your customers want a solid view on the page, so when they show their friends/partner/whoever the page, the product they want to show is still there. So I recommend to not have "total randomness"!– Fabian BlechschmidtOct 31, 2014 at 17:17
-
1Good point, thank you. I don't want show only random products.– KaMZaTaOct 31, 2014 at 17:57
2 Answers
I'll write some psuedocode for you:
While(size($productarray[] <= 12)){
$randomId=generaterandomid();
if($randomId->getproduct()){
$productarray[]=$this->load($randomId);
}
}
...
foreach($productarray[] as $product){
...
}
This will generate random ids (you can constrain it however you want) that will be used to populate your product array. Then a simple foreach will put them all onto the page however you want.
Add in home page
{{block type="catalog/product_list_random" template="catalog/product/list.phtml" num_products="12"}}
control columns add column_count="number"
{{block type="catalog/product_list_random" template="catalog/product/list.phtml" column_count="4" num_products="12"}}
-
Thank you so for your reply. This works partially because it shows only one product and hides (I don't understand why) the rest of the content block (like text and images).– KaMZaTaOct 31, 2014 at 17:52