lfischer

G-Star - Basket

Nov 19th, 2018
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function productsInShoppingbag(){
  2.     function stripSize(str, m, i) { return str.split(m, i).join(m); }
  3.     var products = [];
  4.     var productsTransaction = {{DL - GoogleTagParameters}};
  5.     var checkType = typeof(productsTransaction["ecomm_prodid"]);
  6.  
  7.     if(checkType == "string")
  8.     {
  9.       //1 PRODUCT
  10.       var productlength = 1;
  11.       var id = productsTransaction["ecomm_prodid"];
  12.       var splitId= id.split('-');
  13.       splitId.pop();
  14.       var newId = splitId.join('-');
  15.       products.push({
  16.                   id: newId,
  17.                   price: productsTransaction["ecomm_totalvalue"],
  18.                   quantity: 1
  19.                   });
  20.     }
  21.     else
  22.     {
  23.       //MULTIPLE PRODUCTS
  24.       var productlength = productsTransaction["ecomm_prodid"].length;
  25.       for (var i = 0; i < productlength; i++)
  26.       {
  27.         var id = productsTransaction["ecomm_prodid"][i];
  28.         var splitId= id.split('-');
  29.         splitId.pop();
  30.         var newId = splitId.join('-');
  31.         products.push({
  32.                   id: newId,
  33.                   price: productsTransaction["ecomm_totalvalue"]/productlength,
  34.                   quantity: 1
  35.                   });
  36.       }
  37.     }
  38.     return products;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment