168 lines
5.9 KiB
JavaScript
168 lines
5.9 KiB
JavaScript
/**
|
|
* 2024 DPD Polska Sp. z o.o.
|
|
*
|
|
* NOTICE OF LICENSE
|
|
*
|
|
* This source file is subject to the Open Software License (OSL 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/osl-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
|
|
* prestashop@dpd.com.pl so we can send you a copy immediately.
|
|
*
|
|
* @author DPD Polska Sp. z o.o.
|
|
* @copyright 2024 DPD Polska Sp. z o.o.
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
|
* International Registered Trademark & Property of DPD Polska Sp. z o.o.
|
|
*/
|
|
|
|
$(document).ready(function () {
|
|
handleDpdPudo();
|
|
$(document).on('click', '.delivery_option_radio', handleDpdPudo);
|
|
$(document).on('click', 'input[name^="delivery_option"]', handleDpdPudo);
|
|
|
|
$('.dpdpoland-pudo-container').parent().css('border-right', '0');
|
|
$('.dpdpoland-pudo-cod-container').parent().css('border-right', '0');
|
|
$('.dpdpoland-swipbox-container').parent().css('border-right', '0');
|
|
|
|
$(document).on('click', '.dpdpoland-swipbox-open-map-btn', (e) => showModal(e, '#dpdpolandSwipboxModal'));
|
|
$(document).on('click', '.dpdpoland-swipbox-change-map-btn', (e) => showModal(e, '#dpdpolandSwipboxModal'));
|
|
|
|
$(document).on('click', '.dpdpoland-pudo-open-map-btn', (e) => showModal(e, '#dpdpolandPudoModal'));
|
|
$(document).on('click', '.dpdpoland-pudo-change-map-btn', (e) => showModal(e, '#dpdpolandPudoModal'));
|
|
|
|
$(document).on('click', '.dpdpoland-pudo-cod-open-map-btn', (e) => showModal(e, '#dpdpolandPudoCodModal'));
|
|
$(document).on('click', '.dpdpoland-pudo-cod-change-map-btn', (e) => showModal(e, '#dpdpolandPudoCodModal'));
|
|
|
|
});
|
|
|
|
function dpdPolandSavePudoCode(pudoCode, modal) {
|
|
$.ajax({
|
|
url: dpdpoland_ajax_uri,
|
|
type: 'POST',
|
|
data: {
|
|
'pudo_code': pudoCode,
|
|
'save_pudo_id': 1,
|
|
'token': dpdpoland_token,
|
|
'id_cart': dpdpoland_cart,
|
|
'session': dpdpoland_session
|
|
},
|
|
success: function (response) {
|
|
if (Number(response) === 1) {
|
|
$('.dpdpoland-pudo-new-point').css("display", "none");
|
|
$('.dpdpoland-pudo-selected-point').css("display", "block");
|
|
enableDpdPolandOrderProcessBtn();
|
|
} else {
|
|
$('.container_dpdpoland_pudo_error').css("display", "block");
|
|
disableDpdPolandOrderProcessBtn();
|
|
console.error('Error:', response);
|
|
}
|
|
hideModal(modal);
|
|
},
|
|
error: function (error) {
|
|
console.error('Error:', error);
|
|
hideModal(modal);
|
|
}
|
|
});
|
|
|
|
function hideModal(modal) {
|
|
setTimeout(() => {
|
|
modal.modal('toggle');
|
|
$(".modal-backdrop").hide();
|
|
}, 500);
|
|
}
|
|
|
|
}
|
|
|
|
function dpdPolandGetPudoAddress(pudoCode, input) {
|
|
$.ajax({
|
|
url: dpdpoland_ajax_uri,
|
|
type: 'GET',
|
|
data: {
|
|
'pudo_code': pudoCode,
|
|
'call_pudo_address': 1,
|
|
'token': dpdpoland_token,
|
|
'id_cart': dpdpoland_cart
|
|
},
|
|
success: function (response) {
|
|
input.text(response);
|
|
},
|
|
error: function (error) {
|
|
console.error('Error:', error);
|
|
}
|
|
});
|
|
}
|
|
|
|
function showModal(event, modalDiv) {
|
|
event.preventDefault();
|
|
event.stopPropagation();
|
|
$(modalDiv).modal({
|
|
backdrop: 'static',
|
|
keyboard: false
|
|
})
|
|
handleDpdPudo();
|
|
}
|
|
|
|
function handleDpdPudo() {
|
|
|
|
$('.container_dpdpoland_pudo_cod_error').css("display", "none");
|
|
$('.container_dpdpoland_pudo_cod_warning').css("display", "none");
|
|
|
|
if (getDpdPolandSelectedCarrier() === getDpdPolandIdPudoCarrier()) {
|
|
$('.dpdpoland-pudo-new-point').css("display", "block");
|
|
$('.dpdpoland-pudo-selected-point').css("display", "none");
|
|
|
|
$('.dpdpoland-selected-point').text("");
|
|
const dpdPolandWidgetPudoIframe = $("#dpd-widget-pudo-iframe")
|
|
dpdPolandWidgetPudoIframe.attr("src", dpdPolandWidgetPudoIframe.attr("src"));
|
|
|
|
disableDpdPolandOrderProcessBtn();
|
|
} else if (getDpdPolandSelectedCarrier() === getDpdPolandIdPudoCodCarrier()) {
|
|
$('.dpdpoland-pudo-cod-selected-point').css("display", "none");
|
|
$('.dpdpoland-pudo-cod-new-point').css("display", "block");
|
|
|
|
$('.dpdpoland-selected-point-cod').text("");
|
|
const dpdPolandWidgetPudoCodIframe = $("#dpd-widget-pudo-cod-iframe")
|
|
dpdPolandWidgetPudoCodIframe.attr("src", dpdPolandWidgetPudoCodIframe.attr("src"));
|
|
|
|
disableDpdPolandOrderProcessBtn();
|
|
} else if (getDpdPolandSelectedCarrier() === getDpdPolandIdSwipBoxCarrier()) {
|
|
$('.dpdpoland-swipbox-selected-point').css("display", "none");
|
|
$('.dpdpoland-swipbox-new-point').css("display", "block");
|
|
|
|
$('.dpdpoland-selected-point-swipbox').text("");
|
|
const dpdPolandWidgetSwipBoxIframe = $("#dpd-widget-swipbox-iframe")
|
|
dpdPolandWidgetSwipBoxIframe.attr("src", dpdPolandWidgetSwipBoxIframe.attr("src"));
|
|
|
|
disableDpdPolandOrderProcessBtn();
|
|
} else {
|
|
enableDpdPolandOrderProcessBtn();
|
|
}
|
|
}
|
|
|
|
function getDpdPolandIdPudoCarrier() {
|
|
return Number(dpdpoland_id_pudo_carrier);
|
|
}
|
|
|
|
function getDpdPolandIdPudoCodCarrier() {
|
|
return Number(dpdpoland_id_pudo_cod_carrier);
|
|
}
|
|
|
|
function getDpdPolandIdSwipBoxCarrier() {
|
|
return Number(dpdpoland_id_swipbox_carrier);
|
|
}
|
|
|
|
function getDpdPolandSelectedCarrier() {
|
|
let idDpdPolandSelectedCarrier = $('input[name^="delivery_option"]:checked').val();
|
|
|
|
if (typeof idDpdPolandSelectedCarrier == 'undefined')
|
|
return null;
|
|
|
|
idDpdPolandSelectedCarrier = idDpdPolandSelectedCarrier.replace(',', '');
|
|
if (typeof idDpdPolandSelectedCarrier == 'undefined' || idDpdPolandSelectedCarrier === 0)
|
|
return null;
|
|
|
|
return Number(idDpdPolandSelectedCarrier);
|
|
}
|