Jump to content

Add a datepicker field in the product front page to choose the delivery date


Eliott_Crmx

Recommended Posts

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)

Capture002.PNG

Capture001.PNG

Edited by Eliott_Crmx (see edit history)
Link to comment
Share on other sites

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 by 4you.software (see edit history)
Link to comment
Share on other sites

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...

 

psshoppingcart.PNG

productpl.PNG

productaddtocartpl.PNG

Edited by Eliott_Crmx (see edit history)
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...