I have 3 drop down boxes on my products page and want to add the selected items on to the orderline when the add to cart button is clicked then show the selected items in the cart but I can get it to appear in the cart. I'm not sure weather the selected items arn't being added into the orderline or I just can't get them out. Can anyone help me here
my javascript add to cart in teaCommerce_Advanced code is
jQuery('.productAddToCart').live('click', function () { var jQEle = jQuery(this);
/* If the product allready have a pending add to cart running we do not want to make another one. in principle you could easily make the call again. This is just for demo purposes. You can make as many calls to the server as you like. */ if (!jQEle.parent().hasClass('updating')) { jQEle.parent().addClass('updating');
//Get the various elements and variables var product = jQEle.closest('.productToUpdate'), addingTxt = jQEle.attr('addingtxt'), quantityInput = product.find('input.quantity'), quantity = quantityInput[0] ? quantityInput.val() : 1, material = product.find('productMaterial'), productMaterial = material.option[material.selectedIndex].value, colour = product.find('productColour'), productColour = colour.options[colour.selectedIndex].value, finish = product.find('productFinish'), productFinish = finish.options[finish.selectedIndex].value, variant = product.find('select.productVariants'), productid = variant[0] ? variant.val() : product.attr('productid'), localSubmitTimer = new Date().getTime(); jQEle.attr('standardValue', jQEle.val()).val(addingTxt).attr('standardValue'); /* Add orderline is called using the Tea Commerce javascript API We subscribe to the return events to be able to update the css class of the button. */ TeaCommerce.addOrderLine(productid, quantity, properties, productMaterial, productColour, productFinish, { async: true, successfn: function (data) { //A timeout is set to show the user that the product has been added removeAddButtonUpdate(jQEle, localSubmitTimer); }, errorfn: function (data) { //Something went wrong. We should handle it here removeAddButtonUpdate(jQEle, localSubmitTimer); } }); } return false; });
You can always check you order from firebug (using FireFox) and see what data you have. Just type "TeaCommerce.getOrder()" and you have the json to check - there you should be able to see what orderlines you have. Do you have them? If not we should look more into the code that should add the orderlines.
Your server side fallback code looks okay, but I think your javascript code is where the error is. You can also debug this using firebug :)
material =product.find('productMaterial'), productMaterial =material.option[material.selectedIndex].value,
The product.find will be empty because you dont select by class or id. And productMaterial wont have anything because the material (jQuery object) doesnt have an option property. Remember that there is a different between javascript objects and jQuery objects.
Cheers I have just firebug the javascript code and as you said the productMaterial value isn't there so changed the code to below code but this still isn't picking up the value is teh syntax still wrong or do I need to add any other code
jQuery('.productAddToCart').live('click', function () { var jQEle = jQuery(this);
/* If the product allready have a pending add to cart running we do not want to make another one. in principle you could easily make the call again. This is just for demo purposes. You can make as many calls to the server as you like. */ if (!jQEle.parent().hasClass('updating')) { jQEle.parent().addClass('updating');
//Get the various elements and variables var product = jQEle.closest('.productToUpdate'), addingTxt = jQEle.attr('addingtxt'), quantityInput = product.find('input.quantity'), quantity = quantityInput[0] ? quantityInput.val() : 1, material = product.find('select.productMaterial'), productMaterial = material[0] ? material.val(), variant = product.find('select.productVariants'), productid = variant[0] ? variant.val() : product.attr('productid'), localSubmitTimer = new Date().getTime();
jQEle.attr('standardValue', jQEle.val()).val(addingTxt).attr('standardValue'); /* Add orderline is called using the Tea Commerce javascript API We subscribe to the return events to be able to update the css class of the button. */ TeaCommerce.addOrderLine(productid, quantity, material, { async: true, successfn: function (data) { //A timeout is set to show the user that the product has been added removeAddButtonUpdate(jQEle, localSubmitTimer); }, errorfn: function (data) { //Something went wrong. We should handle it here removeAddButtonUpdate(jQEle, localSubmitTimer);
Its hard to saw when i cant see your markuo and test using firebug. But you should try and insert break points and walk through your code and see where it doesnt fetch the correct values or elements.
I have debugged the code and getting the correct values in the pop ups with the the code below in teaCommerce_Advanced.js jQuery('.productAddToCart').live('click', function ()
I have add the variables into the TeaCommerce.addOrderLine function with code below
TeaCommerce.addOrderLine(productid, quantity, productMaterial, productColour, productFinish, { async: true, successfn: function (data) { //A timeout is set to show the user that the product has been added removeAddButtonUpdate(jQEle, localSubmitTimer); }, errorfn: function (data) { //Something went wrong. We should handle it here removeAddButtonUpdate(jQEle, localSubmitTimer); } });
And in teaCommerce_unpacked.js TeaCommerce.addOrderLine = function
I have added the 3 variables but not even getting the test popup appear so was wondering if I have missed a step somewhere
First of - you shouldnt change the Tea Commerce javascript files - the teacommerce.js and the unpacked one. These is for Tea Commerce and could be updated in later versions.
Ah ok didn't realise that so have now realised I can't add more variables to pass to the javascript api I have tried adding all the ids i want to pass into the productid variable dividing them up with an _ symbol then split them up when i want to pull out the individual id's. I have written the following code to do this which works fine and brings back all the ids when i debug the code e.g 1079_1121_1135_1142 but get the error the input is a string and is looking for an int32 value is this something I can get round or do I need to rethink my method
As i read it, all you want to do is ad three custom properties to the orderline when you add it to the cart. You can do that in the settings parameter you send to the addOrderLine method. More specificly the "properties" setting.
/* If the product allready have a pending add to cart running we do not want to make another one. in principle you could easily make the call again. This is just for demo purposes. You can make as many calls to the server as you like. */ if(!jQEle.parent().hasClass('updating')){ jQEle.parent().addClass('updating');
//Get the various elements and variables varproduct =jQEle.closest('.productToUpdate'), addingTxt =jQEle.attr('addingtxt'), quantityInput =product.find('input.quantity'), quantity =quantityInput[0]?quantityInput.val():1, material =product.find('select.productMaterial'), productMaterial =material[0]?material.val(), variant =product.find('select.productVariants'), productid =variant[0]?variant.val():product.attr('productid'), localSubmitTimer =newDate().getTime();
jQEle.attr('standardValue',jQEle.val()).val(addingTxt).attr('standardValue'); var properties = { 'productMaterial': productMaterial,
'variant': variant,
'nextpropKey': nextPropValue
} /* Add orderline is called using the Tea Commerce javascript API We subscribe to the return events to be able to update the css class of the button. */ TeaCommerce.addOrderLine(productid,quantity, { async:true, properties: properties, successfn:function(data){ //A timeout is set to show the user that the product has been added removeAddButtonUpdate(jQEle,localSubmitTimer); }, errorfn:function(data){ //Something went wrong. We should handle it here removeAddButtonUpdate(jQEle,localSubmitTimer); }
I added a properties object and again added that to the settings.
Cheers for the advise I have changed my code as below my first alert statment outputs the value for productMaterial, productColour, and productFinish as expected my second alert outputs [object Object] is that right but when i debug the code in firebug I still don't see the 3 custom properties
jQuery('.productAddToCart').live('click', function () { var jQEle = jQuery(this); /* If the product allready have a pending add to cart running we do not want to make another one. in principle you could easily make the call again. This is just for demo purposes. You can make as many calls to the server as you like. */ if (!jQEle.parent().hasClass('updating')) { jQEle.parent().addClass('updating');
//Get the various elements and variables var product = jQEle.closest('.productToUpdate'), addingTxt = jQEle.attr('addingtxt'), quantityInput = product.find('input.quantity'), quantity = quantityInput[0] ? quantityInput.val() : 1, material = product.find('select.productMaterial'), productMaterial = material[0] ? material.val() : 1, colour = product.find('select.productColour'), productColour = colour[0] ? colour.val() : 1, finish = product.find('select.productFinish'), productFinish = finish[0] ? finish.val() : 1, variant = product.find('select.productVariants'), productid = variant[0] ? variant.val() : product.attr('productid'), //productid = product.attr('productid')+"_"+productMaterial+"_"+productColour+"_"+productFinish; localSubmitTimer = new Date().getTime(); jQEle.attr('standardValue', jQEle.val()).val(addingTxt).attr('standardValue'); alert(productMaterial + " " + productColour + " " + productFinish); var properties = {'productMaterial': productMaterial, 'productColour': productColour, 'productFinish': productFinish }; alert(properties); /* Add orderline is called using the Tea Commerce javascript API We subscribe to the return events to be able to update the css class of the button. */ TeaCommerce.addOrderLine(productid, quantity, { async: true, properties: properties, successfn: function (data) { //A timeout is set to show the user that the product has been added removeAddButtonUpdate(jQEle, localSubmitTimer); }, errorfn: function (data) { //Something went wrong. We should handle it here removeAddButtonUpdate(jQEle, localSubmitTimer); } }); } ; return false; });
Cheers for the quick response just tested that and get the values expected for the 3 properties in the alert boxes but when i check in firebug they arn't there I get the following
What properties do you have in your generel settings of Tea Commerce? If you have the productMaterial in your "Order line property aliases" this is why you cant add it. We check at the server for these reserved names so people using javascript cant just overwrite your values.
razor custom properties
I have 3 drop down boxes on my products page and want to add the selected items on to the orderline when the add to cart button is clicked then show the selected items in the cart but I can get it to appear in the cart. I'm not sure weather the selected items arn't being added into the orderline or I just can't get them out. Can anyone help me here
on my products page I have the following code
my cart code is
my javascript add to cart in teaCommerce_Advanced code is
jQuery('.productAddToCart').live('click', function () {
var jQEle = jQuery(this);
/*
If the product allready have a pending add to cart running
we do not want to make another one.
in principle you could easily make the call again. This
is just for demo purposes. You can make as many calls to
the server as you like.
*/
if (!jQEle.parent().hasClass('updating')) {
jQEle.parent().addClass('updating');
//Get the various elements and variables
var product = jQEle.closest('.productToUpdate'),
addingTxt = jQEle.attr('addingtxt'),
quantityInput = product.find('input.quantity'),
quantity = quantityInput[0] ? quantityInput.val() : 1,
material = product.find('productMaterial'),
productMaterial = material.option[material.selectedIndex].value,
colour = product.find('productColour'),
productColour = colour.options[colour.selectedIndex].value,
finish = product.find('productFinish'),
productFinish = finish.options[finish.selectedIndex].value,
variant = product.find('select.productVariants'),
productid = variant[0] ? variant.val() : product.attr('productid'),
localSubmitTimer = new Date().getTime();
jQEle.attr('standardValue', jQEle.val()).val(addingTxt).attr('standardValue');
/*
Add orderline is called using the Tea Commerce javascript API
We subscribe to the return events to be able to update the
css class of the button.
*/
TeaCommerce.addOrderLine(productid, quantity, properties, productMaterial, productColour, productFinish,
{
async: true,
successfn: function (data) {
//A timeout is set to show the user that the product has been added
removeAddButtonUpdate(jQEle, localSubmitTimer);
},
errorfn: function (data) {
//Something went wrong. We should handle it here
removeAddButtonUpdate(jQEle, localSubmitTimer);
}
});
}
return false;
});
Hi Phil
You can always check you order from firebug (using FireFox) and see what data you have. Just type "TeaCommerce.getOrder()" and you have the json to check - there you should be able to see what orderlines you have. Do you have them? If not we should look more into the code that should add the orderlines.
Kind regards
Anders
Cheers for the quick response how do i use firebug to check the order
Use the console and write the "TeaCommerce.getOrder()" in it when you have tried to add the products to the cart to see what the order now contains
Kind regards
Anders
Cheers just had a look and its not in the json string can you see anything i have missed in my code above
Hi Phil
Your server side fallback code looks okay, but I think your javascript code is where the error is. You can also debug this using firebug :)
material =product.find('productMaterial'),
productMaterial =material.option[material.selectedIndex].value,
The product.find will be empty because you dont select by class or id. And productMaterial wont have anything because the material (jQuery object) doesnt have an option property. Remember that there is a different between javascript objects and jQuery objects.
Kind regards
Anders
Cheers I have just firebug the javascript code and as you said the productMaterial value isn't there so changed the code to below code but this still isn't picking up the value is teh syntax still wrong or do I need to add any other code
Hi Phil
Its hard to saw when i cant see your markuo and test using firebug. But you should try and insert break points and walk through your code and see where it doesnt fetch the correct values or elements.
Kind regards
Anders
I have debugged the code and getting the correct values in the pop ups with the the code below in teaCommerce_Advanced.js jQuery('.productAddToCart').live('click', function ()
alert(productMaterial);
alert(productColour);
alert(productFinish);
I have add the variables into the TeaCommerce.addOrderLine function with code below
TeaCommerce.addOrderLine(productid, quantity, productMaterial, productColour, productFinish,
{
async: true,
successfn: function (data) {
//A timeout is set to show the user that the product has been added
removeAddButtonUpdate(jQEle, localSubmitTimer);
},
errorfn: function (data) {
//Something went wrong. We should handle it here
removeAddButtonUpdate(jQEle, localSubmitTimer);
}
});
And in teaCommerce_unpacked.js TeaCommerce.addOrderLine = function
I have added the 3 variables but not even getting the test popup appear so was wondering if I have missed a step somewhere
TeaCommerce.addOrderLine = function (nodeId, quantity, productMaterial, productColour, productFinish, settings) {
alert('test');
settings = tcs.fixSettings(settings);
var parameters = [nodeId, quantity, productMaterial, productColour, productFinish],
formData = settings.properties;
tcs.fireCartUpdating({ 'Caller': 'addOrderLine', 'parameters': parameters, 'formData': formData });
return tcs.callBase('AddOrderLine', parameters, formData, settings.async, function (data) {
tcs.fireCartUpdated(data, settings.successfn);
}, function (data) {
tcs.fireCartUpdateError(data, settings.errorfn);
});
};
Hi Phil
First of - you shouldnt change the Tea Commerce javascript files - the teacommerce.js and the unpacked one. These is for Tea Commerce and could be updated in later versions.
Have you read the documentation for the javascript parts so you know how it works?
http://www.teacommerce.dk/en/documentation.aspx
Kind regards
Anders
Ah ok didn't realise that so have now realised I can't add more variables to pass to the javascript api I have tried adding all the ids i want to pass into the productid variable dividing them up with an _ symbol then split them up when i want to pull out the individual id's. I have written the following code to do this which works fine and brings back all the ids when i debug the code e.g 1079_1121_1135_1142 but get the error the input is a string and is looking for an int32 value is this something I can get round or do I need to rethink my method
Hi Phil,
As i read it, all you want to do is ad three custom properties to the orderline when you add it to the cart. You can do that in the settings parameter you send to the addOrderLine method. More specificly the "properties" setting.
What you want to do is something like this.
I added a properties object and again added that to the settings.
/Rune
Cheers for the advise I have changed my code as below my first alert statment outputs the value for productMaterial, productColour, and productFinish as expected my second alert outputs [object Object] is that right but when i debug the code in firebug I still don't see the 3 custom properties
Hi Phil,
You're doing it right now. [object Object] is what we're aiming for here. You can check the values like this:
alert(properties.productMaterial);
/Rune
Cheers for the quick response just tested that and get the values expected for the 3 properties in the alert boxes but when i check in firebug they arn't there I get the following
Ok. Try to go totally basic on the problem.
Open the firebug console and insert the following code (with the node id of one of your own nodes)
TeaCommerce.addOrderLine([the node id], 1, {properties: {test: 'value'}});
Then make this call:
TeaCommerce.getOrder()
Now click on the green "Object..." response and start inspecting the order. Check if the "test" property have been added to the orderline.
This video also shows a bit about how to debug the code :)
http://www.youtube.com/watch?v=onhSnpIQ-xo
/Rune
TeaCommerce.addOrderLine([1079], 1, {properties: {test: 'value'}});
TeaCommerce.getOrder()
Works fine i get test and value in the dom and appears in the json string in my cart
but when i try
TeaCommerce.addOrderLine([1079], 1, {properties: {productMaterial: 'value'}});
TeaCommerce.getOrder()
doesn't work i don't get another property in the dom or json string
Hi Phil
What properties do you have in your generel settings of Tea Commerce? If you have the productMaterial in your "Order line property aliases" this is why you cant add it. We check at the server for these reserved names so people using javascript cant just overwrite your values.
Kind regards
Anders
The [] are not supposed to be there. They where just to show you where to put the id of the node. So right now it won't work in all browsers :)
/Rune
Thanks its working now I had the 3 aliases in the Tea Commerce Orderline property aliases cheers for all your help
Fantastic. Please check Anders' answer as the right answer, so others can see it when they come by this post :)
And feel free to write again, if you run into more problems.
/Rune
This is working fine for 1 or more products with the same 3 properties but if i want to say add
product 1 with properties material leather, colour red, finish wood
then add
product 1 with properties material cloth, colour blue, finish metal
In my shopping cart i get product 1 with quantity 2 and 1 set of properties
Is there a way I get it to display the second product 1 as a second item and show both properties
Yes, that is a whole other problem. What you want to use is unique orderlines. You will need to add the orderlines with this method instead:
http://rune.gronkjaer.dk/en-US/2010/11/16/tea-commerce-javascript-api/#addUniqueOrderLine
Note that you will then have to make a few changes in the cart flow to update a unique order line instead of a normal one.
/Rune
is working on a reply...