0

hello friend i want to set sort by options, instead of “Position” please make this say “Best Selling” in product page of magento how this is possible ? please guide me

2
  • do you mean on a search results page? have you tried anything currently? Oct 4, 2013 at 7:40
  • no in product list page we have option in magento toolbar sort by "position,name and price" so now i want to change position to best selling and i am try this below code <?php if ($_order=="Position" ) {?> <?php $_order ="Best Selling" ?> <?php }?> Oct 4, 2013 at 7:43

3 Answers 3

0

The array containing the options for sorting by are built in the class Mage_Catalog_Model_Config

public function getAttributeUsedForSortByArray()
{
    $options = array(
        'position'  => Mage::helper('catalog')->__('Position')
    );
    foreach ($this->getAttributesUsedForSortBy() as $attribute) {
        /* @var $attribute Mage_Eav_Model_Entity_Attribute_Abstract */
        $options[$attribute->getAttributeCode()] = $attribute->getStoreLabel();
    }

    return $options;
}

You could rewrite this class with your own and then override this function and change the text assigned to the 'position' section of the array.

Another option would be to use the setAvailableOrders on the class Mage_Catalog_Block_Product_List_Toolbar and change the array at this point.

If it is just the text that you are wanting to change then maybe the second option would be the easiest. You can then get the available orders, change the text in the array and then set them again.

6

If all you need to do is change some text and not the behaviour then the simplest option is to use translation.

In your theme create a locale/en_US folder, or whichever language you are using, and in that create a translate.csv. For example, if it's the theme default/default then create app/design/frontend/default/default/locale/en_US/translate.csv. Enter the following into it:

"Position","Best Selling"

Clear the cache after saving and you should see the change.

1
  • This is the least obtrusive method.
    – thdoan
    Nov 2, 2016 at 10:05
0

Expanding on David Manners's answer, here is a low-impact example of how to override the method in a subclass of Mage_Catalog_Model_Config:

public function getAttributeUsedForSortByArray()
{
    $options = parent::getAttributeUsedForSortByArray();
    $options['position'] = 'My New Label';
    return $options;
}
2
  • The OP would like to rename the option not remove it totally I believe.
    – AreDubya
    Aug 19, 2015 at 18:04
  • That is an excellent point. :-) I will update my answer. (I wanted to simply remove it, so that's what I had written originally, forgetting OP question.) Aug 19, 2015 at 21:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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