Forum Moderators: open
This is the javascript, suggested by Microsoft, that should be in my payment method page:
<!–Begin cashback Tracking Pixel Code -->
<script type='text/javascript'>
<!--
var jf_merchant_id = „YOUR_CASHBACK_SHOPPING_HASHED_MERCHANT_ID?;
var jf_merchant_order_num = 'ORDER_NUMBER';
var jf_purchased_items = new Array();
// adding cart items
FOR EACH PURCHASED ITEM...
// add cart item
var jf_item = new Object();
jf_item.mpi = 'ITEM_PRODUCT_ID';
jf_item.price = 'ITEM_PRICE';
jf_item.quantity = ITEM_QUANTITY;
jf_purchased_items.push (jf_item);
NEXT PURCHASED ITEM
//-->
</script>
<script type='text/javascript' src= 'https://ssl.bing.com/cashback/javascripts/1x1tracking.js'>
</script>
<!--End cashbackTracking Pixel Code -->
This is the modified code, given to me by my hosting company, that needs to be fixed up:
<!–Begin cashback Tracking Pixel Code -->
<script type='text/javascript'>
<!--
var jf_merchant_id = 'YOUR_CASHBACK_SHOPPING_HASHED_MERCHANT_ID?';
var jf_merchant_order_num = '<%Order.Number%>';
var jf_purchased_items = new Array();
// product information data
var data = <%Order.ProductsObject%>;
// adding cart items
for (var i = 0; i < data.products.length; i++) {
var jf_item = new Object();
jf_item.mpi = data.products[i].id;
jf_item.price = data.products[i].itemPrice;
jf_item.quantity = data.products[i].quantity;
// add cart item
jf_purchased_items.push (jf_item);
}
//-->
</script>
<script type='text/javascript' src= 'https://ssl.bing.com/cashback/javascripts/1x1tracking.js'>
</script>
<!--End Cashback Tracking Pixel Code -->
This is an example, from Microsoft, of what the order confirmation page (output of above code)should have on a multiple item order:
<script type='text/javascript'>
<!--
var jf_merchant_id = „YOUR_CASHBACK_SHOPPING_HASHED_MERCHANT_ID?';
var jf_merchant_order_num = 'A9812753';
var jf_purchased_items = new Array();
// adding cart items
// add cart item
var jf_item = new Object();
jf_item.mpi = '85343';
jf_item.price = '42.50';
jf_item.quantity = 1;
jf_purchased_items.push( jf_item);
// add cart item
var jf_item = new Object();
jf_item.mpi = '78426';
jf_item.price = '52.40';
jf_item.quantity = 4;
jf_purchased_items.push( jf_item);
// add cart item
var jf_item = new Object();
jf_item.mpi = '25907';
jf_item.price = '20.45';
jf_item.quantity = 1;
jf_purchased_items.push( jf_item);
// -->
</script>
<script type='text/javascript' src= 'https://ssl.bing.com/cashback/javascripts/1x1tracking.js'>
</script>
And finally, here is what I get with my modified javascript on a multi item order:
<script type='text/javascript'>
<!--
var jf_merchant_id = 'YOUR_CASHBACK_SHOPPING_HASHED_MERCHANT_ID?';
var jf_merchant_order_num = '22272';
var jf_purchased_items = new Array();
// product information data
var data = {products : [{id : '290652', name : 'Belkin 6\' 3.5mm Stereo Audio Cable - Male To Male (F8V203-06GLD-AP)', partNumber : 'F8V203-06GLD-AP', mfgPartNumber : 'F8V203-06GLD-AP', quantity : '1', itemPrice : '8.29', totalPrice : '8.29' },{id : '321207', name : 'Motorola Talkabout GMRS\/FRS 2-Way Radios With 20-Mile Range (EM1000R)', partNumber : 'EM1000R', mfgPartNumber : 'EM1000R', quantity : '1', itemPrice : '44.09', totalPrice : '44.09' }]};
// adding cart items
for (var i = 0; i < data.products.length; i++) {
var jf_item = new Object();
jf_item.mpi = data.products[i].id;
jf_item.price = data.products[i].itemPrice;
jf_item.quantity = data.products[i].quantity;
// add cart item
jf_purchased_items.push (jf_item);
}
//-->
</script>
<script type='text/javascript' src= 'https://ssl.bing.com/cashback/javascripts/1x1tracking.js'>
</script>
The "product information data" does seem to be getting the info, but it is not putting it into the locations it needs to be in. ie:
jf_item.mpi = data.products[i].id;
jf_item.price = data.products[i].itemPrice;
jf_item.quantity = data.products[i].quantity;
The script is really close but not quite there yet. Please help!
var data = {products : [{id : '290652', name : 'Belkin 6\' 3.5mm Stereo Audio Cable - Male To Male (F8V203-06GLD-AP)', partNumber : 'F8V203-06GLD-AP', mfgPartNumber : 'F8V203-06GLD-AP', quantity : '1', itemPrice : '8.29', totalPrice : '8.29' },{id : '321207', name : 'Motorola Talkabout GMRS\/FRS 2-Way Radios With 20-Mile Range (EM1000R)', partNumber : 'EM1000R', mfgPartNumber : 'EM1000R', quantity : '1', itemPrice : '44.09', totalPrice : '44.09' }]};
According to the example code, though, it looks like it should be an integer value:
jf_item.quantity = 1;
Perhaps try this:
jf_item.quantity = parseInt(data.products[i].quantity, 10);
Here's an example that might clarify things:
var x = "1";
var y = "2";
var z = x + y; // z will be the string "12"
var a = 1;
var b = 2;
var c = a + b; // c will be the number 3
z = parseInt(x, 10) + parseInt(y, 10); // z will be the number 3
Let's take the "product id" from my modified script for example. The javascript is clearly getting the product information it needs:
// product information data
var data = {products : [{id : '290652', ...
but it will not put that product id below where it needs to go:
jf_item.mpi = data.products[i].id;
so, something about the "data.products[i].id" needs to change to see the "id : '290652'"
<html>
<head>
<title>Test</title>
</head>
<body>
<script type="text/javascript" src="http://yui.yahooapis.com/2.8.0r4/build/yahoo/yahoo-min.js"></script>
<script type="text/javascript" src="http://yui.yahooapis.com/2.8.0r4/build/json/json-min.js"></script>
<script type="text/javascript">
var jf_merchant_id = 'YOUR_CASHBACK_SHOPPING_HASHED_MERCHANT_ID?';
var jf_merchant_order_num = '22272';
var jf_purchased_items = new Array();
// product information data
var data = {
products : [
{
id : '290652',
name : 'Belkin 6\' 3.5mm Stereo Audio Cable - Male To Male (F8V203-06GLD-AP)',
partNumber : 'F8V203-06GLD-AP',
mfgPartNumber : 'F8V203-06GLD-AP',
quantity : '1',
itemPrice : '8.29',
totalPrice : '8.29'
},
{
id : '321207',
name : 'Motorola Talkabout GMRS\/FRS 2-Way Radios With 20-Mile Range (EM1000R)',
partNumber : 'EM1000R',
mfgPartNumber : 'EM1000R',
quantity : '1',
itemPrice : '44.09',
totalPrice : '44.09'
}
]
};
// adding cart items
for (var i = 0; i < data.products.length; i++) {
var jf_item = new Object();
jf_item.mpi = data.products[i].id;
jf_item.price = data.products[i].itemPrice;
jf_item.quantity = parseInt(data.products[i].quantity, 10);
// add cart item
jf_purchased_items.push (jf_item);
}
var str = "";
for (i = 0; i < jf_purchased_items.length; i++) {
str += YAHOO.lang.JSON.stringify(jf_purchased_items[i]);
str += "\n";
}
alert(str);
</script>
</body>
</html>
[edited by: Fotiman at 1:50 pm (utc) on Nov. 19, 2009]
<!–Begin cashback Tracking Pixel Code -->
<script type='text/javascript'>
<!--
var jf_merchant_id = 'YOUR_CASHBACK_SHOPPING_HASHED_MERCHANT_ID?';
var jf_merchant_order_num = '<%Order.Number%>';
var jf_purchased_items = new Array();
// product information data
var data = <%Order.ProductsObject%>;
// adding cart items
for (var i = 0; i < data.products.length; i++) {
var jf_item = new Object();
jf_item.mpi = data.products[i].id;
jf_item.price = data.products[i].itemPrice;
jf_item.quantity = data.products[i].quantity;
// add cart item
jf_purchased_items.push (jf_item);
}
//-->
</script>
<script type='text/javascript' src= 'https://ssl.bing.com/cashback/javascripts/1x1tracking.js'>
</script>
<!--End Cashback Tracking Pixel Code -->
When an order is placed the confirmation page gives this code:
<script type='text/javascript'>
<!--
var jf_merchant_id = 'YOUR_CASHBACK_SHOPPING_HASHED_MERCHANT_ID?';
var jf_merchant_order_num = '22272';
var jf_purchased_items = new Array();
// product information data
var data = {products : [{id : '290652', name : 'Belkin 6\' 3.5mm Stereo Audio Cable - Male To Male (F8V203-06GLD-AP)', partNumber : 'F8V203-06GLD-AP', mfgPartNumber : 'F8V203-06GLD-AP', quantity : '1', itemPrice : '8.29', totalPrice : '8.29' },{id : '321207', name : 'Motorola Talkabout GMRS\/FRS 2-Way Radios With 20-Mile Range (EM1000R)', partNumber : 'EM1000R', mfgPartNumber : 'EM1000R', quantity : '1', itemPrice : '44.09', totalPrice : '44.09' }]};
// adding cart items
for (var i = 0; i < data.products.length; i++) {
var jf_item = new Object();
jf_item.mpi = data.products[i].id;
jf_item.price = data.products[i].itemPrice;
jf_item.quantity = data.products[i].quantity;
// add cart item
jf_purchased_items.push (jf_item);
}
//-->
</script>
<script type='text/javascript' src= 'https://ssl.bing.com/cashback/javascripts/1x1tracking.js'>
</script>
So I guess my question is what do I need to change about the first code so that the second code will fill in the jf_item.mpi values?