I am setting up a variable in GTM to return a count of the number of sizes in-stock (regardless of the color).
In the example below (pulled from the dataLayer) there are 2 colors and 2 sizes for each color (total of 4 sizes). But, the first size is out of stock. So, in this case the output would be 3, since 3 of the 4 sizes are in stock.
How would I set up the JS to make this work?
I really appreciate the help!
{
"product": {
"variants": [
{
"colorID": "03",
"colorName": "MEDIUM DENIM",
"sizes": [
{
"sizeID": "10",
"sizeName": "33",
"available": "false",
"price": "24.0"
},
{
"sizeID": "1",
"sizeName": "24",
"available": "true",
"price": "24.0"
}
]
},
{
"colorID": "06",
"colorName": "LIGHT DENIM",
"sizes": [
{
"sizeID": "1",
"sizeName": "24",
"available": "true",
"price": "24.0"
},
{
"sizeID": "2",
"sizeName": "25",
"available": "true",
"price": "24.0"
}
]
}
]
}
}