Well, probably (I certainly have).
A typical requirement is to show random products on the home page, random products of a category on the category page, or similar. Magento offers a simple block that can show a specified number of random products, Mage_Catalog_Block_Product_List_Random. To add filtering, like by category, you still need to write your own block, but it could easily be extended.
This is the CMS code:
{{block type="catalog/product_list_random" num_products="4"}}
But don’t get too excited. This block type will make your site slow, you should not use it. The problem is in this line:
$collection->getSelect()->order('rand()');
I’ve been recently advocating against using ORDER BY RAND()
to select random products from a Magento database. 1 Generally, this method is discouraged because of its performance issues.
Continue reading “Show random products in Magento: You are doing it wrong”
Notes:
- For example in this Magento StackExchange post: Four Random Products on Homepage ↩