72 lines
2.9 KiB
JavaScript
72 lines
2.9 KiB
JavaScript
/*
|
|
* 2022 ECSoft
|
|
*
|
|
* NOTICE OF LICENSE
|
|
*
|
|
* This source file is subject to the Academic Free License (AFL 3.0)
|
|
* that is bundled with this package in the file LICENSE.txt.
|
|
* It is also available through the world-wide-web at this URL:
|
|
* http://opensource.org/licenses/afl-3.0.php
|
|
* If you did not receive a copy of the license and are unable to
|
|
* obtain it through the world-wide-web, please send an email
|
|
* to dev.ecsoft@gmail.com so we can send you a copy immediately.
|
|
*
|
|
*
|
|
* @author ECSoft <dev.ecsoft@gmail.com>
|
|
* @copyright 2022 ECSoft
|
|
|
|
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
|
* International Registered Trademark & Property of ECSoft
|
|
*/
|
|
|
|
window.addEventListener('load', function(){
|
|
prestashop.on('updateCart', function (event) {
|
|
let requestData = {};
|
|
|
|
if (event && event.reason) {
|
|
requestData = {
|
|
id_product_attribute: event.reason.idProductAttribute,
|
|
id_product: event.reason.idProduct,
|
|
action: event.reason.linkAction
|
|
};
|
|
|
|
let quantity = 1;
|
|
if (event.resp && event.resp.quantity) {
|
|
quantity = event.resp.quantity;
|
|
}
|
|
if (requestData.action == 'add-to-cart') {
|
|
ecsGtmPro.addToCart(requestData.id_product, requestData.id_product_attribute, quantity, null, null);
|
|
} else if(requestData.action == 'delete-from-cart') {
|
|
ecsGtmPro.removeFromCart(requestData.id_product, requestData.id_product_attribute, quantity);
|
|
}
|
|
}
|
|
});
|
|
|
|
$('#checkout').on('click', '#checkout-delivery-step button[type=submit]', function(e, ecsGtmTriggered) {
|
|
let $submitBtn = $(this);
|
|
|
|
let $selectedShipping = $submitBtn.closest('#checkout-delivery-step').find('.delivery-options input[type=radio]:checked').closest('.delivery-option');
|
|
let shippingName = $selectedShipping.find('.carrier-name').text();
|
|
|
|
ecsGtmPro.handleValidateShippingStep($submitBtn, e, ecsGtmTriggered, shippingName);
|
|
});
|
|
|
|
$('#checkout').on('change', '#checkout-payment-step input[type=radio][name=payment-option]', function(e, ecsGtmTriggered) {
|
|
let paymentName = $(this).closest('.payment-option').find('label').text().trim();
|
|
|
|
dataLayer = dataLayer || [];
|
|
let cloneDatalayer = JSON.parse(JSON.stringify(ecsGtmProDatalayer));
|
|
cloneDatalayer.event = 'add_payment_info';
|
|
cloneDatalayer.ecommerce.payment_type = paymentName;
|
|
dataLayer.push(cloneDatalayer);
|
|
});
|
|
|
|
$('article[data-id-product]').find('a').on('click', function() {
|
|
let $product = $(this).closest('article[data-id-product]');
|
|
let idProduct = $product.data('id-product');
|
|
let idProductAttribute = $product.data('id-product-attribute') | 0;
|
|
ecsGtmPro.productClick(idProduct, idProductAttribute);
|
|
});
|
|
});
|
|
|