Jump to content

Remove item from "Sort by" function in products page


Recommended Posts

Hi everyone,

 

I have an issue with Prestashop 1.7 (knew how to do with 1.6, but with the new one):

I would like to remove "Relevance" from the list of Sort by options in the products listing page.

Does someone have any clue about how to proceed?

 

Many thanks,

 

Noe

 

Link to comment
Share on other sites

  • 2 weeks later...

Not sure about removing just 1 sort option...but the entire drop down menu can be removed by editing the file:

 

../themes/classic/templates/catalog/_partials/sort-orders.tpl

 

modify the line:

 
<span class="col-sm-3 col-md-3 hidden-sm-down sort-by">{l s='Sort by:' d='Shop.Theme'}</span>
 
to be

 

<span class="col-sm-3 col-md-3 hidden-sm-down sort-by">{l s=' ' d='Shop.Theme'}</span>

 

then delete the rest of the file below this line.

 

Make a backup of your original file 1st just in case.

Edited by kellyriverstone (see edit history)
  • Thanks 1
Link to comment
Share on other sites

  • 2 weeks later...

I have been trying the same but can´t remove just one sort option. Still figuring out how to do it. 

 

Like kellyriverstone says yo can remove the entire dropdown, but I have done it in a different way.

 

Edit this file:

 

../themes/classic/templates/catalog/_partials/products-top.tpl

 

Delete or comment this lines:

 
<div class="box-sort-by">
      {block name='sort_by'}
        {include file='catalog/_partials/sort-orders.tpl' sort_orders=$listing.sort_orders}
      {/block}
  </div>

 

After that it is recommended to delete the border-right and padding of the "total products" display div. 

You can do that editing the style.css of your template.

In my case this is what i did:

 

.products-selection .total-products p{
margin: 5px 0;
/*border-right: 1px solid #666;*/
margin-right: 8px;
padding-right:8px;
line-height: 13px;
}
 
I have "commented" the line of the border and modified the margin-right and padding-right attributes. 
 
Hope it helps.
Link to comment
Share on other sites

  • 1 month later...
  • 1 year later...
On 5/13/2017 at 4:15 AM, krapo said:

Hi everyone,

 

I have an issue with Prestashop 1.7 (knew how to do with 1.6, but with the new one):

I would like to remove "Relevance" from the list of Sort by options in the products listing page.

Does someone have any clue about how to proceed?

 

Many thanks,

 

Noe

 

I have a temporary 'fix' - to comment out the relevant line in "/modules/ps_facetedsearch/src/Ps_FacetedsearchProductSearchProvider.php":

    private function getAvailableSortOrders()
    {
        return [
//            (new SortOrder('product', 'position', 'asc'))->setLabel(
//                $this->module->getTranslator()->trans('Relevance', array(), 'Modules.Facetedsearch.Shop')
//            ),
            (new SortOrder('product', 'name', 'asc'))->setLabel(
                $this->module->getTranslator()->trans('Name, A to Z', array(), 'Shop.Theme.Catalog')
            ),
            (new SortOrder('product', 'name', 'desc'))->setLabel(
                $this->module->getTranslator()->trans('Name, Z to A', array(), 'Shop.Theme.Catalog')
            ),
            (new SortOrder('product', 'price', 'asc'))->setLabel(
                $this->module->getTranslator()->trans('Price, low to high', array(), 'Shop.Theme.Catalog')
            ),
            (new SortOrder('product', 'price', 'desc'))->setLabel(
                $this->module->getTranslator()->trans('Price, high to low', array(), 'Shop.Theme.Catalog')
            ),
        ];
    }

You should probably override the function for a more permanent fix, but pretty new to Prestashop, so not sure how!

Hope that helps though if a little late to the party!

  • Like 1
Link to comment
Share on other sites

  • 1 year later...

I would go for the following:
In the tpl file sort-orders.tpl edit the following if you want to skip, for example, sort option position.

<span class="col-sm-3 col-md-3 hidden-sm-down sort-by">{l s='Sort by:' d='Shop.Theme.Global'}</span>
<div class="{if !empty($listing.rendered_facets)}col-sm-9 col-xs-8{else}col-sm-12 col-xs-12{/if} col-md-9 products-sort-order dropdown">
  <button
    class="btn-unstyle select-title"
    rel="nofollow"
    data-toggle="dropdown"
    aria-haspopup="true"
    aria-expanded="false">
    {if isset($listing.sort_selected)}{$listing.sort_selected}{else}{l s='Select' d='Shop.Theme.Actions'}{/if}
    <i class="material-icons float-xs-right">&#xE5C5;</i>
  </button>
  <div class="dropdown-menu">
    {foreach from=$listing.sort_orders item=sort_order}
        {if $sort_order.field == 'position'}{continue}{/if}
      <a
        rel="nofollow"
        href="{$sort_order.url}"
        class="select-list {['current' => $sort_order.current, 'js-search-link' => true]|classnames}"
      >
        {$sort_order.label}
      </a>
    {/foreach}
  </div>
</div>

 

The part that does it, is the following:
{if $sort_order.field == 'position'}{continue}{/if}

Here you can add other fields you want to exclude.

 

Link to comment
Share on other sites

  • 10 months later...

PS. 1.7.6.4 file -> /modules/ps_facetedsearch/src/Product/SearchProvider.php

 

CODE TO REMOVE RELEVANT sort by 

private function getAvailableSortOrders()
    {
        $sortSalesDesc = new SortOrder('product', 'sales', 'desc');
        //$sortPosAsc = new SortOrder('product', 'position', 'asc');
        $sortNameAsc = new SortOrder('product', 'name', 'asc');
        $sortNameDesc = new SortOrder('product', 'name', 'desc');
        $sortPriceAsc = new SortOrder('product', 'price', 'asc');
        $sortPriceDesc = new SortOrder('product', 'price', 'desc');
        $translator = $this->module->getTranslator();

        return [
            $sortSalesDesc->setLabel(
                $translator->trans('Best Sellers', [], 'Modules.Facetedsearch.Shop')
            ),
            //$sortPosAsc->setLabel(
            //    $translator->trans('Relevance', [], 'Modules.Facetedsearch.Shop')
            //),
            $sortNameAsc->setLabel(
                $translator->trans('Name, A to Z', [], 'Shop.Theme.Catalog')
            ),
            $sortNameDesc->setLabel(
                $translator->trans('Name, Z to A', [], 'Shop.Theme.Catalog')
            ),
            $sortPriceAsc->setLabel(
                $translator->trans('Price, low to high', [], 'Shop.Theme.Catalog')
            ),
            $sortPriceDesc->setLabel(
                $translator->trans('Price, high to low', [], 'Shop.Theme.Catalog')
            ),
        ];
    }

Link to comment
Share on other sites

  • 9 months later...
  • 5 months later...
On 1/9/2020 at 9:34 AM, Kevin said:
 <div class="dropdown-menu">
        {foreach from=$listing.sort_orders item=sort_order}
            {if $sort_order.current}
                {assign var="currentSortUrl" value=$sort_order.url|regex_replace:"/&resultsPerPage=\d+$/":""}
            {/if}
            <a
                    rel="nofollow"
                    href="{$sort_order.url}"
                    class="select-list dropdown-item {['current' => $sort_order.current, 'js-search-link' => true]|classnames}"
            >
                {$sort_order.label}
            </a>
        {/foreach}
    </div>

Above is the code creating the dropdown menu and below code is how you can remove any option you choose or as many options as you want. 

    <div class="dropdown-menu">
        {foreach from=$listing.sort_orders item=sort_order}
            {if $sort_order.current}
                {assign var="currentSortUrl" value=$sort_order.url|regex_replace:"/&resultsPerPage=\d+$/":""}
            {/if}
            {if $sort_order.label == "Relevance, reverse"}{continue}{/if}
            <a
                    rel="nofollow"
                    href="{$sort_order.url}"
                    class="select-list dropdown-item {['current' => $sort_order.current, 'js-search-link' => true]|classnames}"
            >
                {$sort_order.label}
            </a>
        {/foreach}
    </div>

Here I use .label instead of position since position removed 2 options from my dropdown and not just the 1.

Edited Kevins response above since I believe this to be the most suitable. The ones mentioning Facetedsearch were not suitable for me since I have this module disabled and $listing.sort_orders I believe is Prestashop default functionality. 

With that being said I have modified Kevin's answer to suit the question more and only remove 1 option from the dropdown menu. 

Edited by Shenny (see edit history)
Link to comment
Share on other sites

  • 1 year later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...