Shopping Cart Items for Klaviyo

Les Girvan asked on January 26, 2022 11:10

Hi Guys,

Wondering if you can advise where I can add curly brackets to this method please, as each item in the shopping cart has to be wrapped inside a curly brackets

[{ {% foreach(cartitem in ECommerceContext.CurrentShoppingCart.CartProducts) { %}
"Product Name:"{% cartItem.SKU.SKUName#%}, 
"Item Price:"{% cartItem.UnitPrice#%}, 
"Quantity: "{% cartItem.SKUUnits#%}, 
"Row Total:"{% cartItem.TotalPrice#%}, 
"Image Path:"{% GetAbsoluteUrl(ECommerceContext.CurrentShoppingCart.ContentTable[0]SKU.SKUImagePath) #%}, 
"Product URL:"{% string.GetProductAbsoluteURL(cartItem.SKU.SKUID) %}, {%} #%}
    }
 ]

This code resolves as :

[{ 
"Product Name:"Siena Lady GTX Shoe: BRAUN - 6.5, 
"Item Price:"165.00, 
"Quantity: "1, 
"Row Total:"165.00, 
"Image Path:"https://domain.co.uk/getmetafile/7addc46f-51bb-473b-a3d6-8ba8696dee61/Meindl-Siena-Lady-GTX-Shoe.aspx, 
"Product URL:"https://domain.co.uk/Footwear/Walking-Shoes/Womens-Walking-Shoes/Meindl-Siena-Lady-GTX-Shoe, 
"Product Name:"M Switch Jacket: Cosmos - S, 
"Item Price:"103.99, 
"Quantity: "1, 
"Row Total:"103.99, 
"Image Path:"https://domain.co.uk/getmetafile/7addc46f-51bb-473b-a3d6-8ba8696dee61/Meindl-Siena-Lady-GTX-Shoe.aspx, 
"Product URL:"https://domain.co.uk/Clothing/Micro-Fleece-Tops/Mens-Micro-Fleece-Tops/Mountain-Equipment-Mens-Switch-Jacket, 
"Product Name:"Softie Expan 3: Azure/Black - LH, 
"Item Price:"99.00, 
"Quantity: "1, 
"Row Total:"99.00, 
"Image Path:"https://domain.co.uk/getmetafile/7addc46f-51bb-473b-a3d6-8ba8696dee61/Meindl-Siena-Lady-GTX-Shoe.aspx, 
"Product URL:"https://domain.co.uk/Backpack-Travel/Sleeping-Bags/Sleeping-Bags/Snugpak-Softie-Expansion-3-Azure-Black, 
    }
 ]

As you can see all items are wrapped inside one curly bracket, however the requirement for the Klaviyo services is that each item of the basket needs to be with its own curly bracket like:

[{ 
    "Product Name:"Siena Lady GTX Shoe: BRAUN - 6.5, 
    "Item Price:"165.00, 
    "Quantity: "1, 
    "Row Total:"165.00, 
    "Image Path:"https://domain.co.uk/getmetafile/7addc46f-51bb-473b-a3d6-8ba8696dee61/Meindl-Siena-Lady-GTX-Shoe.aspx, 
    "Product URL:"https://domain.co.uk/Footwear/Walking-Shoes/Womens-Walking-Shoes/Meindl-Siena-Lady-GTX-Shoe, 
}
{
    "Product Name:"M Switch Jacket: Cosmos - S, 
    "Item Price:"103.99, 
    "Quantity: "1, 
    "Row Total:"103.99, 
    "Image Path:"https://domain.co.uk/getmetafile/7addc46f-51bb-473b-a3d6-8ba8696dee61/Meindl-Siena-Lady-GTX-Shoe.aspx, 
    "Product URL:"https://domain.co.uk/Clothing/Micro-Fleece-Tops/Mens-Micro-Fleece-Tops/Mountain-Equipment-Mens-Switch-Jacket, 
}
{
    "Product Name:"Softie Expan 3: Azure/Black - LH, 
    "Item Price:"99.00, 
    "Quantity: "1, 
    "Row Total:"99.00, 
    "Image Path:"https://domain.co.uk/getmetafile/7addc46f-51bb-473b-a3d6-8ba8696dee61/Meindl-Siena-Lady-GTX-Shoe.aspx, 
    "Product URL:"https://domain.co.uk/Backpack-Travel/Sleeping-Bags/Sleeping-Bags/Snugpak-Softie-Expansion-3-Azure-Black, 
        }
     ]

I just cannot figure out where to place the brackets in the code to make this work, can you advise please?

Correct Answer

Les Girvan answered on January 26, 2022 11:41

To update you and anyone that it might help, I have figured out the location of the additional brackets now:

 [{ 
  {% foreach(cartitem in ECommerceContext.CurrentShoppingCart.CartProducts) 
  { %} {
    "Product Name:"{% cartItem.SKU.SKUName#%}, 
    "Item Price:"{% cartItem.UnitPrice#%}, 
    "Quantity: "{% cartItem.SKUUnits#%}, 
    "Row Total:"{% cartItem.TotalPrice#%}, 
    "Image Path:"{% GetAbsoluteUrl(ECommerceContext.CurrentShoppingCart.ContentTable[0]SKU.SKUImagePath) #%}, 
    "Product URL:"{% string.GetProductAbsoluteURL(cartItem.SKU.SKUID) %}, 
    }
    {%} #%}
        }
     ]
   }]);
0 votesVote for this answer Unmark Correct answer

   Please, sign in to be able to submit a new answer.