
        console.log('PP: Init ATC');
        var qty = false;
        var pp_cart_adding = false;
        var eventFrom = null;
        document.addEventListener("DOMContentLoaded", function(event) {
            var attributewizardpro = false;
            var cdesigner = false;
            var isAWP = $('#awp_wizard').length == 1;

            init_add_to_cart(20);
            $(document).on('change', '#quantity_wanted', function () {
                qty = $(this).val();
            });
            function formatedNumberToFloat(price) {
                price = price.replace(prestashop.currency.sign, '');
                price = price.replace(prestashop.currency.iso_code, '');
                switch (parseInt(prestashop.currency.format)) {
                    case 1:
                        return parseFloat(price.replace(',', '').replace(' ', ''));
                    case 2:
                        return parseFloat(price.replace(' ', '').replace(',', '.'));
                    case 3:
                        return parseFloat(price.replace('.', '').replace(' ', '').replace(',', '.'));
                    case 4:
                        return parseFloat(price.replace(',', '').replace(' ', ''));
                    default:
                        return price;
                }
            }

            function init_add_to_cart(tries) {
                if (typeof jQuery === 'undefined') {
                    if (tries > 0) {
                        setTimeout(function() { init_add_to_cart(tries - 1) }, 250);
                    } else {
                        console.log('jQuery Could not be detected, AddToCart events will not be triggered');
                    }
                } else {
                    
                    if (attributewizardpro || isAWP) {
                        //console.log('addToCart-2');
                        // Add AWP module add to cart event
                        var id_product = $('#product_page_product_id').length ? $('#product_page_product_id').val() : $('.product_page_product_id').val();
                        var id_product_attribute = 0;

                        $('.exclusive').on('click', function () {
                            if (!pp_cart_adding) {
                                atcAjaxCall(id_product, id_product_attribute);
                            }
                        });
                    } else {
                        if (typeof (prestashop) === 'object' && typeof prestashop.on !== 'undefined') {
                            prestashop.on('updateCart', function (event) {
                                if (!pp_cart_adding) {
                                    // console.log('addToCart-4');
                                    window.fb_pixel_event_id = getCookie('fb_pixel_event_id');
                                    // It's a cart delete
                                    if (typeof event.reason.linkAction !== 'undefined' && event.reason.linkAction.indexOf('delete') != -1) {
                                        // It's a product cart delete
                                        return;
                                    } else if (typeof event.reason.updateUrl !== 'undefined') {
                                        // It's a product cart update
                                        return;
                                    }
                                    if (typeof event.reason !== 'undefined') {
                                        if (typeof event.reason.idProduct !== 'undefined') {
                                            let ipa = event.reason.idProductAttribute === undefined ? 0 : event.reason.idProductAttribute;
                                            // Add To Cart in the product list
                                                                                        atcAjaxCall(event.reason.idProduct, ipa);
                                                                                    } else if (typeof event.reason.cart !== 'undefined') {
                                            sendAddToCartFromResponse(event.reason, true, true);
                                        }
                                    }
                                }
                            });
                        } else {
                            //console.log('addToCart-3');
                            // Add the regular procedure if prestashop.on fails
                            XMLHttpRequest.prototype.open = (function (open) {
                                return function (method, url, async) {
                                    var checkURL = url.search('/panier');
                                    if (checkURL > -1 && !pp_cart_adding) {
                                        //console.log('addToCart-5');
                                        delete window.content_ids_data;
                                        delete window.content_ids_product;
                                        delete window.total_products_value;
                                        window.fb_pixel_event_id = getRandomString(12);
                                        var checkQuestion = url.search('\\?');
                                        if (checkQuestion > -1) {
                                            url = url + '&fb_pixel_event_id=' + window.fb_pixel_event_id;
                                        } else {
                                            url = url + '?fb_pixel_event_id=' + window.fb_pixel_event_id;
                                        }
                                    }
                                    this.addEventListener('load', function () {
                                        if (this.response != '') {
                                            try {
                                                sendAddToCartFromResponse(this.response, false, false);

                                            } catch (e) {
                                                // Is not an AddToCart event, no action needed
                                                //console.log("Can't be parsed the output to json");
                                            }
                                        }
                                    });
                                    open.apply(this, arguments);
                                };
                            })(XMLHttpRequest.prototype.open);
                        }
                    }
                }
            }
            function unique(array) {
                return $.grep(array, function(el, index) {
                    return index === $.inArray(el, array);
                });
            }
            function sendAddToCartFromResponse(r, parsed, delCookie) {
                // console.log('TrySendingATCfromResponse');
                if (!parsed) {
                    r = JSON.parse(r);
                }
                if (typeof r.cart == 'object' && r.cart != null && typeof r.cart.products == 'object' && !pp_cart_adding) {
                    // console.log('SeemsAnAddToCart');
                    pp_cart_adding = true;
                    window.content_name = 'Liquide vaisselle Pomme verte et basilic 700 ml - Attitude';
                    window.content_category = 'Accueil > Maison Et Jardin > Produits D\'entretien > Vaisselle > Liquide Vaisselle';
                    //cart value should never be 0 or empty, so assigning miniumm value as 1
                    window.content_value = 1;
                    window.content_ids_data = [];
                    window.content_ids_product = [];
                    var selected_product_id = r.id_product ? r.id_product : r.idProduct;
                    var ipa = r.id_product_attribute ? r.id_product_attribute : r.idProductAttribute;
                    if (cdesigner) {
                        atcAjaxCall(selected_product_id, ipa);
                    } else {
                        $.each(r.cart.products, function (key, value) {
                            var id_combination = '';
                                                        if ((selected_product_id == value.id_product && value.id_product_attribute == 0)
                                || (selected_product_id == value.id_product && value.id_product_attribute > 0 && value.id_product_attribute == ipa)) {
                                var pprice = 0;
                                if (typeof value.price_with_reduction !== 'undefined') {
                                    pprice = value.price_with_reduction;
                                } else if (typeof value.price_without_reduction !== 'undefined') {
                                    pprice = value.price_without_reduction;
                                } else {
                                    pprice = formatedNumberToFloat(value.price);
                                }
                                if (typeof value.name !== 'undefined') {
                                    content_name = value.name;
                                }
                                content_value = pprice.toFixed(pp_price_precision);
                                var pid = '' + value.id_product + id_combination;
                                var this_product = {
                                    'id': pid,
                                    'quantity': (qty !== false ? qty : value.quantity),
                                    'item_price': (qty !== false ? qty * pprice : value.quantity * pprice),
                                }
                                if (typeof value.category !== 'undefined' && value.category != '') {
                                    this_product.category = value.category;
                                }
                                content_ids_data.push(this_product);
                                content_ids_product.push(pid);
                            }
                        });

                        window.total_products_value = r.cart.totals.total.amount;
                        //here we suppose to sent the add to cart event
                        var cartValues = {
                            'content_name': window.content_name,
                            'content_ids': unique(window.content_ids_product),
                            'contents': unique(window.content_ids_data),
                            'content_type': 'product',
                            'value': content_value,
                            'currency': 'EUR'
                        };

                                                if (window.content_category != '') {
                            cartValues['content_category'] = window
                                .content_category;
                        }
                        //console.log(cartValues);
                        if (cartValues.content_type != '' && cartValues.contents != '' &&
                            cartValues.content_ids != '' && cartValues.value != '' &&
                            cartValues.currency != '') {
                            var event_id = getCookie('fb_pixel_event_id') !== undefined ? getCookie('fb_pixel_event_id') : getRandomString(12);
                            trackAddToCart(cartValues, event_id);
                        } else {
                            console.log("fbq error: Invalid values in the contents or the cart item is deleted");
                        }
                    }
                    if (delCookie) {
                        deleteCookie('fb_pixel_event_id');
                    }
                }
            }
            function trackAddToCart(values, event_id) {
                // console.log('track Add To Cart');
                setTimeout(function() { pp_cart_adding = false; }, 2000);
                ppTrackEvent('AddToCart', values, event_id);
            }
            /*For custom module add to cart trigger*/
            function atcAjaxCall(id_product, id_product_attribute) {
                pp_cart_adding = true;
                setTimeout(function() {
                    $.ajax({
                        url: pp_aurl,
                        type: 'POST',
                        cache: false,
                        data: {
                            customAjax: true,
                            id_product: id_product,
                            id_product_attribute: id_product_attribute,
                            quantity: qty || 1,
                            event: 'AddToCart',
                            rand: Math.floor((Math.random() * 100000) + 1),
                            token: '0e0c79b421dcba0bcab88bc53779b18f',
                        }
                    })
                        .done(function (data) {
                            if (data.return == 'ok') {
                                trackAddToCart(data.custom_data, data.event_id);
                            }
                        })
                        .fail(function (jqXHR, textStatus, errorThrown) {
                            // Something went wrong
                        });
                }, 500);
            }
    });
    