Jump to content

[Solved]How to add sort by "added date" for product list?


Recommended Posts

This works for 1.3.7, should work with 1.3.6 as well.

 

Edit (after making a backup copy) /themes/prestashop/product-sort.tpl. Within the select element add another option element so the entire select reads:

<select id="selectPrductSort" onchange="document.location.href = $(this).val();">
<option value="{$link->addSortDetails($request, 'position', $orderwayposition)|escape:'htmlall':'UTF-8'}" {if $orderby eq 'position'}selected="selected"{/if}>{l s='--'}</option>
<option value="{$link->addSortDetails($request, 'price', 'asc')|escape:'htmlall':'UTF-8'}" {if $orderby eq 'price'    AND $orderway eq 'ASC' }selected="selected"{/if}>{l s='price: lowest first'}</option>
<option value="{$link->addSortDetails($request, 'price', 'desc')|escape:'htmlall':'UTF-8'}" {if $orderby eq 'price'    AND $orderway eq 'DESC'}selected="selected"{/if}>{l s='price: highest first'}</option>
<option value="{$link->addSortDetails($request, 'name', 'asc')|escape:'htmlall':'UTF-8'}" {if $orderby eq 'name'     AND $orderway eq 'ASC' }selected="selected"{/if}>{l s='name: A to Z'}</option>
<option value="{$link->addSortDetails($request, 'name', 'desc')|escape:'htmlall':'UTF-8'}" {if $orderby eq 'name'     AND $orderway eq 'DESC'}selected="selected"{/if}>{l s='name: Z to A'}</option>
<option value="{$link->addSortDetails($request, 'quantity', 'desc')|escape:'htmlall':'UTF-8'}" {if $orderby eq 'quantity' AND $orderway eq 'DESC' }selected="selected"{/if}>{l s='in-stock first'}</option>
<option value="{$link->addSortDetails($request, 'date_add', 'desc')|escape:'htmlall':'UTF-8'}" {if $orderby eq 'date_add' AND $orderway eq 'DESC' }selected="selected"{/if}>{l s='date added'}</option>
</select>

Notice the the last option element. This will give you products in descending date added order. If you want ascending order change relevant descs to asc. You can also change "date added" at the end to something else if you wish.

  • Like 1
Link to comment
Share on other sites

  • 3 weeks later...
What would the code be for PS 1.4.4?

I don't have 1.4.4 installed. This is for latest version but should work with the 1.4.4. too.

 

Insert one or both lines below in the same file.

 

<option value="date_add:desc" {if $orderby eq 'date_add' AND $orderway eq 'desc'}selected="selected"{/if}>{l s='Date added: latest first'}</option>
<option value="date_add:asc" {if $orderby eq 'date_add' AND $orderway eq 'asc'}selected="selected"{/if}>{l s='Date added: earliest first'}</option>

 

To insert after the existing options use the marked location, or move up to insert earlier

 

<select id="selectPrductSort">        
       <option value="{$orderbydefault|escape:'htmlall':'UTF-8'}:{$orderwaydefault|escape:'htmlall':'UTF-8'}" {if $orderby eq $orderbydefault}selected="selected"{/if}>{l s='--'}</option>
       {if !$PS_CATALOG_MODE}
               <option value="price:asc" {if $orderby eq 'price' AND $orderway eq 'asc'}selected="selected"{/if}>{l s='Price: lowest first'}</option>
               <option value="price:desc" {if $orderby eq 'price' AND $orderway eq 'desc'}selected="selected"{/if}>{l s='Price: highest first'}</option>
       {/if}
       <option value="name:asc" {if $orderby eq 'name' AND $orderway eq 'asc'}selected="selected"{/if}>{l s='Product Name: A to Z'}</option>
       <option value="name:desc" {if $orderby eq 'name' AND $orderway eq 'desc'}selected="selected"{/if}>{l s='Product Name: Z to A'}</option>
       {if !$PS_CATALOG_MODE}
               <option value="quantity:desc" {if $orderby eq 'quantity' AND $orderway eq 'desc'}selected="selected"{/if}>{l s='In-stock first'}</option>
       {/if}
       <!-- INSERT HERE -->
</select>

 

You can change the wording "Date added: latest/earliest first" to whatever you want if not suitable. Remember to make a backup of the original file.

Link to comment
Share on other sites

  • 2 months later...
  • 10 months later...
  • 1 month later...
  • 1 year later...
  • 4 months later...

Sorting within category works perfectly with this change. However when a user manually enters a search tem, there is no visible result (no image, no text) - but page numbers still exist.

Any idea?

 

My version is 1.5.6.2. Regards, Scully

Link to comment
Share on other sites

  • 6 years 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...