Jump to content

Multiple product variants in the URL


alkotronikk

Recommended Posts

Hello,

I currently found a bug on my prestashop site, that sometimes causes customer to add to cart a product variant that was not selected. The URL part after # that is used to change to reflect the selected product attributes is listing duplicate attributes.

So instead of #/01-color-green/03-size-l I get #/01-color-green/01-color-green/02-size-m/03-size-l at the end of the URL, so the add to cart sometimes chooses the bad variant.

These duplicates are constant for every product, so when there are more options in the example above, it could look like #/04-color-green/01-color-green/03-size-l/03-size-l or #/01-color-green/01-color-green/04-size-m/03-size-l. When I select the item that's being added as a duplicate, it would result in: #/01-color-green/01-color-green/03-size-l/03-size-l.

Naturally I assume that it should be having only the selected value in the URL, so I want it to be like this: #/01-color-green/03-size-l.

Any suggestions or help appreciated.

Link to comment
Share on other sites

So I tracked the issue down to the /themes/default-bootstrap/js/product.js file to this part (lines 982-984):

$('#attributes select, #attributes input[type=hidden], ' + radio_inputs).each(function(){
	tab_attributes.push($(this).val());
});

For whatever reason, it selects and pushes to the tab_attributes array extra inputs that are not selected. There are two inputs for every attribute, so if I have 2 products, there are 4 items in the tab_attributes array, and the third and fourth item are correct.

Link to comment
Share on other sites

Since the issue was having duplicities, with the wrong ones stored in the tab_attributes in the first half of an array, I kinda solved the issue by removing the first half of an array. It's a horrible hack and I'm still looking for elegant solution. Anyways, if anyone is interested, here's the code that solved that for me:

//horrible hack to cut the first half of an array
tab_attributes = tab_attributes.slice(tab_attributes.length / 2);

I do not recommend using this, but it's a late weekend night and I'm too tired to keep trying.

Link to comment
Share on other sites

  • 2 years later...

Have you found a better and more versatile solution for this?

I have clothes with Sizes and Colors in my shop, and somehow whenever i change the variant, all sizes get selected in the url, and further is my standard variant ignored when first entering the product detail page

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