Creating Custom Sort-By in Magento

How to add Custom Sorting Option in Magento :

Often there is a need to make a custom Sorting Options in Magento. Though Magento provides a great support for adding sorting options of our choice but at times we need to do it ourself.

Suppose you want to sort product by Price say High-To-Low and Low-To-High. This is not supported by Magento but you can easily do it using some custom coding.

Following are the steps that requires to be taken

1)Goto  app/design/frontend/YOURTHEME/template/catalog/product/list/toolbar.phtml
2)You will find the default Magento <select> </select> option over there.
3)You can either comment out that section and create a new one or just add your option in there to make it working too.
4) Now suppose you want to add an option for sorting by price from High-to-low and Low-To-High you can write the code for it as follows

<option value=”<?php echo $this->getOrderUrl(‘price’, ‘asc’) ?>”<?php if($this->isOrderCurrent(‘price’) && $this->getCurrentDirection() == ‘asc’): ?> selected=”selected”<?php endif; ?>>Price : Low To High</option>
<option value=”<?php echo $this->getOrderUrl(‘price’, ‘desc’) ?>”<?php if($this->isOrderCurrent(‘price’) && $this->getCurrentDirection() == ‘desc’): ?> selected=”selected”<?php endif; ?>>Price : High To Low</option>

Now, what we are doing here is we are getting the attribute price and sorting it in ascending in descending order. Sorting it in ascending order will sort the product with Low-High Price whereas sorting in descending will sort it from High-Low price.

Similarly you can do such custom sorting for many options. Please provide your feedback and suggestion on this in comment section

Advertisements

5 thoughts on “Creating Custom Sort-By in Magento

  1. Pingback: Magento : Sort By Price – Low to High and High to Low Change default Sort Order | Garik'S Blog.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s