Jump to content

[Solved!] Sorting attributes by group AND name??


Recommended Posts

I can't get my groups and the attributes inside of them that are on my items to display in any sort of alphebetical order, or at least, not both at the same time.

I'm not sure how to explain this but I will try my best.

I have groups

1
2
3

In group 1 i have attributes 1, 2, 3. In group 2 I have attributes 1, 2, 3. In group 3 i have attributes 1, 2, 3.

If i do not alter my products.php in the prestashop/classes directory the group order displays randomly, but the attributes inside stay in 1, 2, 3 order.

If i alter my products.php (line 1317 - 1332) from

    public function getAttributesGroups($id_lang)
   {
       return Db::getInstance()->ExecuteS('
       SELECT ag.`id_attribute_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.`id_image`, 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 pa.`id_product_attribute`');
   }



to

    public function getAttributesGroups($id_lang)
   {
       return Db::getInstance()->ExecuteS('
       SELECT ag.`id_attribute_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.`id_image`, 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 ag.`id_attribute_group`');
   }



(changed line 1331 from ORDER BY pa.`id_product_attribute` to ORDER BY ag. 'id_attribute_group' )

the groups will list alphabetically, but the attributes inside do not list alphabetically, in fact it seems almost random in which the order is.

I guess what i'm asking is if there is any way to list both my groups and attributes alphabetically at the same time, and how would i do so?

Sorry if this is confusing, I will clarify if I need to do so.

Thanks for the help!

Link to comment
Share on other sites

Hi I am trying to get a similar order : 1 Attribute group by agl. name and the attributes within the group by the al. name but each time i alter the order by line I get a blank page - I have tried the quotes but still get a problem. Any ideas?
Thx
Psychosonicsid


Hey psychosonicsid. I was trying to do the same thing and was encountering the same error. The code I used above which im going to post again below works perfectly for me. It sorts the groups by name a-z and the attributes a - z, which i think is what your wanting it to be doing. Make a backup and give it a try and see if it works. I could personally never get the agl. things to work myself, not sure why. But again, the code below worked for me so it may for you as well.

ORDER BY ag.`id_attribute_group`, a.`id_attribute`); 



Good luck and while i'm not the most skilled coder, i will try and help you get it working.

Link to comment
Share on other sites

Already tried that - blank screen when replacing with the code listed:
Ideally I want to sort the attribute groups by the name used in the backoffice, not the public name and the attributes within these by the name of the attribute its self (a-z - 1.-9 etc)

Other than this one line there wasnt any other changes that I missed was there??

Link to comment
Share on other sites

Odd. The way that i have it working it sorts based on the private name, not public so it should be what your looking for. I don't believe I changed anything else but i may have, so i rared up my product.php so you can try upping it to your server and see if it works. Other than that, i can't say what is wrong. Perhaps clearing your cache might do something?

http://www.bordnet.net/product.rar

Link to comment
Share on other sites

  • 6 months later...
×
×
  • Create New...