sultangilani Posted November 10, 2020 Share Posted November 10, 2020 (edited) I am trying to add new product to cart with ajax method and I would like to know that how am I able to save customization fields data into a product meta? What parameters should I use to save that data on ajax data parameter? So when I call the request it should add to cart with customization fields data. Here is my currrent code: $('.cart_data').click(function(){ var static_token = $('input[name=token]').val(); var id_product = $('input[name=id_product]').val(); var formActionAttribute_name_field = $("input[name=textField191]").attr("name"); var formActionAttribute_value_field = $('input[name=textField191]').val(); $.ajax({ type: 'POST', headers: { "cache-control": "no-cache" }, url: prestashop.urls.pages.cart, async: false, cache: false, dataType : "json", data: {'action': 'add-to-cart', 'add': 1, 'ajax': true, 'qty': 1, 'id_product': id_product, 'token': static_token, formActionAttribute_name_field: formActionAttribute_value_field}, success: function(jsonData,textStatus,jqXHR) { ajaxCart.updateCartInformation(jsonData, true); console.log(jsonData); } }); }); Thanks in Advance Edited November 10, 2020 by sultangilani (see edit history) Link to comment Share on other sites More sharing options...
JBW Posted November 10, 2020 Share Posted November 10, 2020 You have to submit the customization id ("id_customization") which has to be created first Link to comment Share on other sites More sharing options...
sultangilani Posted November 10, 2020 Author Share Posted November 10, 2020 (edited) Sorry not get your point. I just need to send new customization fields data on cart with product. Just give me a one solution that how am I put customization fields data in ajax like product_id. I think solution must be like this: data: {'action': 'add-to-cart', 'add': 1, 'ajax': true, 'qty': 1, 'id_product': id_product, 'token': static_token, 'id_customization': [217]}, But its not working Can you hel me how may I arrange it so it sends customization to cart? Edited November 10, 2020 by sultangilani (see edit history) Link to comment Share on other sites More sharing options...
JBW Posted November 11, 2020 Share Posted November 11, 2020 This is quite complex and I can't explain you the details as I'm selling a module adding customization directly into cart myself Link to comment Share on other sites More sharing options...
sultangilani Posted November 11, 2020 Author Share Posted November 11, 2020 (edited) I know I am close and I will figure this out soon. I know you are selling a product but I don't think you can't explain it here, The reason you are not sharing the solution because you need me to buy that which is not wrong. I need help in this because my client is waiting for it so he can left review and if I don't revise this thing then he may left negative review. Please help me with this. Here is my email: [email protected]. You can share the solution with me in here. I won't share it with anyone. I hope you will help me out with this Thanks Edited November 11, 2020 by sultangilani (see edit history) Link to comment Share on other sites More sharing options...
sultangilani Posted November 20, 2020 Author Share Posted November 20, 2020 Hello Users, The Prestashop users who are facing this kind of issue should look at this for once. I found a solution but as you know for save customization requires a refresh of the page, I tried a lot of things to make sure that the page not reloads but Prestashop makes it compulsory to reload the page for saving the fields data So, I conditioned the code that if fields are filled up then "refresh add to cart method calls" and if they are empty then the "ajax add to cart method calls". I know its not a complete solution but it works for me. setInterval(function(){ var product_customization_id = $('#product_customization_id').val(); if(product_customization_id == 0){ }else{ $('.add-to-cart').trigger('click'); $('#product_customization_id').val(0); } if( $('.product-add-to-cart').find('.cart_data').length == 0 ){ var atc_text = $('.product-add-to-cart .add-to-cart').html(); $('.product-add-to-cart .add-to-cart').after('<button type="button" class="cart_data btn btn-primary" style="padding: 10px 40px; color: #fff; background-color: #c9902e; border-color: #c9902e;">' + atc_text + '</button>'); $('.product-add-to-cart .add-to-cart').hide(); $('button[name="submitCustomizedData"]').hide(); $('.cart_data').click(function(){ var check_trigger = []; $(".product-customization form .product-message").each(function(){ var pm_val = $(this).val(); if( pm_val == '' ){ check_trigger.push('f'); }else{ check_trigger.push('t'); } }); if( $.inArray('t', check_trigger) >= 0){ $('button[name="submitCustomizedData"]').trigger('click'); }else{ $('.add-to-cart').trigger('click'); } }); } },1000); Thanks and Happy Coding Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now