272 lines
8.4 KiB
JavaScript
272 lines
8.4 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 () {
|
|
testMap = 0;
|
|
if ($("#cgv").length) {
|
|
$("#cgv").unbind('click', inpostCGV).bind('click', inpostCGV);
|
|
} else {
|
|
$("button.standard-checkout").unbind('click', inpostCGV).bind('click', inpostCGV);
|
|
}
|
|
$('.delivery_option_radio').off('click', '.delivery_option_radio', inpostBindRadio);
|
|
$('.delivery_option_radio').on('click', '.delivery_option_radio', inpostBindRadio);
|
|
initInpost($('.delivery_option_radio' + ":checked"));
|
|
|
|
$('#inpostshipmodal .modal-footer button').on('click', function() {
|
|
$('#inpostshipmodal').modal('hide');
|
|
});
|
|
|
|
$('#inpostshipmodal .modal-header button').on('click', function() {
|
|
$('#inpostshipmodal').modal('hide');
|
|
});
|
|
});
|
|
|
|
if (typeof testMap == 'undefined') {
|
|
var testMap = 0;
|
|
}
|
|
|
|
var assetsServer = 'https://api-pl-points.easypack24.net/v1';
|
|
if (testMap == 1) {
|
|
assetsServer = 'https://test-api-pl-points.easypack24.net/v1';
|
|
}
|
|
function openModalMap(id) {
|
|
$('#easypack-widget').empty();
|
|
$('#easypack-map').empty();
|
|
if (imap == 'google') {
|
|
easyPack.init({
|
|
instance: 'pl',
|
|
defaultLocale: 'pl',
|
|
points: {
|
|
types: ['parcel_locker_only']
|
|
},
|
|
locales: 'pl',
|
|
apiEndpoint: assetsServer,
|
|
mapType: imap,
|
|
searchType: imap,
|
|
map: {
|
|
useGeolocation: true,
|
|
initialTypes: ['parcel_locker_only'],
|
|
googleKey: imgm
|
|
},
|
|
});
|
|
} else {
|
|
easyPack.init({
|
|
instance: 'pl',
|
|
defaultLocale: 'pl',
|
|
points: {
|
|
types: ['parcel_locker_only']
|
|
},
|
|
locales: 'pl',
|
|
apiEndpoint: assetsServer,
|
|
mapType: imap,
|
|
searchType: imap,
|
|
map: {
|
|
useGeolocation: true,
|
|
initialTypes: ['parcel_locker_only'],
|
|
},
|
|
});
|
|
}
|
|
easyPack.modalMap(function(point) {
|
|
updateInpostInfo(cart, id, point.name);
|
|
$('#widget-modal').parent().remove();
|
|
$('#widget-modal').remove();
|
|
return false;
|
|
}, { width: 500, height: 600 });
|
|
}
|
|
function openDropDown(id) {
|
|
$('#easypack-widget').empty();
|
|
$('#easypack-map').empty();
|
|
var gmap = null;
|
|
if (imap == 'google') {
|
|
gmap = 'googleKey: "'+imgm+'"';
|
|
}
|
|
easyPack.init({
|
|
instance: 'pl',
|
|
mapType: imap,
|
|
searchType: imap,
|
|
apiEndpoint: assetsServer,
|
|
points: {
|
|
types: ['parcel_locker'],
|
|
},
|
|
map: {
|
|
useGeolocation: true,
|
|
initialTypes: ['parcel_locker'],
|
|
gmap
|
|
}
|
|
});
|
|
easyPack.dropdownWidget('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) {
|
|
if (point.length < 9) {
|
|
$('.tr-inpost-box .inpostship-main').css({
|
|
'border': '1px solid #999'
|
|
});
|
|
$('.point-info').remove();
|
|
$.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,
|
|
success: function (jsonData) {
|
|
if (jsonData === false) {
|
|
$('.tr-inpost-box .inpostship-main').css({
|
|
'border': '3px solid #ff0000'
|
|
});
|
|
} else {
|
|
$('.tr-inpost-box .inpostship-main').css({
|
|
'border': '3px solid #67A901'
|
|
});
|
|
$('.tr-inpost-box .inpostship-main').append('<p class="point-info">Wybrany paczkomat: ' + jsonData.point_code + ', ul. ' + jsonData.point_address1 + ', ' + jsonData.point_address2 + ' - ' + jsonData.point_desc + '</p>');
|
|
selectedPointInfo = jsonData.point_code;
|
|
}
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
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 inpostCGV = function(){
|
|
if (typeof inpostkey === "undefined") {
|
|
inpostkey = 0;
|
|
}
|
|
if (typeof inpostkey_cod === "undefined") {
|
|
inpostkey_cod = 0;
|
|
}
|
|
|
|
var id = parseInt($("input.delivery_option_radio:checked").val());
|
|
if (id == inpostkey) {
|
|
var val = $('.tr-inpost-box .inpostship-main .inpost-point').val();
|
|
if (val == '' && selectedPointInfo == '') {
|
|
$('#inpostshipmodal').modal();
|
|
$('#cgv').parent().removeClass('checked');
|
|
return false;
|
|
}
|
|
}
|
|
if (id == inpostkey_cod) {
|
|
var val = $('.tr-inpost-box .inpostship-main .inpost-point').val();
|
|
if (val == '' && selectedPointInfo == '') {
|
|
$('#inpostshipmodal').modal();
|
|
$('#cgv').parent().removeClass('checked');
|
|
return false;
|
|
}
|
|
}
|
|
};
|
|
|
|
var initInpost = function(elem){
|
|
// inpostCGVUncheck();
|
|
var allow = false;
|
|
var id = parseInt(elem.val());
|
|
var ida = parseInt(elem.data('id_address'));
|
|
|
|
$('.tr-inpost-box').remove();
|
|
var win_width = $(window).width();
|
|
|
|
if (id == inpostkey) {
|
|
elem.closest('.delivery_option').after(createInpostBox(id));
|
|
if (selectedPointInfo != '' || selectedPointInfo != 'undefined') {
|
|
$('.tr-inpost-box .inpostship-main').append('<p class="point-info">'+selectedPointInfo+'</p>');
|
|
}
|
|
} else if( id == inpostkey_cod ) {
|
|
elem.closest('.delivery_option').after(createInpostBox(id));
|
|
if (selectedPointInfo != '' || selectedPointInfo != 'undefined') {
|
|
$('.tr-inpost-box .inpostship-main').append('<p class="point-info">'+selectedPointInfo+'</p>');
|
|
}
|
|
} 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 = '';
|
|
html += '<div class="row tr-inpost-box"><div class="inpostship-main i-go"><div class="inpostship-main-box">';
|
|
html += '<table>' +
|
|
'<tbody>' +
|
|
'<tr>' +
|
|
'<td>' +
|
|
'<img src="'+module_img_dir+'inpostpaczkomaty.jpg" alt="" />' +
|
|
'</td>' +
|
|
'<td>' +
|
|
'<span class="btn btn-success openDropDown" onclick="openDropDown('+idCarrier+');">Wybierz paczkomat z listy</span>' +
|
|
'<span class="btn btn-success 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></div><br />';
|
|
return html;
|
|
}
|
|
|
|
$(document).ready(function () {
|
|
|
|
$('.tr-inpost-box .inpostship-main .inpost-point').on('change', function(){
|
|
var vl = $(this).val();
|
|
if (vl != '' && vl != null && selectedPointInfo != '') {
|
|
var vla = vl.split(',');
|
|
updateInpostInfo(cart, inpostkey, vla[0]);
|
|
} else {
|
|
alert(alertPoint);
|
|
$('#cgv').removeAttr('checked');
|
|
$('#cgv').parent().removeClass('checked');
|
|
updatePaymentMethodsDisplay();
|
|
return false;
|
|
}
|
|
});
|
|
|
|
}); |