Jump to content

Sort products by weight?


Recommended Posts

Hi,

 

I was previously using prestashop 1.25 and we had a fix to sort products by weight ( the weight you enter on the product global information at the first part of the page).

 

Since I updated to 1.4 it seems many things have changed and I have been trying many ways but I can't seem to find the way to add the sorting by weight for my customers to use.

 

I have seen the module to sort by attributes, but that is not what I am looking for as I don't want to add any attributes to my products. The weight is entered directly in the product description for customers to see and inside the product global information for the BO management.

 

If anyone found a way to add this that would help me so much,

 

Thanks

Link to comment
Share on other sites

  On 5/9/2012 at 10:46 AM, gerry293 said:

Since I updated to 1.4 it seems many things have changed and I have been trying many ways but I can't seem to find the way to add the sorting by weight for my customers to use.

 

When you ask a question like this, it would be helpful to let people know the exact version you have installed.

 

Assuming you have the latest version installed (may or may not work with other versions)

 

Locate the file /themes/[your theme]/product-sort.tpl. Within the select element insert the following, e.g., immediately before the closing tag for the element:

 

<option value="weight:asc" {if $orderby eq 'weight' AND $orderway eq 'asc'}selected="selected"{/if}>{l s='Product Weight'}</option>

 

This will sort lowest to highest weight, change all occurences of 'asc' with 'desc' if you want otherwise. Alternatively add a second similar line using 'desc' and change wording of 'Product Weight' in both lines.

 

Then add the attached file to /override/classes/ directory

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

  • 3 weeks later...
  On 5/29/2012 at 12:06 PM, gerry293 said:
where is the attached file?

Removed as it causes more problems than it helps when people try to use it without giving a second thought to the installed version. Let me know of the version you have and I will send you the appropriate change.

  • Like 2
Link to comment
Share on other sites

Hi,

 

I inserted the file in the override folder and here is my code for the product-sort.tpl

 

<form id="productsSortForm" action="{$request|escape:'htmlall':'UTF-8'}">
<p class="select">
 <select id="selectPrductSort" onchange="document.location.href = $(this).val();">
  <option value="{$link->addSortDetails($request, $orderbydefault, $orderwaydefault)|escape:'htmlall':'UTF-8'}" {if $orderby eq $orderbydefault}selected="selected"{/if}>{l s='--'}</option>
  {if !$PS_CATALOG_MODE}
  <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>
  {/if}
  <option value="{$link->addSortDetails($request, 'name', 'asc')|escape:'htmlall':'UTF-8'}" {if $orderby eq 'name' AND $orderway eq 'asc'}selected="selected"{/if}>{l s='Product 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='Product Name: Z to A'}</option>
  <option value="weight:asc" {if $orderby eq 'weight' AND $orderway eq 'asc'}selected="selected"{/if}>{l s='Carat weight: lowest first'}</option>
  <option value="weight:desc" {if $orderby eq 'weight' AND $orderway eq 'desc'}selected="selected"{/if}>{l s='Carat weight: highest first'}</option>
  {if !$PS_CATALOG_MODE}
  {/if}
 </select>

 

It is still not working, the words are showing on my webpage for product weight, but when clicked nothing happens.

 

Thanks

Link to comment
Share on other sites

  On 5/30/2012 at 6:22 PM, phrasespot said:

Hmm. It should work. I tested on a 1.4.5.1 install. Send me link to where it is used.

 

Ah, that template code does not look like the default template from 1.4.5.1. Maybe you are using a theme which modifies the template. I think the following should work, replace with the change you already made to the template:

 

<option value="{$link->addSortDetails($request, 'weight', 'desc')|escape:'htmlall':'UTF-8'}" {if $orderby eq 'weight' AND $orderway eq 'desc'}selected="selected"{/if}>{l s='Carat weight: highest first'}</option>
<option value="{$link->addSortDetails($request, 'weight', 'asc')|escape:'htmlall':'UTF-8'}" {if $orderby eq 'weight' AND $orderway eq 'asc'}selected="selected"{/if}>{l s='Carat weight: lowest first'}</option>

 

If this does not work, I suggest you seek professional help, I am sure it is within the reach of a diamond merchant :)

Link to comment
Share on other sites

It still does not work, it seems the function can not load and sort the weight I enter in each product under the tab <weight (package):>

 

I realize this is taking much of your time and even if I am not much of a diamond dealer, if you would like to offer your professional help, that would be fine, just let me know.

 

Thanks again

Link to comment
Share on other sites

  On 5/31/2012 at 12:59 PM, gerry293 said:

It still does not work, it seems the function can not load and sort the weight I enter in each product under the tab <weight (package):>

I need to see the complete tpl, and maybe the theme. Attach the tpl here. I will ask for theme if I need it.

 

  Quote
if you would like to offer your professional help, that would be fine, just let me know.
Thanks. Not necessary. I don't pick up jobs from help threads I reply to.
Link to comment
Share on other sites

{if isset($orderby) AND isset($orderway)}
<!-- Sort products -->
{if isset($smarty.get.id_category) && $smarty.get.id_category}
{assign var='request' value=$link->getPaginationLink('category', $category, false, true)}
{elseif isset($smarty.get.id_manufacturer) && $smarty.get.id_manufacturer}
{assign var='request' value=$link->getPaginationLink('manufacturer', $manufacturer, false, true)}
{elseif isset($smarty.get.id_supplier) && $smarty.get.id_supplier}
{assign var='request' value=$link->getPaginationLink('supplier', $supplier, false, true)}
{else}
{assign var='request' value=$link->getPaginationLink(false, false, false, true)}
{/if}
<form id="productsSortForm" action="{$request|escape:'htmlall':'UTF-8'}">
<p class="select">
 <select id="selectPrductSort" onchange="document.location.href = $(this).val();">
  <option value="{$link->addSortDetails($request, $orderbydefault, $orderwaydefault)|escape:'htmlall':'UTF-8'}" {if $orderby eq $orderbydefault}selected="selected"{/if}>{l s='--'}</option>
  {if !$PS_CATALOG_MODE}
  <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>
  {/if}
  <option value="{$link->addSortDetails($request, 'name', 'asc')|escape:'htmlall':'UTF-8'}" {if $orderby eq 'name' AND $orderway eq 'asc'}selected="selected"{/if}>{l s='Product 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='Product Name: Z to A'}</option>
  <option value="{$link->addSortDetails($request, 'weight', 'desc')|escape:'htmlall':'UTF-8'}" {if $orderby eq 'weight' AND $orderway eq 'desc'}selected="selected"{/if}>{l s='Carat weight: highest first'}</option>
  <option value="{$link->addSortDetails($request, 'weight', 'asc')|escape:'htmlall':'UTF-8'}" {if $orderby eq 'weight' AND $orderway eq 'asc'}selected="selected"{/if}>{l s='Carat weight: lowest first'}</option>
  {if !$PS_CATALOG_MODE}
  {/if}
 </select>
 <label for="selectPrductSort">{l s='Sort by'}</label>
</p>
</form>
<!-- /Sort products -->
{/if}

 

The theme I use is the free prestashop theme called velvetsky.

 

Thanks

Link to comment
Share on other sites

  • 1 month later...
  On 5/31/2012 at 3:50 PM, phrasespot said:

I need to see the complete tpl, and maybe the theme. Attach the tpl here. I will ask for theme if I need it.

 

  On 7/10/2012 at 9:48 AM, gerry293 said:

Did you find any solution for my problem?

 

Did you do what I asked?

Link to comment
Share on other sites

It does work for me in 1.4.5.1 and every version after that using the product-sort.tpl you posted. I don't know why it does not work in your shop. Do other sorts work as they should?

 

Make sure it is not a caching issue. Delete all files in /tools/smarty/compile/ directory except index.php and try again.

Link to comment
Share on other sites

Hi thx for looking into it.

 

 

I deleted the cache many times, cause I make many changes to the files.

 

Also in my back office I enter the weight in the field called: Weight (package):

 

Would the package word have anything that cause the problem ?

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

  • 2 years later...
Hi, I need to put in the lists of products the ability to sort by weight. I put the following in the product-sort.tpl of my template.

 



<option value="weight:asc" {if $orderby eq 'weight' AND $orderway eq 'asc'}selected="selected"{/if}>{l s='Carat weight: lowest first'}</option>
<option value="weight:desc" {if $orderby eq 'weight' AND $orderway eq 'desc'}selected="selected"{/if}>{l s='Carat weight: highest first'}</option>


 

but although it appears, is no sorting by weight. What else should I change? What other file should be modified to effectively sort by weight?

Prestashop 1.6.0.9

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

I write again, since no one has answered me ...
The solution I found to work is adding weight
 
$ order_by_values = array (0 => 'name', 1 => 'price', 2 => 'DATE_ADD', 3 => 'date_upd', 4 => 'position', 5 => 'manufacturer_name', 6 => 'quantity', 7 => 'reference', 8 => 'weight');

in classes/controller/FrontController.php

 
Thus working properly, the problem is that it does not work when the blocklayerd is active. I do not know what changes need to do to make the ability to sort by weight when the module blocklayered, is active is added.
Edited by fernandodelgado (see edit history)
Link to comment
Share on other sites

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...