how to read complex cookie data - jquery cookie
I have got to read and manipulate a cookie that looks like this:
cookiename = 9918430821007~12.00 | 7C9918430831006~3.00 | 7C7501031311309~50.30
The above cookie has 3 values, each separated by "|" Each value is separated by a "~"
The first item(9918430821007) represents a unique product id The second (12.00) represents the amount in usd
I am stuck in the following:
How do i check if the product ID exist when adding a product to a shopping cart(to prevent duplicate entries)?
I have got to make a total $ of all usd values, how to make the total of all these amout pairs (12.00,3.00,50.30..etc)
FYI i am using jquery 1.72 + jquery.cookie.js
Any help would much be appreciated
How about something like this ?
var Products = $.cookie('cookiename').split(' | ') // Products= ['9918430821007~12.00', '7C9918430831006~3.00', '7C7501031311309~50.30']
You could then do this:
Products.split('~') // 9918430821007 Products.split('~') // 12.00
...or something of that sort. Hope this helps!