Jump to content

[SOLVED] Change the order of the colours in the colour picker?


Recommended Posts

Can anyone tell me how i can change the order of the colours in my colour picker?

At the moment its always alphabetical.

Also i would like to show the colours that cost extra, seperate to the standard colours, is this possible?

Thanks,
Eddie

Link to comment
Share on other sites

The attributes and colours are all retrieves using the same query in the getAttributesGroups function in classes/Product.php (in PrestaShop v1.3.1):

public function getAttributesGroups($id_lang)
{
   return Db::getInstance()->ExecuteS('
   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.`id_product_attribute`, pa.`quantity`, pa.`price`, pa.`ecotax`, pa.`weight`, pa.`default_on`, pa.`reference`
   FROM `'._DB_PREFIX_.'product_attribute` pa
   LEFT JOIN `'._DB_PREFIX_.'product_attribute_combination` pac ON pac.`id_product_attribute` = pa.`id_product_attribute`
   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`
   LEFT JOIN `'._DB_PREFIX_.'attribute_group_lang` agl ON ag.`id_attribute_group` = agl.`id_attribute_group`
   WHERE pa.`id_product` = '.intval($this->id).'
   AND al.`id_lang` = '.intval($id_lang).'
   AND agl.`id_lang` = '.intval($id_lang).'
   ORDER BY al.`name`');
}



As you can see at the end, they are ordered by name. You can change it to order by a.`id_attribute` to sort them by ID instead. It isn't possible to manually choose the order.

Link to comment
Share on other sites

  • 2 months later...
  • 3 weeks later...
Hello, I tried using this on PS 1.3.1 but it did not change anything, it still sorts alphabetically. Is there anything else I might need to change to make it work? Help would be very much appreciated!


I'm looking at the code now and it seems to be different in v1.3, which is why you probably don't see a difference.
Link to comment
Share on other sites

Hi noesac,

thanks for the feedback! I have found a workaround using empty spaces to force the options in the order I want, but this is far form being a good solution, nor one that will work in a full production environment.

If anyone has an idea on how to solve this for PS 1.3.1. that would be really great!

Link to comment
Share on other sites

Hi noesac,

thanks for the feedback! I have found a workaround using empty spaces to force the options in the order I want, but this is far form being a good solution, nor one that will work in a full production environment.

If anyone has an idea on how to solve this for PS 1.3.1. that would be really great!


Would you mind elaborating on this approach that you've taken?

I've also been hunting for a better way to deal with this, but nothing yet!
Link to comment
Share on other sites

I used an invisible character from the symbol map which in the hierarchy of symbols comes after the letter Z. I don't remember the exact name, I think it was something like "small blank space". I placed none in front of my first option, one in front of the second option, two in front of the third, etc...

Because this symbol is considered to come after Z in the alphabet, this method will sort your options alphabetically without regard for the actual first visible letter. For example in my case it looks like this
Sizes:
XS
_S
__M
___L
____XL
_____XXL

(with _ replacing the invisible character for this example)

It is far from perfect, but it's less annoying than having your options sorted against all logic (L, M, S, XL, XS, XXL)

Link to comment
Share on other sites

  • 4 weeks later...

Am having the same issues, need to sort from XS to XL but it's putting them alphabetically.

Anyone know a fix? rocky's fix does not work in Prestashop 1.3.1.1. changed "ORDER BY al.`name`" to "order by a.`id_attribute`" and no changes at all. tried other variations and nothing happens.

Link to comment
Share on other sites

  • 9 months 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...