501 lines
16 KiB
JavaScript
501 lines
16 KiB
JavaScript
/**
|
|
* NOTICE OF LICENSE
|
|
*
|
|
* This file is licenced under the Software License Agreement.
|
|
* With the purchase or the installation of the software in your application
|
|
* you accept the licence agreement.
|
|
*
|
|
* You must not modify, adapt or create derivative works of this source code
|
|
*
|
|
* @author PrestaHelp.com
|
|
* @copyright 2019 PrestaHelp
|
|
* @license LICENSE.txt
|
|
*/
|
|
|
|
$(document).ready(function () {
|
|
|
|
if (typeof checkout == 'undefined') {
|
|
checkout = 'default';
|
|
}
|
|
|
|
if (checkout == 'steasycheckout') {
|
|
$('.steco-custom-input').on('click', function(e) {
|
|
inpostBindRadio($(this), e);
|
|
});
|
|
prestashop.on('steco_init', function () {
|
|
setTimeout(function() {
|
|
$('.steco-custom-input-box.steco-tick').each(function(){
|
|
var ch = $(this).find('i.checkbox-checked');
|
|
if (ch.is(':visible')) {
|
|
id = parseInt(ch.parent().prev().val());
|
|
elem = ch.parent().prev();
|
|
}
|
|
});
|
|
initInpost(elem);
|
|
}, 2500);
|
|
})
|
|
|
|
prestashop.on('steco_event_init', function () {
|
|
setTimeout(function() {
|
|
$('.steco-custom-input-box.steco-tick').each(function(){
|
|
var ch = $(this).find('i.checkbox-checked');
|
|
if (ch.is(':visible')) {
|
|
id = parseInt(ch.parent().prev().val());
|
|
elem = ch.parent().prev();
|
|
}
|
|
});
|
|
initInpost(elem);
|
|
}, 2500);
|
|
})
|
|
|
|
prestashop.on(
|
|
'updatedDeliveryForm',
|
|
function() {
|
|
setTimeout(function() {
|
|
$('.steco-custom-input-box.steco-tick').each(function(){
|
|
var ch = $(this).find('i.checkbox-checked');
|
|
if (ch.is(':visible')) {
|
|
id = parseInt(ch.parent().prev().val());
|
|
elem = ch.parent().prev();
|
|
}
|
|
});
|
|
initInpost(elem);
|
|
}, 1000);
|
|
}
|
|
);
|
|
|
|
$(document).on("click", "#steco-conditions-to-approve .steco-custom-input" , function() {
|
|
inpostCGV();
|
|
});
|
|
|
|
}
|
|
if (checkout == 'supercheckout') {
|
|
if ($("#conditions_to_approve[terms-and-conditions]").length) {
|
|
$("#conditions_to_approve[terms-and-conditions]").unbind('click', inpostCGV).bind('click', inpostCGV);
|
|
}
|
|
$('#supercheckout-agree input').on('click', function() {
|
|
inpostCGV();
|
|
});
|
|
var elem;
|
|
setTimeout(function() {
|
|
$('.delivery_option_radio').each(function(){
|
|
var ch = $(this);
|
|
if (ch.is(':checked')) {
|
|
id = parseInt(ch.val());
|
|
elem = ch;
|
|
}
|
|
});
|
|
initInpost(elem);
|
|
}, 2500);
|
|
}
|
|
|
|
if (checkout == 'default')
|
|
{
|
|
var user_agent = navigator.userAgent.toLowerCase();
|
|
var click_event = user_agent.match(/(iphone|ipod|ipad)/) ? "touchend" : "click";
|
|
|
|
if ($("#cgv").length) {
|
|
// $("#cgv").unbind('click', inpostCGV).bind('click', inpostCGV);
|
|
} else {
|
|
$("button.standard-checkout").unbind('click', inpostCGV).bind('click', inpostCGV);
|
|
$("button.continue").unbind('click', inpostCGV).bind('click', inpostCGV);
|
|
}
|
|
$('#checkout-payment-step h1').unbind('click', inpostCGV).bind('click', inpostCGV);
|
|
|
|
$( 'body' ).on( click_event, '.wk-shipping input', function(e){
|
|
inpostBindRadio($(this), e);
|
|
});
|
|
initInpost($('.wk-shipping input' + ":checked"));
|
|
|
|
if (showWeek == 0) {
|
|
$('.wk-shipping').each(function() {
|
|
var idd = parseInt($(this).find('input').val());
|
|
if (idd == inpostkey_week || idd == inpostkey_week_cod) {
|
|
$(this).hide();
|
|
}
|
|
});
|
|
}
|
|
}
|
|
if (checkout == 'spstepcheckout') {
|
|
setTimeout(function() {
|
|
$('.delivery-option').each(function(){
|
|
var ch = $(this).find('input.delivery_option_radio');
|
|
if (ch.is(':checked')) {
|
|
id = parseInt(ch.val());
|
|
elem = ch;
|
|
}
|
|
});
|
|
initInpost(elem);
|
|
}, 2500);
|
|
}
|
|
$('.delivery-options-list button').on('click', function(){
|
|
var val = $('.tr-inpost-box .inpostship-main .inpost-point').val();
|
|
if (val == '' && selectedPointInfo == '') {
|
|
$('#inpostshipmodal').modal();
|
|
$('#cgv').parent().removeClass('checked');
|
|
return false;
|
|
}
|
|
});
|
|
$('#inpostshipmodal .modal-footer button').on('click', function() {
|
|
$('#inpostshipmodal').modal('hide');
|
|
});
|
|
$('#inpostshipmodal .modal-header button').on('click', function() {
|
|
$('#inpostshipmodal').modal('hide');
|
|
});
|
|
$(document).on('click', '#inpostshipmodal .modal-footer button', function() {
|
|
$('#inpostshipmodal').modal('hide');
|
|
});
|
|
$(document).on('click', '#inpostshipmodal .modal-header button', function() {
|
|
$('#inpostshipmodal').modal('hide');
|
|
});
|
|
});
|
|
var assetsServer = 'https://api-pl-points.easypack24.net/v1';
|
|
function openModalMap(id) {
|
|
$('#easypack-widget').empty();
|
|
$('#easypack-map').empty();
|
|
|
|
var pointType = ['parcel_locker'];
|
|
if (pTypes == 1) {
|
|
pointType = ['parcel_locker', 'pop'];
|
|
}
|
|
|
|
if (mapBox == 1) {
|
|
if (imap == 'google') {
|
|
easyPack.init({
|
|
instance: 'pl',
|
|
defaultLocale: 'pl',
|
|
points: {
|
|
types: pointType
|
|
},
|
|
locales: 'pl',
|
|
apiEndpoint: assetsServer,
|
|
mapType: imap,
|
|
searchType: imap,
|
|
map: {
|
|
useGeolocation: true,
|
|
initialTypes: pointType,
|
|
googleKey: imgm
|
|
},
|
|
});
|
|
} else {
|
|
easyPack.init({
|
|
instance: 'pl',
|
|
defaultLocale: 'pl',
|
|
points: {
|
|
types: pointType
|
|
},
|
|
locales: 'pl',
|
|
apiEndpoint: assetsServer,
|
|
mapType: imap,
|
|
searchType: imap,
|
|
map: {
|
|
useGeolocation: true,
|
|
initialTypes: pointType,
|
|
},
|
|
});
|
|
}
|
|
|
|
var width = 500;
|
|
var height = ($(window).height() * 0.7); // 600
|
|
if (mapShow == 2) {
|
|
width = ($(window).width() * 0.7);
|
|
}
|
|
|
|
easyPack.modalMap(function (point, modal) {
|
|
updateInpostInfo(cart, id, point.name);
|
|
modal.closeModal();
|
|
return false;
|
|
}, {width: width, height: height});
|
|
} else {
|
|
if (imap == 'google') {
|
|
easyPack.init({
|
|
instance: 'pl',
|
|
defaultLocale: 'pl',
|
|
points: {
|
|
types: pointType
|
|
},
|
|
locales: 'pl',
|
|
apiEndpoint: assetsServer,
|
|
mapType: imap,
|
|
searchType: imap,
|
|
map: {
|
|
useGeolocation: true,
|
|
initialTypes: pointType,
|
|
googleKey: imgm
|
|
},
|
|
});
|
|
} else {
|
|
easyPack.init({
|
|
instance: 'pl',
|
|
defaultLocale: 'pl',
|
|
points: {
|
|
types: pointType
|
|
},
|
|
locales: 'pl',
|
|
apiEndpoint: assetsServer,
|
|
mapType: imap,
|
|
searchType: imap,
|
|
map: {
|
|
useGeolocation: true,
|
|
initialTypes: pointType,
|
|
},
|
|
});
|
|
}
|
|
easyPack.mapWidget('easypack-widget', function(point) {
|
|
updateInpostInfo(cart, id, point.name);
|
|
});
|
|
}
|
|
}
|
|
|
|
function inpostCGVUncheck() {
|
|
$("#cgv").prop('checked', false);
|
|
if (typeof $.uniform != 'undefined') {
|
|
$.uniform.update();
|
|
}
|
|
}
|
|
|
|
function inpostBindRadio(el, e) {
|
|
inpostCGVUncheck();
|
|
initInpost(el, true);
|
|
}
|
|
|
|
function updateInpostInfo(id_cart, id_carrier, point) {
|
|
$('.saveInfo').remove();
|
|
if (point.length < 9) {
|
|
$('.point-info').remove();
|
|
var week = 0;
|
|
if ($('.weekPack').is(':checked')){
|
|
week = 1;
|
|
}
|
|
$.ajax({
|
|
type: 'POST',
|
|
headers: {"cache-control": "no-cache"},
|
|
url: baseDirShop + 'modules/inpostship/setPoint.php',
|
|
async: false,
|
|
cache: false,
|
|
dataType: 'json',
|
|
data: 'id_cart=' + id_cart
|
|
+ '&id_carrier=' + id_carrier
|
|
+ '&point=' + point
|
|
+ '&week='+week,
|
|
success: function (jsonData) {
|
|
$('.saveInfo').remove();
|
|
if (jsonData === false) {
|
|
$('.tr-inpost-box .inpostship-main').append('<small class="saveInfo text-danger">Paczkomat nie został poprawnie zapisany</small>');
|
|
} else {
|
|
$('.tr-inpost-box .inpostship-main').append('<p class="point-info">Wybrany paczkomat:<br /><b>' + jsonData.point_code + ', ul. ' + jsonData.point_address1 + ', ' + jsonData.point_address2 + '</b><br />' + jsonData.point_desc + '</p>');
|
|
selectedPointInfo = jsonData.point_code;
|
|
if (selectedPointInfo != '') {
|
|
$('.tr-inpost-box .inpostship-main').append('<small class="saveInfo text-success">Paczkomat został poprawnie zapisany</small>');
|
|
} else {
|
|
$('.tr-inpost-box .inpostship-main').append('<small class="saveInfo text-danger">Paczkomat nie został poprawnie zapisany</small>');
|
|
}
|
|
}
|
|
setTimeout(function() {
|
|
$('.saveInfo').remove();
|
|
}, 3000);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
function updateInpostInfoCourier(id_cart, id_carrier) {
|
|
$.ajax({
|
|
type: 'POST',
|
|
headers: { "cache-control": "no-cache" },
|
|
url: baseDirShop + 'modules/inpostship/setCourier.php',
|
|
async: false,
|
|
cache: false,
|
|
dataType: 'json',
|
|
data: 'id_cart='+id_cart+'&id_carrier='+id_carrier,
|
|
success: function(jsonData) {
|
|
|
|
}
|
|
});
|
|
}
|
|
|
|
var inpostCGVspStepCheckout = function() {
|
|
if (typeof inpostkey === "undefined") {
|
|
inpostkey = 0;
|
|
}
|
|
if (typeof inpostkey_cod === "undefined") {
|
|
inpostkey_cod = 0;
|
|
}
|
|
if (typeof inpostkey_week === "undefined") {
|
|
inpostkey_week = 0;
|
|
}
|
|
if (typeof inpostkey_week_cod === "undefined") {
|
|
inpostkey_week_cod = 0;
|
|
}
|
|
if (id == inpostkey) {
|
|
if (selectedPointInfo == '') {
|
|
$('#inpostshipmodal').modal();
|
|
return false;
|
|
}
|
|
}
|
|
if (id == inpostkey_cod) {
|
|
if (selectedPointInfo == '') {
|
|
$('#inpostshipmodal').modal();
|
|
return false;
|
|
}
|
|
}
|
|
if (id == inpostkey_week) {
|
|
if (selectedPointInfo == '') {
|
|
$('#inpostshipmodal').modal();
|
|
return false;
|
|
}
|
|
}
|
|
if (id == inpostkey_week_cod) {
|
|
if (selectedPointInfo == '') {
|
|
$('#inpostshipmodal').modal();
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
};
|
|
|
|
var inpostCGV = function() {
|
|
if (typeof inpostkey === "undefined") {
|
|
inpostkey = 0;
|
|
}
|
|
if (typeof inpostkey_cod === "undefined") {
|
|
inpostkey_cod = 0;
|
|
}
|
|
if (typeof inpostkey_week === "undefined") {
|
|
inpostkey = 0;
|
|
}
|
|
if (typeof inpostkey_week_cod === "undefined") {
|
|
inpostkey_cod = 0;
|
|
}
|
|
$('.custom-radio').each(function() {
|
|
var inp = $(this).find('input');
|
|
if (inp.is(':checked')) {
|
|
id = parseInt(inp.val());
|
|
}
|
|
});
|
|
if (id == inpostkey || id == inpostkey_week) {
|
|
if (selectedPointInfo == '') {
|
|
$('#inpostshipmodal').modal();
|
|
if (checkout == 'steasycheckout') {
|
|
$('#steco-conditions-to-approve .steco-custom-input').removeAttr('checked').next().find('i').css('display', 'none');
|
|
} else if (checkout == 'supercheckout') {
|
|
$('#supercheckout-agree input').removeAttr('checked');
|
|
} else {
|
|
$('#cgv').parent().removeClass('checked');
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
if (id == inpostkey_cod || id == inpostkey_week_cod) {
|
|
if (selectedPointInfo == '') {
|
|
$('#inpostshipmodal').modal();
|
|
if (checkout == 'steasycheckout') {
|
|
$('#steco-conditions-to-approve .steco-custom-input').removeAttr('checked').next().find('i').css('display', 'none');
|
|
} else if (checkout == 'supercheckout') {
|
|
$('#supercheckout-agree input').removeAttr('checked');
|
|
} else {
|
|
$('#cgv').parent().removeClass('checked');
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
};
|
|
|
|
var initInpost = function(elem) {
|
|
if (typeof inpostkey === "undefined") {
|
|
inpostkey = 0;
|
|
}
|
|
if (typeof inpostkey_cod === "undefined") {
|
|
inpostkey_cod = 0;
|
|
}
|
|
if (typeof inpostkey_week === "undefined") {
|
|
inpostkey = 0;
|
|
}
|
|
if (typeof inpostkey_week_cod === "undefined") {
|
|
inpostkey_cod = 0;
|
|
}
|
|
inpostCGVUncheck();
|
|
id = parseInt(elem.val());
|
|
$('.tr-inpost-box').remove();
|
|
|
|
var closest = '.wk-shipping-list';
|
|
if (checkout == 'supercheckout') {
|
|
closest = '.highlight';
|
|
$('.supercheckoutListItemInpost').remove();
|
|
}
|
|
|
|
if (id == inpostkey || id == inpostkey_week) {
|
|
elem.closest(closest).parent('.row').after(createInpostBox(id));
|
|
if (selectedPointInfo != '' || selectedPointInfo != 'undefined') {
|
|
$('.tr-inpost-box .inpostship-main').append('<p class="point-info"></p>');
|
|
selectedPointInfo = selectedPointInfo.replace('|| ', '<br />').replace(';;', '<b>').replace(';; ', '</b>').replace('||', '<br />');
|
|
$('.tr-inpost-box .inpostship-main .point-info').html(selectedPointInfo);
|
|
}
|
|
} else if (id == inpostkey_cod || id == inpostkey_week_cod) {
|
|
elem.closest(closest).parent('.row').after(createInpostBox(id));
|
|
if (selectedPointInfo != '' || selectedPointInfo != 'undefined') {
|
|
$('.tr-inpost-box .inpostship-main').append('<p class="point-info"></p>');
|
|
selectedPointInfo = selectedPointInfo.replace('|| ', '<br />').replace(';;', '<b>').replace(';; ', '</b>').replace('||', '<br />');
|
|
$('.tr-inpost-box .inpostship-main .point-info').html(selectedPointInfo);
|
|
}
|
|
} else {
|
|
if (typeof courierkey === "undefined") {
|
|
courierkey = 0;
|
|
}
|
|
if (typeof courierkey_cod === "undefined") {
|
|
courierkey_cod = 0;
|
|
}
|
|
if (id == courierkey) {
|
|
updateInpostInfoCourier(cart, courierkey);
|
|
}
|
|
if (id == courierkey_cod) {
|
|
updateInpostInfoCourier(cart, courierkey_cod);
|
|
}
|
|
}
|
|
}
|
|
function createInpostBox(idCarrier) {
|
|
var html = '';
|
|
if (isTable == 1) {
|
|
html += '<tr><td colspan="4">';
|
|
}
|
|
if (checkout == 'supercheckout') {
|
|
html += '<li class="supercheckoutListItemInpost">';
|
|
}
|
|
html += '<div class="row tr-inpost-box"><div class="inpostship-main i-go"><div class="inpostship-main-box">';
|
|
html += '<table>' +
|
|
'<tbody>';
|
|
if (showWeek == 1) {
|
|
// html += '<tr><td colspan="2"><span class="custom-checkbox" style="float: left;margin-right: 15px;"><input type="checkbox" value="1" class="weekPack" /><span><i class="material-icons rtl-no-flip checkbox-checked"></i></span></span> Paczka w weekend (+' + weekPrice + ' zł)</td> </tr>';
|
|
}
|
|
html += '<tr>' +
|
|
'<td>' +
|
|
'<span class="btn btn-success btn-md btn-block openMap" onclick="openModalMap('+idCarrier+');">Wybierz paczkomat z mapy</span>' +
|
|
'</td>' +
|
|
'</tr>' +
|
|
'</tbody>' +
|
|
'</table>';
|
|
html += '</div><div id="easypack-widget"></div><div id="easypack-widget2"></div></div><br /></div>';
|
|
if (checkout == 'supercheckout') {
|
|
html += '</li>';
|
|
}
|
|
if (isTable == 1) {
|
|
html += '</td></tr>';
|
|
}
|
|
return html;
|
|
}
|
|
|
|
$(document).ready(function () {
|
|
$('.tr-inpost-box .inpostship-main .inpost-point').on('change', function(){
|
|
var vl = $(this).html();
|
|
if (vl != '' && vl != null && selectedPointInfo != '') {
|
|
var vla = vl.split(',');
|
|
updateInpostInfo(cart, inpostkey, vla[0]);
|
|
} else {
|
|
alert(alertPoint);
|
|
$('#cgv').removeAttr('checked');
|
|
$('#cgv').parent().removeClass('checked');
|
|
return false;
|
|
}
|
|
});
|
|
});
|