kpham501 Posted November 30, 2013 Share Posted November 30, 2013 On a lot of my products I have 4 attributes, 00 mg, 08 mg, 16 mg, and 24 mg. Sometimes it's listed in order 00, 08, 16, 24 and other times its 08, 00, 16, 24 or 16, 08, 00, 24. Is there a way to force it to display in ascending order? Or will it just have to be this way? www.freshairesupply.com click on any eliquid product and you'll see what I mean. I'm running 1.5.6.1 and the default template. Link to comment Share on other sites More sharing options...
ibndawood Posted December 1, 2013 Share Posted December 1, 2013 Hi I tried recreating this in my local setup but I am not able to reproduce it but I do see it in your website and its really something I haven't seen. 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, product_attribute_shop.`id_product_attribute`, IFNULL(stock.quantity, 0) as quantity, product_attribute_shop.`price`, product_attribute_shop.`ecotax`, product_attribute_shop.`weight`, product_attribute_shop.`default_on`, pa.`reference`, product_attribute_shop.`unit_price_impact`, product_attribute_shop.`minimal_quantity`, product_attribute_shop.`available_date`, ag.`group_type` FROM `ps_product_attribute` pa INNER JOIN ps_product_attribute_shop product_attribute_shop ON (product_attribute_shop.id_product_attribute = pa.id_product_attribute AND product_attribute_shop.id_shop = 1) LEFT JOIN ps_stock_available stock ON (stock.id_product = pa.id_product AND stock.id_product_attribute = IFNULL(`pa`.id_product_attribute, 0) AND stock.id_shop = 1 ) LEFT JOIN `ps_product_attribute_combination` pac ON (pac.`id_product_attribute` = pa.`id_product_attribute`) LEFT JOIN `ps_attribute` a ON (a.`id_attribute` = pac.`id_attribute`) LEFT JOIN `ps_attribute_group` ag ON (ag.`id_attribute_group` = a.`id_attribute_group`) LEFT JOIN `ps_attribute_lang` al ON (a.`id_attribute` = al.`id_attribute`) LEFT JOIN `ps_attribute_group_lang` agl ON (ag.`id_attribute_group` = agl.`id_attribute_group`) INNER JOIN ps_attribute_shop attribute_shop ON (attribute_shop.id_attribute = a.id_attribute AND attribute_shop.id_shop = 1) WHERE pa.`id_product` = 1 AND al.`id_lang` = 1 AND agl.`id_lang` = 1 GROUP BY id_attribute_group, id_product_attribute ORDER BY ag.`position` ASC, a.`position` ASC, agl.`name` ASC The above code is executed when prestashop pulls your product attributes. Line 19 is where specify your product id. If you have access to SQL, execute the above code. If the attributes appear randomly then we can fix this by modifying the SQL otherwise the problem is nothing to do with prestashop but with something else other than core prestashop (could be your modules, but not sure) Link to comment Share on other sites More sharing options...
kpham501 Posted December 1, 2013 Author Share Posted December 1, 2013 where would i execute this sql code? Link to comment Share on other sites More sharing options...
ibndawood Posted December 1, 2013 Share Posted December 1, 2013 Execute this sql code on your prestashop database. Link to comment Share on other sites More sharing options...
kpham501 Posted December 2, 2013 Author Share Posted December 2, 2013 I mean where in Prestashop would I apply this code? a tpl file? or somewhere else? Link to comment Share on other sites More sharing options...
vekia Posted December 2, 2013 Share Posted December 2, 2013 i think that before you will modify core, you have to test code above in database manager like phpmyadmin Link to comment Share on other sites More sharing options...
ibndawood Posted December 2, 2013 Share Posted December 2, 2013 (edited) Yes, please use phpadmin (or any other database client) and check what the above SQL returns. Execute the query more than once and see if the results are same everytime. If the results are same then it means that prestashop core pulls the attributes in the same way everytime and its only in the middle that the order gets mixed up. Edited December 2, 2013 by ibndawood (see edit history) Link to comment Share on other sites More sharing options...
kpham501 Posted December 2, 2013 Author Share Posted December 2, 2013 I ran the sql code from above. The results on 3 executions were 3 different results 0, 0, 16, 16, 8, 8, 24, 24 0, 0, 16, 8, 8, 16, 24, 24 0, 0, 8, 16, 16, 8, 24, 24 Link to comment Share on other sites More sharing options...
ibndawood Posted December 2, 2013 Share Posted December 2, 2013 That explains the random sorting of attributes. Let me check if we can fix this by sorting the array instead of overriding core SQL. I will get back to you in a moment. Link to comment Share on other sites More sharing options...
vekia Posted December 3, 2013 Share Posted December 3, 2013 maybe asort ? but this will affect core Link to comment Share on other sites More sharing options...
ibndawood Posted December 3, 2013 Share Posted December 3, 2013 (edited) Ok this is what I am going to suggest : 1. Paste this file in /override/controllers/front/ ProductController.php 2. Go to /cache folder and delete the cache_index.php file 3. Now try viewing the product. It should be sorted. I have used natsort (since your attributes are alphanumerical) instead of usort as suggested by vekia. I tested this code on 1.5.6.1. Let me know if this works. Edited December 3, 2013 by ibndawood (see edit history) 1 Link to comment Share on other sites More sharing options...
kpham501 Posted December 3, 2013 Author Share Posted December 3, 2013 Works great! Thank you. I appreciate the help. Link to comment Share on other sites More sharing options...
sparhawk Posted February 5, 2014 Share Posted February 5, 2014 (edited) Hello ibndawood, thanks for your modification for sort attributes (file /override/controllers/front/ProductController.php) Modification works great but now I encountered a problem. When in the administration in Preferences \ Product switch Display unavailable product attributes on the product page to NO I dont see attributes Size and Color but I see twice the same color attributes. When the switch is in the administration Display unavailable product attributes on the product page to Yes I see the attribute Size and Color. Could you please advise me how to debug this ? thank you in advance Edited February 7, 2014 by sparhawk (see edit history) Link to comment Share on other sites More sharing options...
ibndawood Posted February 7, 2014 Share Posted February 7, 2014 Hello, I am not able to visualize your problem. You can help me with screenshots and I will see if this problem is a bug or occured because of the override code. Thanks 1 Link to comment Share on other sites More sharing options...
PrestaShark Posted February 25, 2014 Share Posted February 25, 2014 It works perfektly at 1.5.6.2! Your piece of code should be added to the official package!!! This sort alphanumerical values like L, XL, XXL and 41, 42, 43, 44 out from the box! Link to comment Share on other sites More sharing options...
mackooo Posted April 3, 2014 Share Posted April 3, 2014 Hello, I am not able to visualize your problem. You can help me with screenshots and I will see if this problem is a bug or occured because of the override code. Thanks How to sort the admin panel? Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now