0

How i can add a new option in the drop down product listing in category layout? I saw a lot of threads which customize template\catalog\product\list.phtml But i think adding a new dropdown option is better and the dropdown will still be valuable...

  • what mean by dropdown? ] – Amit Bera Sep 24 '15 at 16:51
  • "Sort by: price / position / name" sorry my theme has a dropdown there... I dont remember how it looks in default theme :P – Alexandros Sep 25 '15 at 6:27
1

The following simple but unperformant solution should work

In your layout, add the custom order like this:

<reference name="product_list_toolbar">
    <action method="addOrderToAvailableOrders" translate="label">
        <code>RAND()</code>
        <label>Random</label>
    </action>
</reference>

(in catalog_category_default, catalog_category_layered or in the custom layout update configuration for a single category)

The problem with this is, that the resulting ORDER BY RAND() query is very slow, especially for big categories. A performant solution would need custom preparation of the collection and is not integrated so easily.

You can read more about random product collection performance on my blog: http://www.schmengler-se.de/en/2015/09/show-random-products-in-magento-you-are-doing-it-wrong/

A different approach

You could add a column "random_sort" to the product index tables and use a cronjob to update it with new random numbers regularly (e.g. every few minutes or every hour). Then you can use the XML snippet from above and replace RAND() with random_sort. As a positive side effect, even pagination in the random order will work, without getting duplicates. At least until the random numbers are regenerated.

0

@Alexandros some help to ans

you can get the used category from:

$category = Mage::registry('category') or Mage::registry('current_category')

To do so, you want to implement an observer listening on catalog_block_product_list_collection and instead of joining and filtering for stock options, you add a category filter: addCategoryFilter based on the registry entry.

  • You are talking like chinese to me :) – Alexandros Sep 25 '15 at 6:28
  • NO Sir i speak only English – Ashvin Monpara Sep 25 '15 at 6:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.