Adding product to cart via API

Solved
Jeeg
Tourist
8 1 4

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();
    }
  });

 

 

0 Likes
VedranD
New Member
3 0 0

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. 

 

 

 

0 Likes
LuckyNigam
Excursionist
34 2 6

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

0 Likes
Jeeg
Tourist
8 1 4

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.

0 Likes