Jump to content

1.3 Attribute Order Update


Recommended Posts

Hi All,

Just updated my first of 5 shops to 1.3 and noticed that my attributes are now ordered in alphabetical order and not by the order entered as in 1.2.5.

This is great for most attributes, but makes a Small/Medium/Large/X Large/XX Large list look horrible putting large first.

Where has the change been made? and can it be reversed?

Dan

Link to comment
Share on other sites

  • 2 weeks later...
  • 3 weeks later...
  • 5 weeks later...
Hi All,

Just updated my first of 5 shops to 1.3 and noticed that my attributes are now ordered in alphabetical order and not by the order entered as in 1.2.5.

This is great for most attributes, but makes a Small/Medium/Large/X Large/XX Large list look horrible putting large first.

Where has the change been made? and can it be reversed?

Dan


This is bugging me out, anyone found a solution to this. I don't want to install a module for this. Would appreciate it if someone can point me in the right direction. Thanks
Link to comment
Share on other sites

  • 4 weeks later...

**SOLVED* Hi sgtbash and everyone else looking for the same solution.

The attribute order of 1.3 can be reversed back to the order as in 1.2.5. To do this make the following changes;

1. In /classes/Product.php function: getAttributesGroups()

replace

ORDER BY al.`name`');


with

ORDER BY pa.`id_product_attribute`'); 



2. In /product.php

comment out the following on lines 285 and 286

foreach($groups AS &$group)
natcasesort($group['attributes']);


to

// foreach($groups AS &$group)
// natcasesort($group['attributes']);



Please Note: The order of attributes is the order in which you add them to each product. I will soon post a more elegant solution where you can set the order of the attributes in each group in the back office.

  • Like 1
Link to comment
Share on other sites

  • 4 weeks later...
  • 4 weeks later...

HELP!

I tried the above but when I changed them and uploaded them my homepage goes completely blank.

I'm not sure if this matters but the lines that are supposed to be replaced, there is a space missing between foreach and the bracket. I.e. when you search:

foreach($groups AS &$group)
natcasesort($group['attributes']);

it can't find it, so you have to search for the same with a space, as in:

foreach ($groups AS &$group)
natcasesort ($group['attributes']);

I'm new to Prestashop, but I thought I followed this pretty closely

Link to comment
Share on other sites

Hi everyone.

First of all thank's to justme54s! It work's form me.
I think we all expecting your promised module.

Meanwhile I attached the two modified files. Just replace it, and it's done.
You will have the sort order by ID. In my case (s, m, l, xl, xxl).
Don't forget! The order of attributes is the order in which you add them to each product.

Replace the first file (Product.php) in root/classes/product.php
Replace the second file (product.php) in root/product.php

It's coded in prestashop version 1.3.2. Older versions are not tested!


classyjoes, indeed It have some space errors, so you can download the two file attached and it will work for you.

product.php

Product.php

Link to comment
Share on other sites

  • 1 month later...
  • 4 weeks later...

Hello

I have pretashop version 1.3.5 and tried to make the changes as suggested on here but i get a blank page. I downloaded the files and compared to make sure all spacing was correct etc and as far as im concerned they are exactly the same as suggested on here.

Could this be anything to do with me having a newer version? Or any ideas what I may be doing wrong please?

thanks

Rob

Link to comment
Share on other sites

  • 4 weeks later...
  • 4 weeks later...
  • 2 weeks later...

Thank-You Very, Very much for posting a fix for the funky attributes order issue justme54s and to Jeet Kune Do for posting the files!!

I have been struggling with this attribute order for dang near half a day now and your fix seems to be working for me so far. I am running PrestaShop v.1.3.7 and so far I have not run across any errors.

So again I applaud you for finding a fix for the attribute order.

Link to comment
Share on other sites

  • 2 weeks later...

In version 1.4 you have to change in classes/Product.php on line 2136:

ORDER BY agl.`public_name`, al.`name`');


to

ORDER BY agl.`id_attribute_group`, al.`name`');



and the same modifications must be made in classes/Cart.php, on line 420, for the attributes to be sorted in the same way in the shopping cart.

Link to comment
Share on other sites

  • 3 weeks later...
In version 1.4 you have to change in classes/Product.php on line 2136:
ORDER BY agl.`public_name`, al.`name`);

to
ORDER BY agl.`id_attribute_group`, al.`name`);

and the same modifications must be made in classes/Cart.php, on line 420, for the attributes to be sorted in the same way in the shopping cart.


Only changing this line in the 1.4 will not disappear me 01. 02. etc.

Thanks in advance
Link to comment
Share on other sites

In version 1.4 you have to change in classes/Product.php on line 2136:
ORDER BY agl.`public_name`, al.`name`);

to
ORDER BY agl.`id_attribute_group`, al.`name`);

and the same modifications must be made in classes/Cart.php, on line 420, for the attributes to be sorted in the same way in the shopping cart.


Only changing this line in the 1.4 will not disappear me 01. 02. etc.

Thanks in advance


The solution that I was reffering to doesn't require adding numbers before the name of the attribute, it will sort the attributes by the order they were added in BO.
Link to comment
Share on other sites

  • 2 weeks later...
  • 2 weeks later...

Synkro, did you resolve this?

I understood your original post as a problem with sorting the options (Small, Med, Large Xlarge etc). They currently appear alphabetically (i.e. Large, Med, Small, Xlarge) which is untidy.

Do the remaining posts address this issue, or has the post moved onto the sort over of the attributes. I.e. if a product has more than pne set of options.

I tried the 1.4 code change and it does not solve the problem mentioned in the original post - the options must be getting sorted again further on.

Link to comment
Share on other sites

OK, I figured this out for v 1.4. The answer was pretty much here, but in 1.4 some of the code has moved

To sort the options within a product drop down menu, you need to comment out the following code in controllers/productController.php

foreach($groups AS &$group)
natcasesort($group['attributes']);

Also, within product.php, make the change mentioned earlier ie.

Change "ORDER BY agl.`public_name`, al.`name`" to the sort order you need.

I changed it to "ORDER BY ag.`id_attribute_group`, pa.`price`, pa.`weight`" so that the options are displayed in price order (if the prices are the same, then they will order by weight).

This suited my site, but could do any other order you like.

Link to comment
Share on other sites

  • 3 weeks later...

I was implementing this and yet don't see the point of sorting by `id_attribute_group` since it's going to be always the same id for any given attribute group. What I made at last (somebody correct me if I'm missing something) is to sort that query by al.`id_attribute`. The only condition necesary here is to have the attributes created in our desired order, wich is the usual procedure.

Link to comment
Share on other sites

  • 5 weeks later...
  • 3 months later...
  • 2 weeks later...

Another way to do this :

 

add a smarty modifier in tools/smarty/plugins to sort any array in your tpl :

 

{foreach from=$groups|sortby"name" key=id_attribute_group item=group}

OR with more control

{foreach from=$groups|sortby"-name, #id" key=id_attribute_group item=group}

The '-' lets you sort in reverse order, and the # lets you sort numerically rather than as a string (you can have '-#id' as well to sort numerically in reverse order)

 

you just need to add this file in tools/smarty/plugins

modifier.sortby.php

Link to comment
Share on other sites

  • 3 months later...

Another way to do this :

 

add a smarty modifier in tools/smarty/plugins to sort any array in your tpl :

 

{foreach from=$groups|sortby"name" key=id_attribute_group item=group}

OR with more control

{foreach from=$groups|sortby"-name, #id" key=id_attribute_group item=group}

The '-' lets you sort in reverse order, and the # lets you sort numerically rather than as a string (you can have '-#id' as well to sort numerically in reverse order)

 

you just need to add this file in tools/smarty/plugins

 

The code you included, is not even contained in your attached file. Where do we configure the lines of code you specified please? Thanks

Link to comment
Share on other sites

  • 3 weeks later...

In version 1.4 you have to change in classes/Product.php on line 2136:

ORDER BY agl.`public_name`, al.`name`');

to

ORDER BY agl.`id_attribute_group`, al.`name`');

 

and the same modifications must be made in classes/Cart.php, on line 420, for the attributes to be sorted in the same way in the shopping cart.

 

Hi,

 

I tried this in ps1.4.7.0 but it did not help

 

 $result = Db::getInstance()->ExecuteS('
 SELECT pac.`id_product_attribute`, agl.`public_name` AS public_group_name, al.`name` AS attribute_name
 FROM `'._DB_PREFIX_.'product_attribute_combination` pac
 LEFT JOIN `'._DB_PREFIX_.'attribute` a ON a.`id_attribute` = pac.`id_attribute`
 LEFT JOIN `'._DB_PREFIX_.'attribute_group` ag ON ag.`id_attribute_group` = a.`id_attribute_group`
 LEFT JOIN `'._DB_PREFIX_.'attribute_lang` al ON (a.`id_attribute` = al.`id_attribute` AND al.`id_lang` = '.(int)$id_lang.')
 LEFT JOIN `'._DB_PREFIX_.'attribute_group_lang` agl ON (ag.`id_attribute_group` = agl.`id_attribute_group` AND agl.`id_lang` = '.(int)$id_lang.')
 WHERE pac.`id_product_attribute` IN ('.implode($paImplode, ',').')
 ORDER BY agl.`id_attribute_group`, al.`name` ASC');

the last line was changed (nearby, referencing code line numbers > in mine it was on line #470)

 

sort order still L, M, S, XL,...

 

also, I'm still confused about setting the order by id_attribute_group - is it the group which get sortet or are this the attributes themself?

 

however, I tried all what I found here and in a previous 1.3 post, the attribute sort order did not change.

any idea to fix this without buying a module?

 

Thanks from Vienna

Tom

 

UPDATE:

I gave it a try directly in phpmyadmin which gave me a correct sortorder with the following sql:

SELECT ag.id_attribute_group, ag.is_color_group, agl.name AS group_name, agl.public_name AS public_group_name, a.id_attribute, al.name AS attribute_name, a.color AS attribute_color, pa . *
FROM ps9gs3ka_product_attribute pa
LEFT JOIN ps9gs3ka_product_attribute_combination pac ON pac.id_product_attribute = pa.id_product_attribute
LEFT JOIN ps9gs3ka_attribute a ON a.id_attribute = pac.id_attribute
LEFT JOIN ps9gs3ka_attribute_group ag ON ag.id_attribute_group = a.id_attribute_group
LEFT JOIN ps9gs3ka_attribute_lang al ON a.id_attribute = al.id_attribute
LEFT JOIN ps9gs3ka_attribute_group_lang agl ON ag.id_attribute_group = agl.id_attribute_group
WHERE pa.id_product =10
AND al.id_lang =4
AND agl.id_lang =4
ORDER BY agl.id_attribute_group, a.id_attribute ;

 

so I went back in code in /classes/product.php and /classes/cart.php adding

ORDER BY agl.id_attribute_group, a.id_attribute ;

 

But in Frontend the order is still the same.

any idea, if I did the changes in the wrong places?

 

Thanks

Tom

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

Sort Order of attributes (german: Sortierung von Varianten und Kombinationen zb. Größe s, m. l, xl...)

Solved with this post also in v 1.4.7.0

I translate:

in /classes/Product.php

 

search for:

public function getAttributesGroups

below that code find the line:

ORDER BY ag.`id_attribute_group`, pa.`id_product_attribute`');

in my case it was on line 1217

and change it to:

ORDER BY ag.`id_attribute_group`, pa.`id_product_attribute`');

 

then in /controllers/ProductController.php search for:

foreach ($groups AS &$group)
natcasesort($group['attributes']);

in my case it was on line 327-328

and comment these 2 lines

(

// foreach ($groups AS &$group)
 //  natcasesort($group['attributes']);

)

 

Thanks to JAKCRABBIT

  • Like 1
Link to comment
Share on other sites

  • 4 weeks later...

@gsdealer.

 

I'm using 1.4.5.1 and I think your solution might work. However I see the same line twice:

ORDER BY ag.`id_attribute_group`, pa.`id_product_attribute`');

 

So replace a line with another identical line ? Must be a typo error. Could you help me out?

 

Cheers,

 

Steven

Link to comment
Share on other sites

  • 1 month later...
  • 3 weeks later...

Hi everyone.

 

First of all thank's to justme54s! It work's form me.

I think we all expecting your promised module.

 

Meanwhile I attached the two modified files. Just replace it, and it's done.

You will have the sort order by ID. In my case (s, m, l, xl, xxl).

Don't forget! The order of attributes is the order in which you add them to each product.

 

Replace the first file (Product.php) in root/classes/product.php

Replace the second file (product.php) in root/product.php

 

It's coded in prestashop version 1.3.2. Older versions are not tested!

 

 

classyjoes, indeed It have some space errors, so you can download the two file attached and it will work for you.

 

worked perfectly. thanx alot for the fix

Link to comment
Share on other sites

  • 3 weeks later...

Thank you gsdealer. Your fix worked for me.

 

To be clear, change

ORDER BY ag.`id_attribute_group`, pa.`id_product_attribute`');

to

 

');

 

in the first edit an the second edit as listed.

 

I had to try a couple times to get that first one right.

 

Thanks again

SC

Link to comment
Share on other sites

  • 3 months later...

I have changed the code to successfully change the order of the attribute *groups*, but still am not able to change the order of the actual attributes *within* a group (for example: S, M, L, XL, in the "Size" group).

 

Any ideas? I have tried everything mentioned here and in other posts, but still cannot change the order of the attributes themselves.

 

Version 1.4.6.2.

 

THANKS! :)

 

http://www.professio.../6-macbook.html

 

*I am using a module called "Improved Attributes Selection", which may be the reason the code changes I have made are not working. Hmmmm.....

 

Frustrated and stuck. Any help would be greatly appreciated.

 

UPDATE: solved it, which is amazing considering my very limited programming knowledge:) Wooooooo hooooooooo!! :) :)

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

  • 4 years later...

Hi.

 

I have a problem with sorting product attribute. In BO size is list in order that I added it with combination generator.

But in front ofice attributes are not in same order like in BO.

Problem is that if I choose size which I already add for product before, prestashop place ¨"old" size first and then new created size. But only in FO in BO they are just like they have to be.

Examlpe:

BO 100 x 100cm   (add second)

BO 110 x 110cm    (add first)

 

FO 110 x 110cm  (add first)

FO 100 x 100cm  (add second)

 

 My prestashop version is 1.6.1.4. Can someone please help me with this?

 

post-140755-0-35013500-1492543791_thumb.

post-140755-0-19274300-1492543780_thumb.

post-140755-0-62481800-1492543785_thumb.

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