Magento: How To Remove The "Position" Sort Option

Magento Icon

I had a client ask me today to remove the “Position” option from the toolbar on the category product listing. I realized that there are probably a lot of people that don’t ever utilize position, and therefore it is basically useless and should be removed so it doesn’t cause any confusion for the people browsing the store.

Unfortunately, this is not a listed attribute that you can easily turn on or off as far as sorting goes. So, we have to do it the harder way and dive into the code.

There may be a “better” way to do this, I’m not sure, but this is super easy and it works. All you have to do is edit the file /app/design/frontend/yourpackage/yourtheme/template/catalog/product/list/toolbar.phtml. Towards the bottom, you’ll find the sort by code that outputs a select element. It looks like this:

<?php echo $this->__('Sort by') ?> <select onchange="setLocation(this.value)">
<?php foreach($this->getAvailableOrders() as $_key=>$_order): ?>
    <option value="<?php echo $this->getOrderUrl($_key, 'asc') ?>"<?php if($this->isOrderCurrent($_key)): ?> selected="selected"<?php endif; ?>>
        <?php echo $_order ?>
    </option>
<?php endforeach; ?>
</select>

Change that to this (just adds an if statement):

<?php echo $this->__('Sort by') ?> <select onchange="setLocation(this.value)">
<?php foreach($this->getAvailableOrders() as $_key=>$_order): ?>
    <?php if ($_order != 'Position') : // Remove "Position" from the sort option list ?>
        <option value="<?php echo $this->getOrderUrl($_key, 'asc') ?>"<?php if($this->isOrderCurrent($_key)): ?> selected="selected"<?php endif; ?>>
            <?php echo $_order ?>
        </option>
    <?php endif; // End for removing "Position" sort option ?>
<?php endforeach; ?>
</select>

And that all it takes. If anyone knows of a better/easier way to do it, please let me know.

This entry was posted in Magento, PHP. Bookmark the permalink.

26 Responses to Magento: How To Remove The "Position" Sort Option

  1. Andy says:

    Thank you . This was a big help. I have a quick question. Is there a way to change to sort order from asc to desc for just one category?

  2. Mrnl says:

    I am working on a local host to test if i want to start a shop and i can design it. I have a question for U.

    If u make attributes for products they come in additional information, now i have implemented a video and made a new tab for it, but the video keeps showing up in additional also and i do not want that. Do you know how i can fix it.

    thanks.

    • Josh Pratt says:

      Mrnl,

      The reason it is showing up in the Additional Information is most likely because for that attribute you have “Yes” selected for the “Visible on Product View Page on Front-end” option. You need to turn that to “No”.

  3. Mrnl says:

    Hi Josh Pratt,

    Just looking at your site again.
    And saw that you answered my question. tried it and it works.
    Thanks very much.
    That a simple yes or no can make so much difference.

    Maybe an idea for you , when you or someone else answers a comment that the people who left a comment get an e-mail.

  4. toniyecla says:

    in 1.4, you can try to comment this in app/code/core/Mage/Catalog/Model/Config.php:

    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;
    }

    • Josh Pratt says:

      I do not suggest doing the above (DO NOT EDIT CORE CODE).

      At a bare minimum, move the above mentioned file to app/code/local/Mage/Catalog/Model/Config.php and then make the edit.

  5. Rich says:

    Is there a way to just modify the way the option ‘Position’ sorts? That is the only one that I want to sort desc. All the rest I want to sort asc.

    • Josh Pratt says:

      Rich – I know there is a way to do it, I just don’t remember off the top of my head… With a little searching around, you should be able to find it.

  6. Paeddl says:

    It is better to use the array index for this issue, because the array value contains the localization. Use this code instead:

  7. Chris says:

    This worked perfectly – thanks for being such a great resource!

  8. Pingback: Wöchentliche Linktipps | User Agent - Websites, Online-Marketing, Berlin

  9. Istvan Nonn says:

    Hi,
    I tried and it doesn’t work, probably because I have 1.4.1.1

    The solution is this line in magento 1.4.1.1 :
    removeOrderFromAvailableOrders('position'); ?>
    and you need to insert before:
    getAvailableOrders() as $_key=>$_order): ?>

    I think with this solution you can remove name and price as well or other attribute where you defined sortable.

    • Istvan Nonn says:

      $this->removeOrderFromAvailableOrders(‘position’);
      and you need to insert before:
      foreach($this->getAvailableOrders() as $_key=>$_order):

  10. The best way to remove “Position” from Sort-By-List is the following:

    Create a new PHP class in app/code/local/$MyCompany/Catalog/Model/Config.php which extends Mage_Catalog_Model_Config and overwrite the Method “getAttributeUsedForSortByArray()”.

    If this is done, you extend your module’s config xml file with:

    MyCompany_Catalog_Model_Config

    This is not the easiest way, but the cleanest ;)

  11. Oh, the xml for the config has been removed from my post. Here is it again, but replaced “” with “/” and “\”

    /global\
    /models\
    /catalog\
    /rewrite\
    /config\MyCompany_Catalog_Model_Config//config\
    //rewrite\
    //catalog\
    //models\
    //global\

  12. Pingback: Removing Default Catalog Sort Options in Magento | Spenser Baldwin

  13. Harsh says:

    Thanks dude , ;-)

  14. jimboboy says:

    you can also select only the attribtues you want to use in the sort by dropdown menu, in the catalog > manage categories > display settings… just uncheck the “Use All Available Attributes” checkbox and select only the attributes you want to use

    • eramos says:

      Thanks jimboboy, your solution by doing the following did work and it is flexible to edit it by “category”
      catalog > manage categories > display settings… just uncheck the “Use All Available Attributes” checkbox and select only the attributes you want to use

  15. Priya says:

    Thanks for the Information, I was looking for it for a long time,

    After installing the google webmaster file, I saw 10000 of unnecessary links cached by google, I even block the URL but that was not the full solution.

    After removing this I think I get the solution.

    Million thanks.

  16. Daco says:

    Or, you could just set manually the order field you want to use (in this case ‘price’)
    <a href="getOrderUrl(‘price’, ‘desc’) ?>” title=”__(‘Set Descending Direction’) ?>”>Desc
    in toolbar.php

  17. elvar says:

    How to reorder the attributes for sorting?

    Currently I have now 3 – Name, Price and Newest (without Position)

    I want to have it listed differently and column ‘Position’ in table ‘`catalog_eav_attribute’ does not affect it. Also even if Position method for sorting is pulled out – category listing is still by default with it.

  18. GLOKAL says:

    Hi there

    I would like to echo position no. on the product listing on frontend. But how can I do this? It sorts by position no. but I cannot get it to echo the numbers in the listing?

    Please advice:-)

  19. Jelle says:

    For those who have issues with multi language, change ‘Position’ in the if to $this->__(‘Position’) . This will make Magento remove the translated ‘Position ‘.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">