Developer forum

Forum » Swift » Product numbers with special characters

Product numbers with special characters

Didzis Kuzmans
Reply

Hello.

I have seen few solutions where we have products with comma, dot, white-space and some other characters in product numbers.

Because of that, there are 2 Swift features which doesn't work:

"Add to favorites list" button and "Add to quote cart" button.

In both templates, product numbers are used in html ID attribute which is used in javascript functions which leads to javascript errors.

 

I fixed this issue in the way that javascript will work with invalid IDs:


document.querySelector("#"+e)

document.querySelector('[id="'+ e +'"]')

 

But now i'm thinking that better way would be to fix it in a way that these ID in html won't have any whitespaces or other invalid characters. 


Replies

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

Yeah - those kind of IDs are always causing issues. So better clean the IDs as part of the integration.

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

For those looking to fix this themselves, you also need to update the code for the favorite button or otherwise the heart icon won't reflect the latest status. Here's what I changed in _favorites.js:

var clickedButton = e.currentTarget != undefined ? e.currentTarget : document.querySelector('#' + e);
var form = e.currentTarget != undefined ? clickedButton.closest('form') : document.querySelector('#' + e);
...
var productButton = document.querySelector('#FavoriteBtn_' + productId + variantId);


became

var clickedButton = e.currentTarget != undefined ? e.currentTarget : document.querySelector('[id="'+ e +'"]');
var form = e.currentTarget != undefined ? clickedButton.closest('form') : document.querySelector('[id="'+ e +'"]');
...
var productButton = document.querySelector('[id="FavoriteBtn_' + productId + variantId + '"]');

Cheers,

Imar

 

 

 
Didzis Kuzmans
Reply

Changing product IDs is not always solution when we are working with existing BC integrations.

And these are frontend javascript errors. We don't actually need product ids in code where we get these javascript errors. 

There can be way different identifiers, example, "paragraphxproducty".

In 1.19 I fixed this in html with .Replace(" ","") function in multiple lines without adding any javascript changes.

 

 

You must be logged in to post in the forum