Jump to content

Attributes sorting. Why is it random?


Recommended Posts

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

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

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 by ibndawood (see edit history)
Link to comment
Share on other sites

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 by ibndawood (see edit history)
  • Like 1
Link to comment
Share on other sites

  • 2 months later...

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 by sparhawk (see edit history)
Link to comment
Share on other sites

  • 3 weeks later...
  • 1 month 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...