Liquid, JavaScript, themes, sales channels
Hi all,
I'm struggling to add an additional product to cart via API, but it's not working. The scenario has been already discussed because it's the classic embroidery that should be added to a main product when a checkbox is checked.
I've created the embroidery product and the line properties that should send the information like text and color of the embroidery to the cart. Everything works fine BUT the embroidery product is not added. I don't get any error, the product is simply not added.
This is my code:
$('.add-to-cart').on('click', function(e){
e.preventDefault();
if( $('#personalize').prop("checked") == true ){
$.ajax({
type: "POST",
url: '/cart/add.js',
data: {quantity: 1,id: 39332170301484}, //this is the variant id of my product
dataType: "json",
success: function(data) {
$('.product-single__form').submit();
},
error: function() {
alert('error');
}
});
} else {
$(this).parents('form').submit();
}
});
Solved! Go to the solution
This is an accepted solution.
Thank you for your reply. Actually it was just a class written in a wrong way. This happens when you have looked at a code so many times that you no longer see the details. 😉
Hi,
The ajax call itself is okay. Are you sure you trigger that call correctly on the site you are building, did you debug that part?
Also, the problem can be in calling 2x add.js in a short period of time. Better option would be if you dynamically build the ajax call based on checkbox, and trigger 1 ajax call with both products together if the checkbox is checked.
This is an accepted solution.
Thank you for your reply. Actually it was just a class written in a wrong way. This happens when you have looked at a code so many times that you no longer see the details. 😉
Hi @Jeeg
Your ajax call is fine. for more theme customization and also this issue to resolve you can hire me I'll work for you. If you want contact with us on skype (cid.6072cc42f2bf365c).
Thanks
Portrait of Stephen positioned next to an image of planet Earth, with the Stephen's World ...
By JasonH Mar 18, 2024Digital marketers and app developers have tracked activity in apps and websites for yea...
By Ollie Mar 13, 2024February was an exciting month with Shopify Editions, informative webinars, and more! F...
By JasonH Mar 7, 2024