Eliott_Crmx Posted July 15, 2022 Share Posted July 15, 2022 (edited) Hello, I need your help to understand how to retrieve the data from the product page form (product.tpl) sent by the 'add to cart' button (product-add-to-cart.tpl include). Indeed, I would like to retrieve the value of a datepicker field, added under the entry dedicated to the quantity of the product page, in order to save it in the ps_cart_product table. Despite my research in the cart class and its controller, I can't do it. How to retrieve the value of an entry in the home page of a product? A null date (0000-00-00) is however well recorded in our new columns date_retrait in ps_cart_product, we manage to recover it as you can see on a screen, but not to record it correctly. Where can I call $_POST or REQUEST from the input datepicker name = date_retrait (here it is 2022-07-24 but this is only a test, modified directly in the DB, normally it displays 0000-00-00) Edited July 15, 2022 by Eliott_Crmx (see edit history) Link to comment Share on other sites More sharing options...
ps8modules Posted July 16, 2022 Share Posted July 16, 2022 (edited) On 7/15/2022 at 10:16 AM, Eliott_Crmx said: Hello, I need your help to understand how to retrieve the data from the product page form (product.tpl) sent by the 'add to cart' button (product-add-to-cart.tpl include). Indeed, I would like to retrieve the value of a datepicker field, added under the entry dedicated to the quantity of the product page, in order to save it in the ps_cart_product table.... Hi. Use JavaScript instead and capture the button click. Eg: $(document).ready(function() { prestashop.on('updateCart', function(e) { var deliverydate = document.getElementById('my-date-picker-value'); if (typeof(deliverydate) != 'undefined' && deliverydate != null) { if (deliverydate.value !== ''){ $.ajax({ type: "POST", url: '/modules/my-module/function/my-function.php', data:'idCart='+this.cart.id+'&deliveryDate='+deliverydate.value, cache: false, ajax: false, success: function(data){ if (data !== ''){ console.log('done'); } } }); } } }); }); Edited July 16, 2022 by 4you.software (see edit history) Link to comment Share on other sites More sharing options...
Eliott_Crmx Posted July 20, 2022 Author Share Posted July 20, 2022 (edited) On 7/16/2022 at 11:24 AM, 4you.software said: Hi. Use JavaScript instead and capture the button click. Eg: $(document).ready(function() { prestashop.on('updateCart', function(e) { var deliverydate = document.getElementById('my-date-picker-value'); if (typeof(deliverydate) != 'undefined' && deliverydate != null) { if (deliverydate.value !== ''){ $.ajax({ type: "POST", url: '/modules/my-module/function/my-function.php', data:'idCart='+this.cart.id+'&deliveryDate='+deliverydate.value, cache: false, ajax: false, success: function(data){ if (data !== ''){ console.log('done'); } } }); } } }); }); Hi, Thank you very much for your answer which already helps me a lot, however I don't know where to put this ajax script, in the tpl of the form, in the partial tpl included in the forms and in which the submit is located, or in ps_shoppingcart.js? Could you explain me a little more the process ? I am a novice in JS... Edited July 20, 2022 by Eliott_Crmx (see edit history) Link to comment Share on other sites More sharing options...
ps8modules Posted July 21, 2022 Share Posted July 21, 2022 Hi. You can use it, for example, in custom.js in the template folder, or in your own module. E.g. ./themes/classic/assets/js/custom.js 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