aktualizacja modułu dpd
This commit is contained in:
42
modules/dpdshipping/views/js/configuration/address-grid.js
Normal file
42
modules/dpdshipping/views/js/configuration/address-grid.js
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright 2024 DPD Polska Sp. z o.o.
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* Licensed under the EUPL-1.2 or later.
|
||||
* You may not use this work except in compliance with the Licence.
|
||||
*
|
||||
* You may obtain a copy of the Licence at:
|
||||
* https://joinup.ec.europa.eu/software/page/eupl
|
||||
* It is also bundled with this package in the file LICENSE.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the Licence is distributed on an AS IS basis,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the Licence for the specific language governing permissions
|
||||
* and limitations under the Licence.
|
||||
*
|
||||
* @author DPD Polska Sp. z o.o.
|
||||
* @copyright 2024 DPD Polska Sp. z o.o.
|
||||
* @license https://joinup.ec.europa.eu/software/page/eupl
|
||||
*/
|
||||
|
||||
$(document).ready(function () {
|
||||
window.prestashop.component.initComponents(
|
||||
[
|
||||
'Grid'
|
||||
],
|
||||
);
|
||||
const grid = new window.prestashop.component.Grid('dpdshipping_sender_address');
|
||||
grid.addExtension(new window.prestashop.component.GridExtensions.BulkActionCheckboxExtension());
|
||||
// grid.addExtension(new window.prestashop.component.GridExtensions.ExportToSqlManagerExtension());
|
||||
grid.addExtension(new window.prestashop.component.GridExtensions.ReloadListExtension());
|
||||
grid.addExtension(new window.prestashop.component.GridExtensions.SortingExtension());
|
||||
grid.addExtension(new window.prestashop.component.GridExtensions.FiltersResetExtension());
|
||||
grid.addExtension(new window.prestashop.component.GridExtensions.SubmitRowActionExtension());
|
||||
grid.addExtension(new window.prestashop.component.GridExtensions.SubmitBulkActionExtension());
|
||||
grid.addExtension(new window.prestashop.component.GridExtensions.AjaxBulkActionExtension());
|
||||
// grid.addExtension(new window.prestashop.component.GridExtensions.FiltersSubmitButtonEnablerExtension());
|
||||
grid.addExtension(new window.prestashop.component.GridExtensions.AsyncToggleColumnExtension());
|
||||
// grid.addExtension(new window.prestashop.component.GridExtensions.PositionExtension(grid));
|
||||
});
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright 2024 DPD Polska Sp. z o.o.
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* Licensed under the EUPL-1.2 or later.
|
||||
* You may not use this work except in compliance with the Licence.
|
||||
*
|
||||
* You may obtain a copy of the Licence at:
|
||||
* https://joinup.ec.europa.eu/software/page/eupl
|
||||
* It is also bundled with this package in the file LICENSE.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the Licence is distributed on an AS IS basis,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the Licence for the specific language governing permissions
|
||||
* and limitations under the Licence.
|
||||
*
|
||||
* @author DPD Polska Sp. z o.o.
|
||||
* @copyright 2024 DPD Polska Sp. z o.o.
|
||||
* @license https://joinup.ec.europa.eu/software/page/eupl
|
||||
*/
|
||||
|
||||
$(document).ready(function () {
|
||||
window.prestashop.component.initComponents(
|
||||
[
|
||||
'Grid'
|
||||
],
|
||||
);
|
||||
const grid = new window.prestashop.component.Grid('dpdshipping_connection');
|
||||
grid.addExtension(new window.prestashop.component.GridExtensions.BulkActionCheckboxExtension());
|
||||
// grid.addExtension(new window.prestashop.component.GridExtensions.ExportToSqlManagerExtension());
|
||||
grid.addExtension(new window.prestashop.component.GridExtensions.ReloadListExtension());
|
||||
grid.addExtension(new window.prestashop.component.GridExtensions.SortingExtension());
|
||||
grid.addExtension(new window.prestashop.component.GridExtensions.FiltersResetExtension());
|
||||
grid.addExtension(new window.prestashop.component.GridExtensions.SubmitRowActionExtension());
|
||||
grid.addExtension(new window.prestashop.component.GridExtensions.SubmitBulkActionExtension());
|
||||
grid.addExtension(new window.prestashop.component.GridExtensions.AjaxBulkActionExtension());
|
||||
// grid.addExtension(new window.prestashop.component.GridExtensions.FiltersSubmitButtonEnablerExtension());
|
||||
grid.addExtension(new window.prestashop.component.GridExtensions.AsyncToggleColumnExtension());
|
||||
// grid.addExtension(new window.prestashop.component.GridExtensions.PositionExtension(grid));
|
||||
});
|
||||
56
modules/dpdshipping/views/js/configuration/connection.js
Normal file
56
modules/dpdshipping/views/js/configuration/connection.js
Normal file
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright 2024 DPD Polska Sp. z o.o.
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* Licensed under the EUPL-1.2 or later.
|
||||
* You may not use this work except in compliance with the Licence.
|
||||
*
|
||||
* You may obtain a copy of the Licence at:
|
||||
* https://joinup.ec.europa.eu/software/page/eupl
|
||||
* It is also bundled with this package in the file LICENSE.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the Licence is distributed on an AS IS basis,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the Licence for the specific language governing permissions
|
||||
* and limitations under the Licence.
|
||||
*
|
||||
* @author DPD Polska Sp. z o.o.
|
||||
* @copyright 2024 DPD Polska Sp. z o.o.
|
||||
* @license https://joinup.ec.europa.eu/software/page/eupl
|
||||
*/
|
||||
|
||||
$(() => {
|
||||
|
||||
$(document).on('click', '#addFidRow', function () {
|
||||
const packagesTable = document.getElementById('fidTable');
|
||||
const tbody = packagesTable.getElementsByTagName('tbody')[0];
|
||||
addFidRow(tbody.rows.length);
|
||||
});
|
||||
|
||||
$(document).on('click', '.dpdshipping-remove-row', function () {
|
||||
$(this).closest('tr').remove();
|
||||
});
|
||||
|
||||
function addFidRow(index) {
|
||||
const rowTemplate = `
|
||||
<tr>
|
||||
<td><input type="text" class="form-control" name="form[payerList][${index}][name]" ></td>
|
||||
<td><input type="number" class="form-control" name="form[payerList][${index}][fid]"></td>
|
||||
<td><input type="checkbox" class="form-control" name="form[payerList][${index}][default]"></td>
|
||||
<td><i class="material-icons btn btn-sm text-secondary delete-icon-gray dpdshipping-remove-row">delete</i></td>
|
||||
</tr>
|
||||
`;
|
||||
const packagesTable = document.getElementById('fidTable');
|
||||
const tbody = packagesTable.getElementsByTagName('tbody')[0];
|
||||
|
||||
tbody.appendChild(createRow());
|
||||
|
||||
function createRow(row) {
|
||||
const newRow = document.createElement('tr');
|
||||
newRow.innerHTML = rowTemplate;
|
||||
return newRow;
|
||||
}
|
||||
}
|
||||
});
|
||||
33
modules/dpdshipping/views/js/configuration/index.php
Normal file
33
modules/dpdshipping/views/js/configuration/index.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright 2024 DPD Polska Sp. z o.o.
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* Licensed under the EUPL-1.2 or later.
|
||||
* You may not use this work except in compliance with the Licence.
|
||||
*
|
||||
* You may obtain a copy of the Licence at:
|
||||
* https://joinup.ec.europa.eu/software/page/eupl
|
||||
* It is also bundled with this package in the file LICENSE.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the Licence is distributed on an AS IS basis,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the Licence for the specific language governing permissions
|
||||
* and limitations under the Licence.
|
||||
*
|
||||
* @author DPD Polska Sp. z o.o.
|
||||
* @copyright 2024 DPD Polska Sp. z o.o.
|
||||
* @license https://joinup.ec.europa.eu/software/page/eupl
|
||||
*/
|
||||
|
||||
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
|
||||
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
|
||||
|
||||
header('Cache-Control: no-store, no-cache, must-revalidate');
|
||||
header('Cache-Control: post-check=0, pre-check=0', false);
|
||||
header('Pragma: no-cache');
|
||||
|
||||
header('Location: ../');
|
||||
exit;
|
||||
51
modules/dpdshipping/views/js/configuration/parameters.js
Normal file
51
modules/dpdshipping/views/js/configuration/parameters.js
Normal file
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright 2024 DPD Polska Sp. z o.o.
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* Licensed under the EUPL-1.2 or later.
|
||||
* You may not use this work except in compliance with the Licence.
|
||||
*
|
||||
* You may obtain a copy of the Licence at:
|
||||
* https://joinup.ec.europa.eu/software/page/eupl
|
||||
* It is also bundled with this package in the file LICENSE.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the Licence is distributed on an AS IS basis,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the Licence for the specific language governing permissions
|
||||
* and limitations under the Licence.
|
||||
*
|
||||
* @author DPD Polska Sp. z o.o.
|
||||
* @copyright 2024 DPD Polska Sp. z o.o.
|
||||
* @license https://joinup.ec.europa.eu/software/page/eupl
|
||||
*/
|
||||
|
||||
$(() => {
|
||||
function handleSelectChange() {
|
||||
const selectedValue = $(this).val();
|
||||
const parentContainer = $(this).closest('.row');
|
||||
if (selectedValue === 'STATIC_VALUE' || selectedValue === 'STATIC_VALUE_ONLY_FOR_EMPIK') {
|
||||
parentContainer.find('.input-static-value').removeClass('d-none').addClass('d-block');
|
||||
} else {
|
||||
parentContainer.find('.input-static-value').removeClass('d-block').addClass('d-none');
|
||||
}
|
||||
}
|
||||
|
||||
$('.select-with-static-value').each(handleSelectChange);
|
||||
$(document).on('change', '.select-with-static-value', handleSelectChange);
|
||||
|
||||
function handlePrintFormat() {
|
||||
const selectedValue = $('#form_printFormat').val();
|
||||
|
||||
if (selectedValue === 'LBL_PRINTER') {
|
||||
$('#form_labelType').removeAttr('disabled');
|
||||
} else {
|
||||
$('#form_labelType').prop('selectedIndex', 0);
|
||||
$('#form_labelType').attr('disabled', 'disabled');
|
||||
}
|
||||
}
|
||||
handlePrintFormat();
|
||||
$(document).on('change', '#form_printFormat', handlePrintFormat);
|
||||
|
||||
});
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright 2024 DPD Polska Sp. z o.o.
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* Licensed under the EUPL-1.2 or later.
|
||||
* You may not use this work except in compliance with the Licence.
|
||||
*
|
||||
* You may obtain a copy of the Licence at:
|
||||
* https://joinup.ec.europa.eu/software/page/eupl
|
||||
* It is also bundled with this package in the file LICENSE.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the Licence is distributed on an AS IS basis,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the Licence for the specific language governing permissions
|
||||
* and limitations under the Licence.
|
||||
*
|
||||
* @author DPD Polska Sp. z o.o.
|
||||
* @copyright 2024 DPD Polska Sp. z o.o.
|
||||
* @license https://joinup.ec.europa.eu/software/page/eupl
|
||||
*/
|
||||
|
||||
$(document).ready(function () {
|
||||
window.prestashop.component.initComponents(
|
||||
[
|
||||
'Grid'
|
||||
],
|
||||
);
|
||||
const grid = new window.prestashop.component.Grid('dpdshipping_pickup_courier_settings');
|
||||
grid.addExtension(new window.prestashop.component.GridExtensions.BulkActionCheckboxExtension());
|
||||
// grid.addExtension(new window.prestashop.component.GridExtensions.ExportToSqlManagerExtension());
|
||||
grid.addExtension(new window.prestashop.component.GridExtensions.ReloadListExtension());
|
||||
grid.addExtension(new window.prestashop.component.GridExtensions.SortingExtension());
|
||||
grid.addExtension(new window.prestashop.component.GridExtensions.FiltersResetExtension());
|
||||
grid.addExtension(new window.prestashop.component.GridExtensions.SubmitRowActionExtension());
|
||||
grid.addExtension(new window.prestashop.component.GridExtensions.SubmitBulkActionExtension());
|
||||
grid.addExtension(new window.prestashop.component.GridExtensions.AjaxBulkActionExtension());
|
||||
grid.addExtension(new window.prestashop.component.GridExtensions.FiltersSubmitButtonEnablerExtension());
|
||||
grid.addExtension(new window.prestashop.component.GridExtensions.AsyncToggleColumnExtension());
|
||||
grid.addExtension(new window.prestashop.component.GridExtensions.PositionExtension(grid));
|
||||
});
|
||||
222
modules/dpdshipping/views/js/configuration/special-price-data.js
Normal file
222
modules/dpdshipping/views/js/configuration/special-price-data.js
Normal file
@@ -0,0 +1,222 @@
|
||||
/*
|
||||
* Copyright 2025 DPD Polska Sp. z o.o.
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* Licensed under the EUPL-1.2 or later.
|
||||
* You may not use this work except in compliance with the Licence.
|
||||
*
|
||||
* You may obtain a copy of the Licence at:
|
||||
* https://joinup.ec.europa.eu/software/page/eupl
|
||||
* It is also bundled with this package in the file LICENSE.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the Licence is distributed on an AS IS basis,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the Licence for the specific language governing permissions
|
||||
* and limitations under the Licence.
|
||||
*
|
||||
* @author DPD Polska Sp. z o.o.
|
||||
* @copyright 2024 DPD Polska Sp. z o.o.
|
||||
* @license https://joinup.ec.europa.eu/software/page/eupl
|
||||
*/
|
||||
|
||||
$(() => {
|
||||
const $importFileInput = $('#dpdSpecialPriceImportFile');
|
||||
const $selectedFileName = $('#selectedFileName');
|
||||
const $exportButton = $('#dpdSpecialPriceExportButton');
|
||||
const $importButton = $('#dpdSpecialPriceImportFileButton');
|
||||
|
||||
$importFileInput.on('change', function () {
|
||||
const fileName = $(this).val().split('\\').pop();
|
||||
$selectedFileName.text(fileName ? fileName : 'No file chosen');
|
||||
});
|
||||
|
||||
$exportButton.on('click', function (e) {
|
||||
e.preventDefault();
|
||||
$.ajax({
|
||||
url: dpdshipping_special_price_export_ajax_url,
|
||||
method: 'GET',
|
||||
data: {
|
||||
dpdshipping_token: dpdshipping_token
|
||||
},
|
||||
xhrFields: {
|
||||
responseType: 'blob',
|
||||
},
|
||||
success: function (data) {
|
||||
const url = window.URL.createObjectURL(data);
|
||||
const a = $('<a />', {
|
||||
href: url,
|
||||
download: 'export-dpd-ceny-specjalne-prestashop.csv',
|
||||
}).appendTo('body');
|
||||
a[0].click();
|
||||
window.URL.revokeObjectURL(url);
|
||||
a.remove();
|
||||
},
|
||||
error: function () {
|
||||
alert('Error exporting the file.');
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
$importButton.on('click', function (e) {
|
||||
e.preventDefault();
|
||||
const file = $importFileInput[0].files[0];
|
||||
if (file) {
|
||||
const formData = new FormData();
|
||||
formData.append('csvFile', file);
|
||||
formData.append('dpdshipping_token', dpdshipping_token);
|
||||
|
||||
$.ajax({
|
||||
url: dpdshipping_special_price_import_ajax_url,
|
||||
method: 'POST',
|
||||
data: formData,
|
||||
processData: false,
|
||||
contentType: false,
|
||||
success: function (response) {
|
||||
if (response.success) {
|
||||
location.reload();
|
||||
} else {
|
||||
alert('Import failed: ' + response.message);
|
||||
}
|
||||
},
|
||||
error: function () {
|
||||
alert('Error importing the file.');
|
||||
},
|
||||
});
|
||||
} else {
|
||||
alert('Please select a file first.');
|
||||
}
|
||||
});
|
||||
|
||||
const rowsPerPage = 50;
|
||||
|
||||
function showPage(page) {
|
||||
|
||||
const $tbody = $('#specialPriceTable').find('tbody');
|
||||
const $rows = $tbody.find('tr');
|
||||
const totalRows = $rows.length;
|
||||
const totalPages = Math.ceil(totalRows / rowsPerPage);
|
||||
|
||||
if (page < 1) page = 1;
|
||||
if (page > totalPages) page = totalPages;
|
||||
|
||||
$rows.hide();
|
||||
|
||||
const start = (page - 1) * rowsPerPage;
|
||||
const end = start + rowsPerPage;
|
||||
|
||||
$rows.slice(start, end).show();
|
||||
|
||||
$('.pagination-button').removeClass('active');
|
||||
$(`.pagination-button[data-page='${page}']`).addClass('active');
|
||||
|
||||
updatePaginationInfo(page, totalPages, rowsPerPage, totalRows);
|
||||
}
|
||||
|
||||
function updatePaginationInfo(page, totalPages, rowsPerPage, totalRows) {
|
||||
const startRow = (page - 1) * rowsPerPage + 1;
|
||||
let endRow = page * rowsPerPage;
|
||||
if (endRow > totalRows) endRow = totalRows;
|
||||
|
||||
$('#pagination-info-rows-from').text(startRow);
|
||||
$('#pagination-info-rows-to').text(endRow);
|
||||
$('#pagination-info-pages').text(totalRows);
|
||||
}
|
||||
|
||||
function createPagination() {
|
||||
const $pagination = $('#dpdSpecialPricePagination');
|
||||
$pagination.empty();
|
||||
|
||||
const $tbody = $('#specialPriceTable').find('tbody');
|
||||
const $rows = $tbody.find('tr');
|
||||
const totalRows = $rows.length;
|
||||
const totalPages = Math.ceil(totalRows / rowsPerPage);
|
||||
|
||||
const $prev = $('<a href="#" class="pagination-button">Prev</a>');
|
||||
if (currentPage === 1) {
|
||||
$prev.addClass('disabled');
|
||||
}
|
||||
$pagination.append($prev);
|
||||
|
||||
let startPage = Math.max(1, currentPage - 2);
|
||||
let endPage = Math.min(totalPages, currentPage + 2);
|
||||
|
||||
if (currentPage <= 3) {
|
||||
endPage = Math.min(5, totalPages);
|
||||
}
|
||||
if (currentPage >= totalPages - 2) {
|
||||
startPage = Math.max(totalPages - 4, 1);
|
||||
}
|
||||
|
||||
if (startPage > 1) {
|
||||
const $first = $(`<a href="#" class="pagination-button" data-page="1">1</a>`);
|
||||
$pagination.append($first);
|
||||
if (startPage > 2) {
|
||||
$pagination.append('<span>...</span>');
|
||||
}
|
||||
}
|
||||
|
||||
for (let i = startPage; i <= endPage; i++) {
|
||||
const $btn = $(`<a href="#" class="pagination-button" data-page="${i}">${i}</a>`);
|
||||
if (i === currentPage) $btn.addClass('active');
|
||||
$pagination.append($btn);
|
||||
}
|
||||
|
||||
if (endPage < totalPages) {
|
||||
if (endPage < totalPages - 1) {
|
||||
$pagination.append('<span>...</span>');
|
||||
}
|
||||
const $last = $(`<a href="#" class="pagination-button" data-page="${totalPages}">${totalPages}</a>`);
|
||||
$pagination.append($last);
|
||||
}
|
||||
|
||||
const $next = $('<a href="#" class="pagination-button">Next</a>');
|
||||
if (currentPage === totalPages) {
|
||||
$next.addClass('disabled');
|
||||
}
|
||||
$pagination.append($next);
|
||||
|
||||
if (currentPage === endPage) {
|
||||
$('#addFidRow').show();
|
||||
} else {
|
||||
$('#addFidRow').hide();
|
||||
}
|
||||
}
|
||||
|
||||
let currentPage = 1;
|
||||
|
||||
showPage(currentPage);
|
||||
|
||||
createPagination();
|
||||
|
||||
$('#dpdSpecialPricePagination').on('click', '.pagination-button', function (e) {
|
||||
e.preventDefault();
|
||||
|
||||
if ($(this).hasClass('disabled') || $(this).hasClass('active')) {
|
||||
return;
|
||||
}
|
||||
|
||||
const $tbody = $('#specialPriceTable').find('tbody');
|
||||
const $rows = $tbody.find('tr');
|
||||
const totalRows = $rows.length;
|
||||
const totalPages = Math.ceil(totalRows / rowsPerPage);
|
||||
|
||||
const buttonText = $(this).text();
|
||||
|
||||
if (buttonText === 'Prev') {
|
||||
if (currentPage > 1) {
|
||||
currentPage--;
|
||||
}
|
||||
} else if (buttonText === 'Next') {
|
||||
if (currentPage < totalPages) {
|
||||
currentPage++;
|
||||
}
|
||||
} else {
|
||||
currentPage = parseInt($(this).attr('data-page'));
|
||||
}
|
||||
|
||||
showPage(currentPage);
|
||||
createPagination();
|
||||
});
|
||||
});
|
||||
86
modules/dpdshipping/views/js/configuration/special-price.js
Normal file
86
modules/dpdshipping/views/js/configuration/special-price.js
Normal file
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Copyright 2024 DPD Polska Sp. z o.o.
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* Licensed under the EUPL-1.2 or later.
|
||||
* You may not use this work except in compliance with the Licence.
|
||||
*
|
||||
* You may obtain a copy of the Licence at:
|
||||
* https://joinup.ec.europa.eu/software/page/eupl
|
||||
* It is also bundled with this package in the file LICENSE.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the Licence is distributed on an AS IS basis,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the Licence for the specific language governing permissions
|
||||
* and limitations under the Licence.
|
||||
*
|
||||
* @author DPD Polska Sp. z o.o.
|
||||
* @copyright 2024 DPD Polska Sp. z o.o.
|
||||
* @license https://joinup.ec.europa.eu/software/page/eupl
|
||||
*/
|
||||
|
||||
$(() => {
|
||||
|
||||
$(document).on('click', '#addFidRow', function () {
|
||||
const parentContainer = $("#specialPriceTable tbody tr:last");
|
||||
const clonedRow = parentContainer.clone();
|
||||
|
||||
setIndexForNewRow(clonedRow, true);
|
||||
clonedRow.insertAfter(parentContainer);
|
||||
});
|
||||
|
||||
$(document).on('click', '.dpdshipping-remove-row', function () {
|
||||
$(this).closest('tr').remove();
|
||||
|
||||
$("#specialPriceTable tbody tr").each(function (index) {
|
||||
function setIndexesAfterRemoveRow() {
|
||||
const currentName = $(this).attr('name');
|
||||
const matches = currentName.match(/\[(\d+)\]/);
|
||||
if (matches) {
|
||||
const newIndex = index + 1;
|
||||
const newName = currentName.replace(/\[(\d+)\]/, '[' + newIndex + ']');
|
||||
$(this).attr('name', newName);
|
||||
}
|
||||
}
|
||||
|
||||
$(this).find('input').each(function () {
|
||||
setIndexesAfterRemoveRow.call(this);
|
||||
});
|
||||
|
||||
$(this).find('select').each(function () {
|
||||
setIndexesAfterRemoveRow.call(this);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
$(document).on('click', '.dpdshipping-duplicate-row', function () {
|
||||
const parentContainer = $(this).closest('tr');
|
||||
const clonedRow = parentContainer.clone();
|
||||
|
||||
setIndexForNewRow(clonedRow, false);
|
||||
const lastRow = $("#specialPriceTable tbody tr:last");
|
||||
clonedRow.insertAfter(lastRow);
|
||||
});
|
||||
|
||||
function setIndexForNewRow(clonedRow, emptyValue) {
|
||||
function setIndexes() {
|
||||
const index = parseInt($("#specialPriceTable tbody tr").length) + 1;
|
||||
const currentName = $(this).attr('name');
|
||||
const newName = currentName.replace(/\[(\d+)\]/, '[' + index + ']');
|
||||
$(this).attr('name', newName);
|
||||
if (emptyValue)
|
||||
$(this).val('');
|
||||
}
|
||||
|
||||
clonedRow.find('input').each(function () {
|
||||
setIndexes.call(this);
|
||||
});
|
||||
|
||||
clonedRow.find('select').each(function () {
|
||||
setIndexes.call(this);
|
||||
});
|
||||
}
|
||||
});
|
||||
201
modules/dpdshipping/views/js/dpdshipping-ajax.js
Normal file
201
modules/dpdshipping/views/js/dpdshipping-ajax.js
Normal file
@@ -0,0 +1,201 @@
|
||||
/*
|
||||
* Copyright 2024 DPD Polska Sp. z o.o.
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* Licensed under the EUPL-1.2 or later.
|
||||
* You may not use this work except in compliance with the Licence.
|
||||
*
|
||||
* You may obtain a copy of the Licence at:
|
||||
* https://joinup.ec.europa.eu/software/page/eupl
|
||||
* It is also bundled with this package in the file LICENSE.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the Licence is distributed on an AS IS basis,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the Licence for the specific language governing permissions
|
||||
* and limitations under the Licence.
|
||||
*
|
||||
* @author DPD Polska Sp. z o.o.
|
||||
* @copyright 2024 DPD Polska Sp. z o.o.
|
||||
* @license https://joinup.ec.europa.eu/software/page/eupl
|
||||
*/
|
||||
|
||||
$(document).ready(function () {
|
||||
|
||||
function downloadFile(xhr, response) {
|
||||
const contentType = xhr.getResponseHeader('Content-Type');
|
||||
const fileName = getFileName(xhr);
|
||||
const blob = new Blob([response], {type: contentType});
|
||||
const link = document.createElement('a');
|
||||
link.href = window.URL.createObjectURL(blob);
|
||||
link.download = fileName;
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
document.body.removeChild(link);
|
||||
}
|
||||
|
||||
function getFileName(xhr) {
|
||||
const contentDisposition = xhr.getResponseHeader('Content-Disposition');
|
||||
let fileName = 'downloaded-file';
|
||||
|
||||
if (contentDisposition && contentDisposition.indexOf('attachment') !== -1) {
|
||||
const filenameRegex = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/;
|
||||
const matches = filenameRegex.exec(contentDisposition);
|
||||
if (matches != null && matches[1]) {
|
||||
fileName = matches[1].replace(/['"]/g, '');
|
||||
}
|
||||
}
|
||||
return fileName;
|
||||
}
|
||||
|
||||
$('#print-label').on('click', function (event) {
|
||||
event.preventDefault();
|
||||
|
||||
const shippingHistoryId = $(this).data('shipping-history-id');
|
||||
const url = $(this).data('url');
|
||||
|
||||
$.ajax({
|
||||
url: url,
|
||||
method: 'POST',
|
||||
data: {
|
||||
shippingHistoryId: shippingHistoryId,
|
||||
token: dpdshipping_token
|
||||
},
|
||||
xhrFields: {
|
||||
responseType: 'blob'
|
||||
},
|
||||
success: function (response, status, xhr) {
|
||||
downloadFile(xhr, response);
|
||||
$('.alert-messages').hide();
|
||||
$('.success-message-ajax').text(dpdshipping_translations.dpdshipping_label_success_text).show();
|
||||
$('.error-message-ajax').hide();
|
||||
},
|
||||
error: function () {
|
||||
handleErrorResponse(dpdshipping_translations.dpdshipping_label_error_text);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
$('#print-return-label').on('click', function (event) {
|
||||
event.preventDefault();
|
||||
|
||||
const shippingHistoryId = $(this).data('shipping-history-id');
|
||||
const orderId = $(this).data('order-id');
|
||||
const url = $(this).data('url');
|
||||
|
||||
$.ajax({
|
||||
url: url,
|
||||
method: 'POST',
|
||||
data: {
|
||||
shippingHistoryId: shippingHistoryId,
|
||||
orderId: orderId,
|
||||
token: dpdshipping_token
|
||||
},
|
||||
xhrFields: {
|
||||
responseType: 'blob'
|
||||
},
|
||||
success: function (response, status, xhr) {
|
||||
downloadFile(xhr, response);
|
||||
$('.alert-messages').hide();
|
||||
$('.success-message-ajax').text(dpdshipping_translations.dpdshipping_return_label_success_text).show();
|
||||
$('.error-message-ajax').hide();
|
||||
},
|
||||
error: function () {
|
||||
handleErrorResponse(dpdshipping_translations.dpdshipping_return_label_error_text);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
function handleErrorResponse(message) {
|
||||
$('.alert-messages').hide();
|
||||
$('.success-message-ajax').hide();
|
||||
$('.error-message-ajax').text(message).show();
|
||||
}
|
||||
|
||||
const $dpdConn = $('.js-dpd-connection');
|
||||
const $dpdPayer = $('.js-dpd-payer');
|
||||
if ($dpdConn.length === 0 || $dpdPayer.length === 0) return;
|
||||
|
||||
const dpdOriginalByLabel = Object.create(null);
|
||||
let dpdPlaceholder = null;
|
||||
|
||||
$dpdPayer.find('option').each((_, el) => {
|
||||
const $opt = $(el);
|
||||
const val = String($opt.attr('value') ?? '');
|
||||
const text = $opt.text();
|
||||
if (val === '') {
|
||||
dpdPlaceholder = { value: '', text: text || '—' };
|
||||
} else {
|
||||
dpdOriginalByLabel[text] = val;
|
||||
}
|
||||
});
|
||||
|
||||
let dpdPayersByConn = {};
|
||||
try {
|
||||
let dpdRaw = $dpdConn.attr('data-payers') || '{}';
|
||||
if (dpdRaw.includes('"') || dpdRaw.includes(''') || dpdRaw.includes('&')) {
|
||||
dpdRaw = dpdRaw.replace(/"/g, '"').replace(/'/g, "'").replace(/&/g, '&');
|
||||
}
|
||||
dpdPayersByConn = JSON.parse(dpdRaw);
|
||||
} catch {
|
||||
dpdPayersByConn = {};
|
||||
}
|
||||
|
||||
const dpdFillPayers = () => {
|
||||
const dpdConnId = String($dpdConn.val() || '');
|
||||
const dpdMap = dpdPayersByConn[dpdConnId] || {};
|
||||
const dpdLabels = Object.keys(dpdMap);
|
||||
const dpdRemembered = String($dpdPayer.val() || $dpdPayer.attr('data-selected') || '');
|
||||
|
||||
$dpdPayer.empty();
|
||||
|
||||
if (dpdLabels.length === 0) {
|
||||
const text = dpdPlaceholder?.text ?? '—';
|
||||
$('<option/>', { value: '', text }).appendTo($dpdPayer);
|
||||
$dpdPayer.prop('disabled', true);
|
||||
return;
|
||||
}
|
||||
|
||||
$dpdPayer.prop('disabled', false);
|
||||
|
||||
let dpdSelectedSet = false;
|
||||
|
||||
if (dpdPlaceholder) {
|
||||
$('<option/>', { value: '', text: dpdPlaceholder.text }).appendTo($dpdPayer);
|
||||
}
|
||||
|
||||
for (const label of dpdLabels) {
|
||||
const originalVal = String(dpdOriginalByLabel[label] ?? '');
|
||||
const isSelected = !dpdSelectedSet && originalVal !== '' && originalVal === dpdRemembered;
|
||||
|
||||
$('<option/>', {
|
||||
value: originalVal || '',
|
||||
text: label,
|
||||
selected: isSelected
|
||||
}).appendTo($dpdPayer);
|
||||
|
||||
if (isSelected) dpdSelectedSet = true;
|
||||
}
|
||||
|
||||
if (!dpdSelectedSet) {
|
||||
const firstIndex = dpdPlaceholder ? 1 : 0;
|
||||
const $opts = $dpdPayer.find('option');
|
||||
if ($opts.length > firstIndex) $opts.eq(firstIndex).prop('selected', true);
|
||||
}
|
||||
|
||||
$dpdPayer.attr('data-selected', '');
|
||||
};
|
||||
|
||||
dpdFillPayers();
|
||||
|
||||
$dpdConn.on('change', () => {
|
||||
$dpdPayer.attr('data-selected', String($dpdPayer.val() || ''));
|
||||
dpdFillPayers();
|
||||
});
|
||||
|
||||
$dpdPayer.closest('form').on('submit', () => {
|
||||
$dpdPayer.prop('disabled', false);
|
||||
});
|
||||
});
|
||||
195
modules/dpdshipping/views/js/dpdshipping-common.js
Normal file
195
modules/dpdshipping/views/js/dpdshipping-common.js
Normal file
@@ -0,0 +1,195 @@
|
||||
/*
|
||||
* Copyright 2024 DPD Polska Sp. z o.o.
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* Licensed under the EUPL-1.2 or later.
|
||||
* You may not use this work except in compliance with the Licence.
|
||||
*
|
||||
* You may obtain a copy of the Licence at:
|
||||
* https://joinup.ec.europa.eu/software/page/eupl
|
||||
* It is also bundled with this package in the file LICENSE.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the Licence is distributed on an AS IS basis,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the Licence for the specific language governing permissions
|
||||
* and limitations under the Licence.
|
||||
*
|
||||
* @author DPD Polska Sp. z o.o.
|
||||
* @copyright 2024 DPD Polska Sp. z o.o.
|
||||
* @license https://joinup.ec.europa.eu/software/page/eupl
|
||||
*/
|
||||
|
||||
// noinspection JSUnresolvedReference
|
||||
|
||||
$(document).ready(function () {
|
||||
handleDpdShippingPudo();
|
||||
$(document).on('click', '.delivery_option_radio', handleDpdShippingPudo);
|
||||
$(document).on('click', 'input[name^="delivery_option"]', handleDpdShippingPudo);
|
||||
|
||||
$('.dpdshipping-pudo-container').parent().css('border-right', '0');
|
||||
$('.dpdshipping-pudo-cod-container').parent().css('border-right', '0');
|
||||
$('.dpdshipping-pudo-swipbox-container').parent().css('border-right', '0');
|
||||
|
||||
$(document).on('click', '.dpdshipping-pudo-open-map-btn', (e) => showModal(e, '#dpdshippingPudoModal'));
|
||||
$(document).on('click', '.dpdshipping-pudo-change-map-btn', (e) => showModal(e, '#dpdshippingPudoModal'));
|
||||
|
||||
$(document).on('click', '.dpdshipping-pudo-cod-open-map-btn', (e) => showModal(e, '#dpdshippingPudoCodModal'));
|
||||
$(document).on('click', '.dpdshipping-pudo-cod-change-map-btn', (e) => showModal(e, '#dpdshippingPudoCodModal'));
|
||||
|
||||
$(document).on('click', '.dpdshipping-pudo-swipbox-open-map-btn', (e) => showModal(e, '#dpdshippingPudoSwipBoxModal'));
|
||||
$(document).on('click', '.dpdshipping-pudo-swipbox-change-map-btn', (e) => showModal(e, '#dpdshippingPudoSwipBoxModal'));
|
||||
});
|
||||
|
||||
function dpdshippingSavePudoCode(pudoCode, modal) {
|
||||
$.ajax({
|
||||
url: dpdshipping_pickup_save_point_ajax_url,
|
||||
type: 'POST',
|
||||
data: {
|
||||
dpdshipping_token: dpdshipping_token,
|
||||
dpdshipping_csrf: dpdshipping_csrf,
|
||||
dpdshipping_id_cart: dpdshipping_id_cart,
|
||||
dpdshipping_pudo_code: pudoCode
|
||||
},
|
||||
success: function (response) {
|
||||
const resultJson = JSON.parse(response)
|
||||
if (resultJson.success) {
|
||||
$('.dpdshipping-pudo-new-point').css("display", "none");
|
||||
$('.dpdshipping-pudo-selected-point').css("display", "block");
|
||||
dpdshippingEnableOrderProcessBtn();
|
||||
} else {
|
||||
$('.container_dpdshipping_pudo_error').css("display", "block");
|
||||
dpdshippingDisableOrderProcessBtn();
|
||||
console.error('Error:', response);
|
||||
}
|
||||
hideModal(modal);
|
||||
},
|
||||
error: function (error) {
|
||||
console.log('Error:', error);
|
||||
hideModal(modal);
|
||||
}
|
||||
});
|
||||
|
||||
function hideModal(modal) {
|
||||
setTimeout(() => {
|
||||
modal.modal('toggle');
|
||||
$(".modal-backdrop").hide();
|
||||
}, 500);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function dpdshippingGetPudoAddress(pudoCode, input) {
|
||||
$.ajax({
|
||||
url: dpdshipping_pickup_get_address_ajax_url,
|
||||
type: 'GET',
|
||||
data: {
|
||||
dpdshipping_token: dpdshipping_token,
|
||||
dpdshipping_csrf: dpdshipping_csrf,
|
||||
dpdshipping_pudo_code: pudoCode
|
||||
},
|
||||
success: function (response) {
|
||||
const resultJson = JSON.parse(response)
|
||||
if (resultJson.success && resultJson.data)
|
||||
input.text(resultJson.data);
|
||||
else
|
||||
console.log('Error:', response);
|
||||
},
|
||||
error: function (error) {
|
||||
console.log('Error:', error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function showModal(a, b) {
|
||||
let el;
|
||||
if (a instanceof Event) {
|
||||
a.preventDefault(); a.stopPropagation();
|
||||
el = typeof b === 'string' ? document.querySelector(b) : b;
|
||||
} else {
|
||||
el = typeof a === 'string' ? document.querySelector(a) : a;
|
||||
}
|
||||
|
||||
if (!(el instanceof Element)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (window.bootstrap && window.bootstrap.Modal) {
|
||||
window.bootstrap.Modal.getOrCreateInstance(el, { backdrop: 'static', keyboard: false }).show();
|
||||
}
|
||||
else if (window.jQuery && jQuery.fn && jQuery.fn.modal &&
|
||||
jQuery.fn.modal.Constructor && /^4\./.test(String(jQuery.fn.modal.Constructor.VERSION || ''))) {
|
||||
jQuery(el).modal({ backdrop: 'static', keyboard: false });
|
||||
}
|
||||
else {
|
||||
el.style.display = 'block';
|
||||
el.classList.add('show');
|
||||
document.body.classList.add('modal-open');
|
||||
}
|
||||
|
||||
if (typeof handleDpdShippingPudo === 'function')
|
||||
handleDpdShippingPudo();
|
||||
}
|
||||
|
||||
function handleDpdShippingPudo() {
|
||||
|
||||
$('.container_dpdshipping_pudo_cod_error').css("display", "none");
|
||||
$('.container_dpdshipping_pudo_cod_warning').css("display", "none");
|
||||
|
||||
if (getDpdshippingSelectedCarrier() === getDpdshippingIdPudoCarrier()) {
|
||||
$('.dpdshipping-pudo-new-point').css("display", "block");
|
||||
$('.dpdshipping-pudo-selected-point').css("display", "none");
|
||||
|
||||
$('.dpdshipping-selected-point').text("");
|
||||
const dpdShippingWidgetPudoIframe = $("#dpdshiping-widget-pudo-iframe")
|
||||
dpdShippingWidgetPudoIframe.attr("src", dpdShippingWidgetPudoIframe.attr("src"));
|
||||
|
||||
dpdshippingDisableOrderProcessBtn();
|
||||
} else if (getDpdshippingSelectedCarrier() === getDpdshippingIdPudoCodCarrier()) {
|
||||
$('.dpdshipping-pudo-cod-new-point').css("display", "block");
|
||||
$('.dpdshipping-pudo-cod-selected-point').css("display", "none");
|
||||
|
||||
$('.dpdshipping-cod-selected-point').text("");
|
||||
const dpdShippingWidgetPudoCodIframe = $("#dpdshipping-widget-pudo-cod-iframe")
|
||||
dpdShippingWidgetPudoCodIframe.attr("src", dpdShippingWidgetPudoCodIframe.attr("src"));
|
||||
|
||||
dpdshippingDisableOrderProcessBtn();
|
||||
} else if (getDpdshippingSelectedCarrier() === getDpdshippingIdPudoSwipBoxCarrier()) {
|
||||
$('.dpdshipping-pudo-swipbox-new-point').css("display", "block");
|
||||
$('.dpdshipping-pudo-swipbox-selected-point').css("display", "none");
|
||||
|
||||
$('.dpdshipping-swipbox-selected-point').text("");
|
||||
const dpdShippingWidgetPudoSwipboxIframe = $("#dpdshipping-widget-pudo-swipbox-iframe")
|
||||
dpdShippingWidgetPudoSwipboxIframe.attr("src", dpdShippingWidgetPudoSwipboxIframe.attr("src"));
|
||||
|
||||
dpdshippingDisableOrderProcessBtn();
|
||||
} else {
|
||||
dpdshippingEnableOrderProcessBtn();
|
||||
}
|
||||
}
|
||||
|
||||
function getDpdshippingIdPudoCarrier() {
|
||||
return Number(dpdshipping_id_pudo_carrier);
|
||||
}
|
||||
|
||||
function getDpdshippingIdPudoCodCarrier() {
|
||||
return Number(dpdshipping_id_pudo_cod_carrier);
|
||||
}
|
||||
|
||||
function getDpdshippingIdPudoSwipBoxCarrier() {
|
||||
return Number(dpdshipping_id_pudo_swipbox_carrier);
|
||||
}
|
||||
|
||||
function getDpdshippingSelectedCarrier() {
|
||||
let idSelectedCarrier = $('input[name^="delivery_option"]:checked').val();
|
||||
|
||||
if (typeof idSelectedCarrier == 'undefined')
|
||||
return null;
|
||||
|
||||
idSelectedCarrier = idSelectedCarrier.replace(',', '');
|
||||
if (typeof idSelectedCarrier == 'undefined' || idSelectedCarrier === 0)
|
||||
return null;
|
||||
|
||||
return Number(idSelectedCarrier);
|
||||
}
|
||||
309
modules/dpdshipping/views/js/dpdshipping-pickup-courier-ajax.js
Normal file
309
modules/dpdshipping/views/js/dpdshipping-pickup-courier-ajax.js
Normal file
@@ -0,0 +1,309 @@
|
||||
/*
|
||||
* Copyright 2024 DPD Polska Sp. z o.o.
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* Licensed under the EUPL-1.2 or later.
|
||||
* You may not use this work except in compliance with the Licence.
|
||||
*
|
||||
* You may obtain a copy of the Licence at:
|
||||
* https://joinup.ec.europa.eu/software/page/eupl
|
||||
* It is also bundled with this package in the file LICENSE.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the Licence is distributed on an AS IS basis,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the Licence for the specific language governing permissions
|
||||
* and limitations under the Licence.
|
||||
*
|
||||
* @author DPD Polska Sp. z o.o.
|
||||
* @copyright 2024 DPD Polska Sp. z o.o.
|
||||
* @license https://joinup.ec.europa.eu/software/page/eupl
|
||||
*/
|
||||
|
||||
$(document).ready(function () {
|
||||
|
||||
$('#form_dpdshipping_pickup_courier_sender_address').on('change', function (event) {
|
||||
event.preventDefault();
|
||||
$('.errorMessagePickupCourier').hide();
|
||||
const pickupOrderSettingsId = $(this).val();
|
||||
$('#senderAddressContainer').hide();
|
||||
$.ajax({
|
||||
url: dpdshipping_pickup_courier_ajax_url, method: 'GET', data: {
|
||||
pickupOrderSettingsId: pickupOrderSettingsId,
|
||||
token: dpdshipping_token
|
||||
}, success: function (response, status, xhr) {
|
||||
if (response.success === true && response.data !== null) {
|
||||
$('#form_customer_company').val(response.data.customerFullName);
|
||||
$('#form_customer_name').val(response.data.customerName);
|
||||
$('#form_customer_phone').val(response.data.customerPhone);
|
||||
$('#senderFullName').text(response.data.senderFullName);
|
||||
$('#senderName').text(response.data.senderName);
|
||||
$('#senderAddress').text(response.data.senderAddress);
|
||||
$('#senderPostalCode').text(response.data.senderPostalCode);
|
||||
$('#senderCity').text(response.data.senderCity);
|
||||
$('#senderCountryCode').text(response.data.senderCountryCode);
|
||||
$('#senderPhone').text(response.data.senderPhone);
|
||||
$('#payerNumber').text(response.data.payerNumber);
|
||||
$('#senderAddressContainer').show();
|
||||
} else if (response.success === false && response.errors && response.errors.length > 0) {
|
||||
$('.errorMessagePickupCourier').text(response.errors[0]);
|
||||
$('.errorMessagePickupCourier').show();
|
||||
} else {
|
||||
$('.errorMessagePickupCourier').text('Unknown error');
|
||||
$('.errorMessagePickupCourier').show();
|
||||
}
|
||||
}, error: function () {
|
||||
$('.errorMessagePickupCourier').text('Unknown error');
|
||||
$('.errorMessagePickupCourier').show();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$('#button_get_pickup_time_frames').on('click', function (event) {
|
||||
$('.errorMessagePickupCourier').hide();
|
||||
const pickupOrderSettingsId = $('#form_dpdshipping_pickup_courier_sender_address').val()
|
||||
const countryCode = $('#senderCountryCode').text()
|
||||
const postalCode = $('#senderPostalCode').text()
|
||||
|
||||
$('#pickupTimeContainer').hide();
|
||||
$.ajax({
|
||||
url: dpdshipping_pickup_courier_get_pickup_time_frames_ajax_url, method: 'GET', data: {
|
||||
pickupOrderSettingsId: pickupOrderSettingsId,
|
||||
countryCode: countryCode,
|
||||
postalCode: postalCode,
|
||||
token: dpdshipping_token
|
||||
}, success: function (response, status, xhr) {
|
||||
if (response.success === true && response.data !== null) {
|
||||
const select = $('#form_pickup_time');
|
||||
select.empty();
|
||||
|
||||
const currentTime = new Date();
|
||||
$.each(response.data, function (index, item) {
|
||||
function getEndTime() {
|
||||
const [startTime, endTime] = item.range.split('-');
|
||||
const [endHour, endMinute] = endTime.split(':');
|
||||
const endDate = new Date();
|
||||
endDate.setHours(parseInt(endHour));
|
||||
endDate.setMinutes(parseInt(endMinute));
|
||||
endDate.setSeconds(0);
|
||||
return endDate;
|
||||
}
|
||||
|
||||
const pickedDate = new Date($('#form_pickup_date').val());
|
||||
const isToday = pickedDate.toDateString() === currentTime.toDateString();
|
||||
const isAfterCurrentTime = getEndTime() > currentTime;
|
||||
|
||||
if ((isToday && isAfterCurrentTime) || !isToday) {
|
||||
const option = $('<option></option>')
|
||||
.attr('value', item.range)
|
||||
.text(item.range);
|
||||
select.append(option);
|
||||
}
|
||||
});
|
||||
|
||||
const jsonString = JSON.stringify(response.data);
|
||||
select.attr('data-timeframes', jsonString);
|
||||
select.val(response.data.length > 0 ? response.data[0].range : '').change();
|
||||
|
||||
$('#pickupTimeContainer').show();
|
||||
} else if (response.success === false && response.errors && response.errors.length > 0) {
|
||||
$('.errorMessagePickupCourier').text(response.errors[0]);
|
||||
$('.errorMessagePickupCourier').show();
|
||||
} else {
|
||||
$('.errorMessagePickupCourier').text('Unknown error');
|
||||
$('.errorMessagePickupCourier').show();
|
||||
}
|
||||
}, error: function () {
|
||||
$('.errorMessagePickupCourier').text('Unknown error');
|
||||
$('.errorMessagePickupCourier').show();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$('#pickup-courier-add-save-button').on('click', function (event) {
|
||||
event.preventDefault();
|
||||
$('.errorMessagePickupCourier').hide();
|
||||
|
||||
const form = document.getElementById('dpdshipping_pickup_courier_form');
|
||||
|
||||
if (!form.checkValidity()) {
|
||||
form.reportValidity();
|
||||
return;
|
||||
}
|
||||
if (!validateAddPickupCourier())
|
||||
return;
|
||||
|
||||
|
||||
const pickupOrderSettingsId = $('#form_dpdshipping_pickup_courier_sender_address').val()
|
||||
|
||||
$.ajax({
|
||||
url: dpdshipping_pickup_courier_pickup_courier_ajax_url, method: 'POST', data: {
|
||||
pickupOrderSettingsId: pickupOrderSettingsId,
|
||||
customerFullName: $('#form_customer_company').val(),
|
||||
customerName: $('#form_customer_name').val(),
|
||||
customerPhone: $('#form_customer_phone').val(),
|
||||
senderFullName: $('#senderFullName').text(),
|
||||
senderName: $('#senderName').text(),
|
||||
senderAddress: $('#senderAddress').text(),
|
||||
senderPostalCode: $('#senderPostalCode').text(),
|
||||
senderCity: $('#senderCity').text(),
|
||||
senderCountryCode: $('#senderCountryCode').text(),
|
||||
senderPhone: $('#senderPhone').text(),
|
||||
payerNumber: $('#payerNumber').text(),
|
||||
payerName: "DPD_API",
|
||||
pickupDate: $('#form_pickup_date').val(),
|
||||
pickupTime: $('#form_pickup_time').val(),
|
||||
letters: $('#form_letters').is(':checked'),
|
||||
lettersCount: $('#form_letters_count').val(),
|
||||
packages: $('#form_packages').is(':checked'),
|
||||
packagesCount: $('#form_packages_count').val(),
|
||||
packagesWeightSum: $('#form_packages_weight_sum').val(),
|
||||
packagesWeightMax: $('#form_packages_weight_max').val(),
|
||||
packagesSizeXMax: $('#form_packages_size_x_max').val(),
|
||||
packagesSizeYMax: $('#form_packages_size_y_max').val(),
|
||||
packagesSizeZMax: $('#form_packages_size_z_max').val(),
|
||||
palette: $('#form_palette').is(':checked'),
|
||||
paletteCount: $('#form_palette_count').val(),
|
||||
paletteWeightSum: $('#form_palette_weight_sum').val(),
|
||||
paletteWeightMx: $('#form_palette_weight_max').val(),
|
||||
paletteSizeYMax: $('#form_palette_size_y_max').val(),
|
||||
token: dpdshipping_token
|
||||
}, success: function (response, status, xhr) {
|
||||
if (response.success === true && response.data !== null) {
|
||||
window.location.href = response.data.redirectPath;
|
||||
} else if (response.success === false && response.errors && response.errors.length > 0) {
|
||||
$('.errorMessagePickupCourier').text(response.errors[0]);
|
||||
$('.errorMessagePickupCourier').show();
|
||||
} else {
|
||||
$('.errorMessagePickupCourier').text('Unknown error');
|
||||
$('.errorMessagePickupCourier').show();
|
||||
}
|
||||
}, error: function () {
|
||||
$('.errorMessagePickupCourier').text('Unknown error');
|
||||
$('.errorMessagePickupCourier').show();
|
||||
}
|
||||
});
|
||||
|
||||
function isEmptyInputData(fields) {
|
||||
return fields.some(function (selector) {
|
||||
return !$.trim($(selector).val()) && !$.trim($(selector).text());
|
||||
});
|
||||
}
|
||||
|
||||
function validateAddPickupCourier() {
|
||||
function showError(errorMsg) {
|
||||
$('.errorMessagePickupCourier').text(errorMsg);
|
||||
$('.errorMessagePickupCourier').show();
|
||||
}
|
||||
|
||||
if (isEmptyInputData([
|
||||
'#form_customer_company',
|
||||
'#form_customer_name',
|
||||
'#form_customer_phone'])) {
|
||||
showError(dpdshipping_pickup_courier_pickup_courier_ajax_empty_customer);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isEmptyInputData([
|
||||
'#senderFullName',
|
||||
'#senderName',
|
||||
'#senderAddress',
|
||||
'#senderPostalCode',
|
||||
'#senderCity',
|
||||
'#senderCountryCode',
|
||||
'#senderPhone',
|
||||
])) {
|
||||
showError(dpdshipping_pickup_courier_pickup_courier_ajax_empty_sender);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isEmptyInputData([
|
||||
'#payerNumber',
|
||||
])) {
|
||||
showError(dpdshipping_pickup_courier_pickup_courier_ajax_empty_payer);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isEmptyInputData([
|
||||
'#form_pickup_date',
|
||||
'#form_pickup_time',
|
||||
])) {
|
||||
showError(dpdshipping_pickup_courier_pickup_courier_ajax_empty_pickup_date_time);
|
||||
return false;
|
||||
}
|
||||
if (!$('#form_letters').is(':checked') &&
|
||||
!$('#form_packages').is(':checked') &&
|
||||
!$('#form_palette').is(':checked')) {
|
||||
showError(dpdshipping_pickup_courier_pickup_courier_ajax_empty_parcel);
|
||||
return false;
|
||||
}
|
||||
if ($('#form_letters').is(':checked')) {
|
||||
if (isEmptyInputData([
|
||||
'#form_letters_count',
|
||||
])) {
|
||||
showError(dpdshipping_pickup_courier_pickup_courier_ajax_empty_letters);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if ($('#form_packages').is(':checked')) {
|
||||
if (isEmptyInputData([
|
||||
'#form_packages_count',
|
||||
'#form_packages_weight_sum',
|
||||
'#form_packages_weight_max',
|
||||
'#form_packages_size_x_max',
|
||||
'#form_packages_size_y_max',
|
||||
'#form_packages_size_z_max',
|
||||
])) {
|
||||
showError(dpdshipping_pickup_courier_pickup_courier_ajax_empty_packages);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if ($('#form_palette').is(':checked')) {
|
||||
if (isEmptyInputData([
|
||||
'#form_palette_count',
|
||||
'#form_palette_weight_sum',
|
||||
'#form_palette_weight_max',
|
||||
'#form_palette_size_y_max'
|
||||
])) {
|
||||
showError(dpdshipping_pickup_courier_pickup_courier_ajax_empty_palette);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
$('#form_pickup_time').on('change', function (event) {
|
||||
const selectedRange = $(this).val();
|
||||
const timeFrames = $('#form_pickup_time').data('timeframes');
|
||||
const selectedTimeFrame = timeFrames.find(tf => tf.range === selectedRange);
|
||||
|
||||
function getFormatedHour() {
|
||||
const rangeParts = selectedTimeFrame.range.split('-');
|
||||
const startTime = rangeParts[0];
|
||||
|
||||
const startDate = new Date();
|
||||
const [startHour, startMinute] = startTime.split(':');
|
||||
startDate.setHours(parseInt(startHour));
|
||||
startDate.setMinutes(parseInt(startMinute));
|
||||
startDate.setSeconds(0);
|
||||
|
||||
const offsetDate = new Date(startDate.getTime() - selectedTimeFrame.offset * 60000);
|
||||
|
||||
const offsetHour = offsetDate.getHours().toString().padStart(2, '0');
|
||||
const offsetMinute = offsetDate.getMinutes().toString().padStart(2, '0');
|
||||
return `${offsetHour}:${offsetMinute}`;
|
||||
}
|
||||
|
||||
if (selectedTimeFrame) {
|
||||
$('#timeFrameHour').text(getFormatedHour());
|
||||
$('#timeFrameDate').text($('#form_pickup_date').val());
|
||||
} else {
|
||||
console.error('No matching time frame found for the selected range:', selectedRange);
|
||||
}
|
||||
});
|
||||
});
|
||||
114
modules/dpdshipping/views/js/dpdshipping-pickup-courier.js
Normal file
114
modules/dpdshipping/views/js/dpdshipping-pickup-courier.js
Normal file
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
* Copyright 2024 DPD Polska Sp. z o.o.
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* Licensed under the EUPL-1.2 or later.
|
||||
* You may not use this work except in compliance with the Licence.
|
||||
*
|
||||
* You may obtain a copy of the Licence at:
|
||||
* https://joinup.ec.europa.eu/software/page/eupl
|
||||
* It is also bundled with this package in the file LICENSE.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the Licence is distributed on an AS IS basis,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the Licence for the specific language governing permissions
|
||||
* and limitations under the Licence.
|
||||
*
|
||||
* @author DPD Polska Sp. z o.o.
|
||||
* @copyright 2024 DPD Polska Sp. z o.o.
|
||||
* @license https://joinup.ec.europa.eu/software/page/eupl
|
||||
*/
|
||||
|
||||
$(document).ready(function () {
|
||||
|
||||
setLetterFields($('#form_letters'))
|
||||
setPackageFields($('#form_packages'))
|
||||
setPaletteFields($('#form_palette'))
|
||||
|
||||
$(document).on('change', '#form_letters', function () {
|
||||
setLetterFields($('#form_letters'));
|
||||
});
|
||||
|
||||
$(document).on('change', '#form_packages', function () {
|
||||
setPackageFields($('#form_packages'));
|
||||
});
|
||||
|
||||
$(document).on('change', '#form_palette', function () {
|
||||
setPaletteFields($('#form_palette'));
|
||||
});
|
||||
|
||||
|
||||
function checkConfigurationWarning() {
|
||||
if ($('#form_dpdshipping_pickup_courier_sender_address option').length <= 1) {
|
||||
$('.warnMessagePickupCourier').text(dpdshipping_pickup_courier_pickup_courier_empty_configuration);
|
||||
$('.warnMessagePickupCourier').show();
|
||||
}
|
||||
}
|
||||
|
||||
checkConfigurationWarning()
|
||||
|
||||
function setLetterFields(input) {
|
||||
function getLetterFields() {
|
||||
return $("label[for='form_letters_count'], #form_letters_count");
|
||||
}
|
||||
|
||||
if (input.is(':checked')) {
|
||||
getLetterFields().show();
|
||||
$('#form_palette').prop("checked", false);
|
||||
$('#form_packages').prop("checked", false);
|
||||
} else {
|
||||
getLetterFields().hide();
|
||||
$('#form_letters_count').val(undefined);
|
||||
}
|
||||
}
|
||||
|
||||
function setPackageFields(input) {
|
||||
function getPackagesFields() {
|
||||
return $(
|
||||
"label[for='form_packages_count'], #form_packages_count, " +
|
||||
"label[for='form_packages_weight_sum'], #form_packages_weight_sum, " +
|
||||
"label[for='form_packages_weight_max'], #form_packages_weight_max, " +
|
||||
"label[for='form_packages_size_x_max'], #form_packages_size_x_max, " +
|
||||
"label[for='form_packages_size_y_max'], #form_packages_size_y_max, " +
|
||||
"label[for='form_packages_size_z_max'], #form_packages_size_z_max");
|
||||
}
|
||||
|
||||
if (input.is(':checked')) {
|
||||
getPackagesFields().show();
|
||||
$('#form_letters').prop("checked", false);
|
||||
$('#form_palette').prop("checked", false);
|
||||
} else {
|
||||
getPackagesFields().hide();
|
||||
$('#form_packages_count').val(undefined);
|
||||
$('#form_packages_weight_sum').val(undefined);
|
||||
$('#form_packages_weight_max').val(undefined);
|
||||
$('#form_packages_size_x_max').val(undefined);
|
||||
$('#form_packages_size_y_max').val(undefined);
|
||||
$('#form_packages_size_z_max').val(undefined);
|
||||
}
|
||||
}
|
||||
|
||||
function setPaletteFields(input) {
|
||||
function getPaletteFields() {
|
||||
return $(
|
||||
"label[for='form_palette_count'], #form_palette_count, " +
|
||||
"label[for='form_palette_weight_sum'], #form_palette_weight_sum, " +
|
||||
"label[for='form_palette_weight_max'], #form_palette_weight_max, " +
|
||||
"label[for='form_palette_size_y_max'], #form_palette_size_y_max");
|
||||
}
|
||||
|
||||
if (input.is(':checked')) {
|
||||
getPaletteFields().show();
|
||||
$('#form_letters').prop("checked", false);
|
||||
$('#form_packages').prop("checked", false);
|
||||
} else {
|
||||
getPaletteFields().hide();
|
||||
$('#form_palette_count').val(undefined);
|
||||
$('#form_palette_weight_sum').val(undefined);
|
||||
$('#form_palette_weight_max').val(undefined);
|
||||
$('#form_palette_size_y_max').val(undefined);
|
||||
}
|
||||
}
|
||||
});
|
||||
216
modules/dpdshipping/views/js/dpdshipping-pudo-cod-iframe.js
Normal file
216
modules/dpdshipping/views/js/dpdshipping-pudo-cod-iframe.js
Normal file
@@ -0,0 +1,216 @@
|
||||
/*
|
||||
* Copyright 2024 DPD Polska Sp. z o.o.
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* Licensed under the EUPL-1.2 or later.
|
||||
* You may not use this work except in compliance with the Licence.
|
||||
*
|
||||
* You may obtain a copy of the Licence at:
|
||||
* https://joinup.ec.europa.eu/software/page/eupl
|
||||
* It is also bundled with this package in the file LICENSE.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the Licence is distributed on an AS IS basis,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the Licence for the specific language governing permissions
|
||||
* and limitations under the Licence.
|
||||
*
|
||||
* @author DPD Polska Sp. z o.o.
|
||||
* @copyright 2024 DPD Polska Sp. z o.o.
|
||||
* @license https://joinup.ec.europa.eu/software/page/eupl
|
||||
*/
|
||||
|
||||
// noinspection JSUnresolvedReference
|
||||
|
||||
console.log('[DPD Pudo COD] Skrypt załadowany');
|
||||
|
||||
if (typeof dpsShippingCodEventCreated == 'undefined') {
|
||||
var dpsShippingCodEventCreated = false;
|
||||
}
|
||||
|
||||
if (typeof dpsShippingCodIframeCreated == 'undefined') {
|
||||
var dpsShippingCodIframeCreated = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tworzy iframe dla mapy PUDO COD
|
||||
*/
|
||||
function dpsShippingCodCreateIframe() {
|
||||
console.log('[DPD Pudo COD] Próba utworzenia iframe...');
|
||||
|
||||
// Sprawdź czy iframe już istnieje
|
||||
if (document.getElementById("dpdshipping-widget-pudo-cod-iframe")) {
|
||||
console.log('[DPD Pudo COD] Iframe już istnieje');
|
||||
return true;
|
||||
}
|
||||
|
||||
// Walidacja: sprawdź czy URL iframe jest zdefiniowany
|
||||
if (typeof dpdshipping_iframe_cod_url === 'undefined' || !dpdshipping_iframe_cod_url) {
|
||||
console.error('[DPD Pudo COD] Błąd: dpdshipping_iframe_cod_url nie jest zdefiniowany lub jest pusty');
|
||||
return false;
|
||||
}
|
||||
|
||||
// Walidacja: sprawdź czy element docelowy istnieje
|
||||
var dpsShippingCod_script = document.getElementById("dpdshipping-widget-pudo-cod");
|
||||
if (!dpsShippingCod_script) {
|
||||
console.error('[DPD Pudo COD] Błąd: Nie znaleziono elementu #dpdshipping-widget-pudo-cod');
|
||||
return false;
|
||||
}
|
||||
|
||||
var dpsShippingCod_iframe = document.createElement("iframe");
|
||||
dpsShippingCod_iframe.setAttribute("id", "dpdshipping-widget-pudo-cod-iframe");
|
||||
dpsShippingCod_iframe.setAttribute("allow", "geolocation");
|
||||
dpsShippingCod_iframe.style.width = "100%";
|
||||
dpsShippingCod_iframe.style.border = "none";
|
||||
dpsShippingCod_iframe.style.minHeight = "400px";
|
||||
dpsShippingCod_iframe.style.height = "768px";
|
||||
|
||||
dpsShippingCod_iframe.onerror = function() {
|
||||
console.error('[DPD Pudo COD] Błąd ładowania iframe');
|
||||
};
|
||||
|
||||
dpsShippingCod_iframe.onload = function() {
|
||||
console.log('[DPD Pudo COD] Iframe załadowany pomyślnie');
|
||||
};
|
||||
|
||||
dpsShippingCod_iframe.src = dpdshipping_iframe_cod_url;
|
||||
|
||||
dpsShippingCod_script.parentNode.insertBefore(dpsShippingCod_iframe, dpsShippingCod_script);
|
||||
console.log('[DPD Pudo COD] Iframe dodany do DOM, URL:', dpdshipping_iframe_cod_url);
|
||||
|
||||
window.dpsShippingCod_iframe = dpsShippingCod_iframe;
|
||||
dpsShippingCodIframeCreated = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Obserwator DOM
|
||||
function dpsShippingCodObserveDOM() {
|
||||
if (document.getElementById("dpdshipping-widget-pudo-cod")) {
|
||||
console.log('[DPD Pudo COD] Element znaleziony w DOM');
|
||||
dpsShippingCodCreateIframe();
|
||||
return;
|
||||
}
|
||||
|
||||
if (typeof MutationObserver !== 'undefined') {
|
||||
console.log('[DPD Pudo COD] Uruchamiam MutationObserver...');
|
||||
var observer = new MutationObserver(function() {
|
||||
if (document.getElementById("dpdshipping-widget-pudo-cod")) {
|
||||
console.log('[DPD Pudo COD] Element pojawił się w DOM (MutationObserver)');
|
||||
observer.disconnect();
|
||||
dpsShippingCodCreateIframe();
|
||||
}
|
||||
});
|
||||
observer.observe(document.body, { childList: true, subtree: true });
|
||||
|
||||
setTimeout(function() {
|
||||
observer.disconnect();
|
||||
}, 30000);
|
||||
}
|
||||
}
|
||||
|
||||
if (document.readyState === 'loading') {
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
console.log('[DPD Pudo COD] DOMContentLoaded');
|
||||
dpsShippingCodObserveDOM();
|
||||
});
|
||||
} else {
|
||||
console.log('[DPD Pudo COD] DOM już załadowany');
|
||||
dpsShippingCodObserveDOM();
|
||||
}
|
||||
|
||||
$(document).ready(function() {
|
||||
console.log('[DPD Pudo COD] jQuery ready');
|
||||
|
||||
$(document).on('click', '.dpdshipping-pudo-cod-open-map-btn, .dpdshipping-pudo-cod-change-map-btn', function() {
|
||||
console.log('[DPD Pudo COD] Kliknięto przycisk otwierania mapy');
|
||||
setTimeout(function() {
|
||||
dpsShippingCodCreateIframe();
|
||||
}, 200);
|
||||
});
|
||||
|
||||
$(document).on('show.bs.modal shown.bs.modal', '#dpdshippingPudoCodModal', function() {
|
||||
console.log('[DPD Pudo COD] Modal pokazywany');
|
||||
dpsShippingCodCreateIframe();
|
||||
});
|
||||
});
|
||||
|
||||
if (!dpsShippingCodEventCreated) {
|
||||
var dpsShippingCod_eventListener = window[window.addEventListener ? "addEventListener" : "attachEvent"];
|
||||
var dpsShippingCod_messageEvent = ("attachEvent" === dpsShippingCod_eventListener) ? "onmessage" : "message";
|
||||
dpsShippingCod_eventListener(dpsShippingCod_messageEvent, function (a) {
|
||||
if (typeof getDpdshippingIdPudoCodCarrier !== 'function' || typeof getDpdshippingSelectedCarrier !== 'function') {
|
||||
return;
|
||||
}
|
||||
if (getDpdshippingIdPudoCodCarrier() === getDpdshippingSelectedCarrier()) {
|
||||
var iframe = window.dpsShippingCod_iframe || document.getElementById("dpdshipping-widget-pudo-cod-iframe");
|
||||
if (a.data && a.data.height && !isNaN(a.data.height)) {
|
||||
if (iframe) {
|
||||
iframe.style.height = a.data.height + "px";
|
||||
}
|
||||
} else if (a.data && a.data.point_id) {
|
||||
dpdShippingCodPointSelected(a.data.point_id);
|
||||
}
|
||||
}
|
||||
}, !1);
|
||||
dpsShippingCodEventCreated = true;
|
||||
}
|
||||
|
||||
function dpdShippingCodPointSelected(pudoCode) {
|
||||
if (!pudoCode) {
|
||||
console.error('[DPD Pudo COD] Błąd: Brak kodu punktu');
|
||||
return;
|
||||
}
|
||||
|
||||
$('.container_dpdshipping_pudo_cod_error').css("display", "none");
|
||||
$('.dpdshipping-pudo-cod-new-point').css("display", "none");
|
||||
$('.dpdshipping-pudo-cod-selected-point').css("display", "block");
|
||||
|
||||
if (typeof dpdshippingSavePudoCode === 'function') {
|
||||
dpdshippingSavePudoCode(pudoCode, $('#dpdshippingPudoCodModal'));
|
||||
}
|
||||
|
||||
if (typeof dpdshippingGetPudoAddress === 'function') {
|
||||
dpdshippingGetPudoAddress(pudoCode, $('.dpdshipping-cod-selected-point'));
|
||||
}
|
||||
|
||||
if (typeof dpdshippingIsPointWithCod === 'function') {
|
||||
dpdshippingIsPointWithCod(pudoCode);
|
||||
} else {
|
||||
dpdshippingIsPointWithCodInternal(pudoCode);
|
||||
}
|
||||
|
||||
console.log('[DPD Pudo COD] Wybrano punkt:', pudoCode);
|
||||
}
|
||||
|
||||
function dpdshippingIsPointWithCodInternal(pudoCode) {
|
||||
if (typeof dpdshipping_pickup_is_point_with_cod_ajax_url === 'undefined') {
|
||||
console.error('[DPD Pudo COD] Brak URL dla sprawdzenia COD');
|
||||
return;
|
||||
}
|
||||
|
||||
$.ajax({
|
||||
url: dpdshipping_pickup_is_point_with_cod_ajax_url,
|
||||
type: 'GET',
|
||||
data: {
|
||||
dpdshipping_token: dpdshipping_token,
|
||||
dpdshipping_csrf: dpdshipping_csrf,
|
||||
dpdshipping_pudo_code: pudoCode
|
||||
},
|
||||
success: function (response) {
|
||||
var resultJson = JSON.parse(response);
|
||||
if (resultJson.success && resultJson.data && Number(resultJson.data) === 1) {
|
||||
$('.container_dpdshipping_pudo_cod_warning').css("display", "none");
|
||||
} else {
|
||||
$('.container_dpdshipping_pudo_cod_warning').css("display", "block");
|
||||
if (typeof dpdshippingDisableOrderProcessBtn === 'function') {
|
||||
dpdshippingDisableOrderProcessBtn();
|
||||
}
|
||||
}
|
||||
},
|
||||
error: function (error) {
|
||||
console.error('[DPD Pudo COD] Błąd sprawdzania COD:', error);
|
||||
}
|
||||
});
|
||||
}
|
||||
30
modules/dpdshipping/views/js/dpdshipping-pudo-default.js
Normal file
30
modules/dpdshipping/views/js/dpdshipping-pudo-default.js
Normal file
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright 2024 DPD Polska Sp. z o.o.
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* Licensed under the EUPL-1.2 or later.
|
||||
* You may not use this work except in compliance with the Licence.
|
||||
*
|
||||
* You may obtain a copy of the Licence at:
|
||||
* https://joinup.ec.europa.eu/software/page/eupl
|
||||
* It is also bundled with this package in the file LICENSE.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the Licence is distributed on an AS IS basis,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the Licence for the specific language governing permissions
|
||||
* and limitations under the Licence.
|
||||
*
|
||||
* @author DPD Polska Sp. z o.o.
|
||||
* @copyright 2024 DPD Polska Sp. z o.o.
|
||||
* @license https://joinup.ec.europa.eu/software/page/eupl
|
||||
*/
|
||||
|
||||
function dpdshippingDisableOrderProcessBtn() {
|
||||
$('button[name="confirmDeliveryOption"]').attr('disabled', 'disabled');
|
||||
}
|
||||
|
||||
function dpdshippingEnableOrderProcessBtn() {
|
||||
$('button[name="confirmDeliveryOption"]').removeAttr('disabled');
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright 2025 DPD Polska Sp. z o. o.
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* Licensed under the EUPL-1.2 or later.
|
||||
* You may not use this work except in compliance with the Licence.
|
||||
*
|
||||
* You may obtain a copy of the Licence at:
|
||||
* https://joinup.ec.europa.eu/software/page/eupl
|
||||
* It is also bundled with this package in the file LICENSE.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the Licence is distributed on an AS IS basis,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the Licence for the specific language governing permissions
|
||||
* and limitations under the Licence.
|
||||
*
|
||||
* @author DPD Polska Sp. z o.o.
|
||||
* @copyright 2025 DPD Polska Sp. z o.o.
|
||||
* @license https://joinup.ec.europa.eu/software/page/eupl
|
||||
*/
|
||||
|
||||
$(document).ready(function () {
|
||||
setTimeout(() => {
|
||||
handleDpdShippingPudo()
|
||||
}, 2000);
|
||||
})
|
||||
|
||||
function dpdshippingDisableOrderProcessBtn() {
|
||||
$("#payment-confirmation button").prop("disabled", true);
|
||||
$("#payment-confirmation a").addClass("disabled").attr("aria-disabled", "true");
|
||||
}
|
||||
|
||||
function dpdshippingEnableOrderProcessBtn() {
|
||||
$("#payment-confirmation button").prop("disabled", false);
|
||||
$("#payment-confirmation a").removeClass("disabled").removeAttr("aria-disabled");
|
||||
}
|
||||
179
modules/dpdshipping/views/js/dpdshipping-pudo-iframe.js
Normal file
179
modules/dpdshipping/views/js/dpdshipping-pudo-iframe.js
Normal file
@@ -0,0 +1,179 @@
|
||||
/*
|
||||
* Copyright 2024 DPD Polska Sp. z o.o.
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* Licensed under the EUPL-1.2 or later.
|
||||
* You may not use this work except in compliance with the Licence.
|
||||
*
|
||||
* You may obtain a copy of the Licence at:
|
||||
* https://joinup.ec.europa.eu/software/page/eupl
|
||||
* It is also bundled with this package in the file LICENSE.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the Licence is distributed on an AS IS basis,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the Licence for the specific language governing permissions
|
||||
* and limitations under the Licence.
|
||||
*
|
||||
* @author DPD Polska Sp. z o.o.
|
||||
* @copyright 2024 DPD Polska Sp. z o.o.
|
||||
* @license https://joinup.ec.europa.eu/software/page/eupl
|
||||
*/
|
||||
|
||||
// noinspection JSUnresolvedReference
|
||||
|
||||
console.log('[DPD Pudo] Skrypt załadowany');
|
||||
|
||||
if (typeof dpdshippingEventCreated == 'undefined') {
|
||||
var dpdshippingEventCreated = false;
|
||||
}
|
||||
|
||||
if (typeof dpdshippingIframeCreated == 'undefined') {
|
||||
var dpdshippingIframeCreated = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tworzy iframe dla mapy PUDO
|
||||
*/
|
||||
function dpdshippingCreateIframe() {
|
||||
console.log('[DPD Pudo] Próba utworzenia iframe...');
|
||||
|
||||
// Sprawdź czy iframe już istnieje
|
||||
if (document.getElementById("dpdshipping-widget-pudo-iframe")) {
|
||||
console.log('[DPD Pudo] Iframe już istnieje');
|
||||
return true;
|
||||
}
|
||||
|
||||
// Walidacja: sprawdź czy URL iframe jest zdefiniowany
|
||||
if (typeof dpdshipping_iframe_url === 'undefined' || !dpdshipping_iframe_url) {
|
||||
console.error('[DPD Pudo] Błąd: dpdshipping_iframe_url nie jest zdefiniowany lub jest pusty');
|
||||
return false;
|
||||
}
|
||||
|
||||
// Walidacja: sprawdź czy element docelowy istnieje
|
||||
var dpdshipping_script = document.getElementById("dpdshipping-widget-pudo");
|
||||
if (!dpdshipping_script) {
|
||||
console.error('[DPD Pudo] Błąd: Nie znaleziono elementu #dpdshipping-widget-pudo');
|
||||
return false;
|
||||
}
|
||||
|
||||
var dpdshipping_iframe = document.createElement("iframe");
|
||||
dpdshipping_iframe.setAttribute("id", "dpdshipping-widget-pudo-iframe");
|
||||
dpdshipping_iframe.setAttribute("allow", "geolocation");
|
||||
dpdshipping_iframe.style.width = "100%";
|
||||
dpdshipping_iframe.style.border = "none";
|
||||
dpdshipping_iframe.style.minHeight = "400px";
|
||||
dpdshipping_iframe.style.height = "768px";
|
||||
|
||||
dpdshipping_iframe.onerror = function() {
|
||||
console.error('[DPD Pudo] Błąd ładowania iframe');
|
||||
};
|
||||
|
||||
dpdshipping_iframe.onload = function() {
|
||||
console.log('[DPD Pudo] Iframe załadowany pomyślnie');
|
||||
};
|
||||
|
||||
dpdshipping_iframe.src = dpdshipping_iframe_url;
|
||||
|
||||
dpdshipping_script.parentNode.insertBefore(dpdshipping_iframe, dpdshipping_script);
|
||||
console.log('[DPD Pudo] Iframe dodany do DOM, URL:', dpdshipping_iframe_url);
|
||||
|
||||
window.dpdshipping_iframe = dpdshipping_iframe;
|
||||
dpdshippingIframeCreated = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Obserwator DOM
|
||||
function dpdshippingObserveDOM() {
|
||||
if (document.getElementById("dpdshipping-widget-pudo")) {
|
||||
console.log('[DPD Pudo] Element znaleziony w DOM');
|
||||
dpdshippingCreateIframe();
|
||||
return;
|
||||
}
|
||||
|
||||
if (typeof MutationObserver !== 'undefined') {
|
||||
console.log('[DPD Pudo] Uruchamiam MutationObserver...');
|
||||
var observer = new MutationObserver(function() {
|
||||
if (document.getElementById("dpdshipping-widget-pudo")) {
|
||||
console.log('[DPD Pudo] Element pojawił się w DOM (MutationObserver)');
|
||||
observer.disconnect();
|
||||
dpdshippingCreateIframe();
|
||||
}
|
||||
});
|
||||
observer.observe(document.body, { childList: true, subtree: true });
|
||||
|
||||
setTimeout(function() {
|
||||
observer.disconnect();
|
||||
}, 30000);
|
||||
}
|
||||
}
|
||||
|
||||
if (document.readyState === 'loading') {
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
console.log('[DPD Pudo] DOMContentLoaded');
|
||||
dpdshippingObserveDOM();
|
||||
});
|
||||
} else {
|
||||
console.log('[DPD Pudo] DOM już załadowany');
|
||||
dpdshippingObserveDOM();
|
||||
}
|
||||
|
||||
$(document).ready(function() {
|
||||
console.log('[DPD Pudo] jQuery ready');
|
||||
|
||||
$(document).on('click', '.dpdshipping-pudo-open-map-btn, .dpdshipping-pudo-change-map-btn', function() {
|
||||
console.log('[DPD Pudo] Kliknięto przycisk otwierania mapy');
|
||||
setTimeout(function() {
|
||||
dpdshippingCreateIframe();
|
||||
}, 200);
|
||||
});
|
||||
|
||||
$(document).on('show.bs.modal shown.bs.modal', '#dpdshippingPudoModal', function() {
|
||||
console.log('[DPD Pudo] Modal pokazywany');
|
||||
dpdshippingCreateIframe();
|
||||
});
|
||||
});
|
||||
|
||||
if (!dpdshippingEventCreated) {
|
||||
var dpdshipping_eventListener = window[window.addEventListener ? "addEventListener" : "attachEvent"];
|
||||
var dpdshipping_messageEvent = ("attachEvent" === dpdshipping_eventListener) ? "onmessage" : "message";
|
||||
dpdshipping_eventListener(dpdshipping_messageEvent, function (a) {
|
||||
if (typeof getDpdshippingIdPudoCarrier !== 'function' || typeof getDpdshippingSelectedCarrier !== 'function') {
|
||||
return;
|
||||
}
|
||||
if (getDpdshippingIdPudoCarrier() === getDpdshippingSelectedCarrier()) {
|
||||
var iframe = window.dpdshipping_iframe || document.getElementById("dpdshipping-widget-pudo-iframe");
|
||||
if (a.data && a.data.height && !isNaN(a.data.height)) {
|
||||
if (iframe) {
|
||||
iframe.style.height = a.data.height + "px";
|
||||
}
|
||||
} else if (a.data && a.data.point_id) {
|
||||
dpdShippingPointSelected(a.data.point_id);
|
||||
}
|
||||
}
|
||||
}, !1);
|
||||
dpdshippingEventCreated = true;
|
||||
}
|
||||
|
||||
function dpdShippingPointSelected(pudoCode) {
|
||||
if (!pudoCode) {
|
||||
console.error('[DPD Pudo] Błąd: Brak kodu punktu');
|
||||
return;
|
||||
}
|
||||
|
||||
$('.container_dpdshipping_pudo_error').css("display", "none");
|
||||
$('.dpdshipping-pudo-new-point').css("display", "none");
|
||||
$('.dpdshipping-pudo-selected-point').css("display", "block");
|
||||
|
||||
if (typeof dpdshippingSavePudoCode === 'function') {
|
||||
dpdshippingSavePudoCode(pudoCode, $('#dpdshippingPudoModal'));
|
||||
}
|
||||
|
||||
if (typeof dpdshippingGetPudoAddress === 'function') {
|
||||
dpdshippingGetPudoAddress(pudoCode, $('.dpdshipping-selected-point'));
|
||||
}
|
||||
|
||||
console.log('[DPD Pudo] Wybrano punkt:', pudoCode);
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright 2025 DPD Polska Sp. z o. o.
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* Licensed under the EUPL-1.2 or later.
|
||||
* You may not use this work except in compliance with the Licence.
|
||||
*
|
||||
* You may obtain a copy of the Licence at:
|
||||
* https://joinup.ec.europa.eu/software/page/eupl
|
||||
* It is also bundled with this package in the file LICENSE.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the Licence is distributed on an AS IS basis,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the Licence for the specific language governing permissions
|
||||
* and limitations under the Licence.
|
||||
*
|
||||
* @author DPD Polska Sp. z o.o.
|
||||
* @copyright 2025 DPD Polska Sp. z o.o.
|
||||
* @license https://joinup.ec.europa.eu/software/page/eupl
|
||||
*/
|
||||
|
||||
$(document).ready(function () {
|
||||
setTimeout(() => {
|
||||
handleDpdShippingPudo()
|
||||
}, 2000);
|
||||
})
|
||||
|
||||
function dpdshippingDisableOrderProcessBtn() {
|
||||
$("#confirm_order").css("pointer-events", "none");
|
||||
}
|
||||
|
||||
function dpdshippingEnableOrderProcessBtn() {
|
||||
$("#confirm_order").css("pointer-events", "auto");
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright 2025 DPD Polska Sp. z o. o.
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* Licensed under the EUPL-1.2 or later.
|
||||
* You may not use this work except in compliance with the Licence.
|
||||
*
|
||||
* You may obtain a copy of the Licence at:
|
||||
* https://joinup.ec.europa.eu/software/page/eupl
|
||||
* It is also bundled with this package in the file LICENSE.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the Licence is distributed on an AS IS basis,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the Licence for the specific language governing permissions
|
||||
* and limitations under the Licence.
|
||||
*
|
||||
* @author DPD Polska Sp. z o.o.
|
||||
* @copyright 2025 DPD Polska Sp. z o.o.
|
||||
* @license https://joinup.ec.europa.eu/software/page/eupl
|
||||
*/
|
||||
|
||||
$(document).ready(function () {
|
||||
setTimeout(() => {
|
||||
handleDpdShippingPudo()
|
||||
}, 2000);
|
||||
})
|
||||
|
||||
function dpdshippingDisableOrderProcessBtn() {
|
||||
$("#btn_place_order").css("pointer-events", "none");
|
||||
}
|
||||
|
||||
function dpdshippingEnableOrderProcessBtn() {
|
||||
$("#btn_place_order").css("pointer-events", "auto");
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright 2025 DPD Polska Sp. z o. o.
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* Licensed under the EUPL-1.2 or later.
|
||||
* You may not use this work except in compliance with the Licence.
|
||||
*
|
||||
* You may obtain a copy of the Licence at:
|
||||
* https://joinup.ec.europa.eu/software/page/eupl
|
||||
* It is also bundled with this package in the file LICENSE.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the Licence is distributed on an AS IS basis,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the Licence for the specific language governing permissions
|
||||
* and limitations under the Licence.
|
||||
*
|
||||
* @author DPD Polska Sp. z o.o.
|
||||
* @copyright 2025 DPD Polska Sp. z o.o.
|
||||
* @license https://joinup.ec.europa.eu/software/page/eupl
|
||||
*/
|
||||
|
||||
$(document).ready(function () {
|
||||
setTimeout(() => {
|
||||
handleDpdShippingPudo()
|
||||
}, 2000);
|
||||
})
|
||||
|
||||
function dpdshippingDisableOrderProcessBtn() {
|
||||
$("#opc_step_shipping_footer, #opc_step_payment_header").css("pointer-events", "none");
|
||||
}
|
||||
|
||||
function dpdshippingEnableOrderProcessBtn() {
|
||||
$("#opc_step_shipping_footer, #opc_step_payment_header").css("pointer-events", "auto");
|
||||
}
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright 2024 DPD Polska Sp. z o.o.
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* Licensed under the EUPL-1.2 or later.
|
||||
* You may not use this work except in compliance with the Licence.
|
||||
*
|
||||
* You may obtain a copy of the Licence at:
|
||||
* https://joinup.ec.europa.eu/software/page/eupl
|
||||
* It is also bundled with this package in the file LICENSE.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the Licence is distributed on an AS IS basis,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the Licence for the specific language governing permissions
|
||||
* and limitations under the Licence.
|
||||
*
|
||||
* @author DPD Polska Sp. z o.o.
|
||||
* @copyright 2024 DPD Polska Sp. z o.o.
|
||||
* @license https://joinup.ec.europa.eu/software/page/eupl
|
||||
*/
|
||||
|
||||
$(document).ready(function () {
|
||||
setTimeout(() => {
|
||||
handleDpdShippingPudo()
|
||||
}, 2000);
|
||||
})
|
||||
|
||||
function dpdshippingDisableOrderProcessBtn() {
|
||||
$('#supercheckout_confirm_order').attr('disabled', 'disabled');
|
||||
$('#supercheckout_confirm_order').css('pointer-events', 'none');
|
||||
}
|
||||
|
||||
function dpdshippingEnableOrderProcessBtn() {
|
||||
$('#supercheckout_confirm_order').removeAttr('disabled');
|
||||
$('#supercheckout_confirm_order').css('pointer-events', '');
|
||||
}
|
||||
203
modules/dpdshipping/views/js/dpdshipping-pudo-swipbox-iframe.js
Normal file
203
modules/dpdshipping/views/js/dpdshipping-pudo-swipbox-iframe.js
Normal file
@@ -0,0 +1,203 @@
|
||||
/*
|
||||
* Copyright 2024 DPD Polska Sp. z o.o.
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* Licensed under the EUPL-1.2 or later.
|
||||
* You may not use this work except in compliance with the Licence.
|
||||
*
|
||||
* You may obtain a copy of the Licence at:
|
||||
* https://joinup.ec.europa.eu/software/page/eupl
|
||||
* It is also bundled with this package in the file LICENSE.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the Licence is distributed on an AS IS basis,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the Licence for the specific language governing permissions
|
||||
* and limitations under the Licence.
|
||||
*
|
||||
* @author DPD Polska Sp. z o.o.
|
||||
* @copyright 2024 DPD Polska Sp. z o.o.
|
||||
* @license https://joinup.ec.europa.eu/software/page/eupl
|
||||
*/
|
||||
|
||||
// noinspection JSUnresolvedReference
|
||||
|
||||
console.log('[DPD SwipBox] Skrypt załadowany');
|
||||
|
||||
if (typeof dpsShippingSwipBoxEventCreated == 'undefined') {
|
||||
var dpsShippingSwipBoxEventCreated = false;
|
||||
}
|
||||
|
||||
if (typeof dpsShippingSwipBoxIframeCreated == 'undefined') {
|
||||
var dpsShippingSwipBoxIframeCreated = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tworzy iframe dla mapy SwipBox - wywoływane przy otwieraniu modala
|
||||
*/
|
||||
function dpsShippingSwipBoxCreateIframe() {
|
||||
console.log('[DPD SwipBox] Próba utworzenia iframe...');
|
||||
|
||||
// Sprawdź czy iframe już istnieje
|
||||
if (document.getElementById("dpdshipping-widget-pudo-swipbox-iframe")) {
|
||||
console.log('[DPD SwipBox] Iframe już istnieje');
|
||||
return true;
|
||||
}
|
||||
|
||||
// Walidacja: sprawdź czy URL iframe jest zdefiniowany
|
||||
if (typeof dpdshipping_iframe_swipbox_url === 'undefined' || !dpdshipping_iframe_swipbox_url) {
|
||||
console.error('[DPD SwipBox] Błąd: dpdshipping_iframe_swipbox_url nie jest zdefiniowany lub jest pusty');
|
||||
console.error('[DPD SwipBox] Dostępne zmienne:', {
|
||||
dpdshipping_iframe_swipbox_url: typeof dpdshipping_iframe_swipbox_url !== 'undefined' ? dpdshipping_iframe_swipbox_url : 'UNDEFINED',
|
||||
dpdshipping_id_pudo_swipbox_carrier: typeof dpdshipping_id_pudo_swipbox_carrier !== 'undefined' ? dpdshipping_id_pudo_swipbox_carrier : 'UNDEFINED'
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
// Walidacja: sprawdź czy element docelowy istnieje
|
||||
var dpsShippingSwipBox_script = document.getElementById("dpdshipping-widget-pudo-swipbox");
|
||||
if (!dpsShippingSwipBox_script) {
|
||||
console.error('[DPD SwipBox] Błąd: Nie znaleziono elementu #dpdshipping-widget-pudo-swipbox');
|
||||
return false;
|
||||
}
|
||||
|
||||
var dpsShippingSwipBox_iframe = document.createElement("iframe");
|
||||
dpsShippingSwipBox_iframe.setAttribute("id", "dpdshipping-widget-pudo-swipbox-iframe");
|
||||
dpsShippingSwipBox_iframe.setAttribute("allow", "geolocation");
|
||||
dpsShippingSwipBox_iframe.style.width = "100%";
|
||||
dpsShippingSwipBox_iframe.style.border = "none";
|
||||
dpsShippingSwipBox_iframe.style.minHeight = "400px";
|
||||
dpsShippingSwipBox_iframe.style.height = "768px";
|
||||
|
||||
// Obsługa błędów ładowania iframe
|
||||
dpsShippingSwipBox_iframe.onerror = function() {
|
||||
console.error('[DPD SwipBox] Błąd ładowania iframe');
|
||||
};
|
||||
|
||||
dpsShippingSwipBox_iframe.onload = function() {
|
||||
console.log('[DPD SwipBox] Iframe załadowany pomyślnie');
|
||||
};
|
||||
|
||||
// Ustaw src
|
||||
dpsShippingSwipBox_iframe.src = dpdshipping_iframe_swipbox_url;
|
||||
|
||||
dpsShippingSwipBox_script.parentNode.insertBefore(dpsShippingSwipBox_iframe, dpsShippingSwipBox_script);
|
||||
console.log('[DPD SwipBox] Iframe dodany do DOM, URL:', dpdshipping_iframe_swipbox_url);
|
||||
|
||||
// Eksportuj iframe do globalnego scope
|
||||
window.dpsShippingSwipBox_iframe = dpsShippingSwipBox_iframe;
|
||||
dpsShippingSwipBoxIframeCreated = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Obserwator DOM - czeka na pojawienie się elementu
|
||||
function dpsShippingSwipBoxObserveDOM() {
|
||||
// Sprawdź czy element już istnieje
|
||||
if (document.getElementById("dpdshipping-widget-pudo-swipbox")) {
|
||||
console.log('[DPD SwipBox] Element znaleziony w DOM');
|
||||
dpsShippingSwipBoxCreateIframe();
|
||||
return;
|
||||
}
|
||||
|
||||
// Jeśli nie ma, obserwuj zmiany w DOM
|
||||
if (typeof MutationObserver !== 'undefined') {
|
||||
console.log('[DPD SwipBox] Uruchamiam MutationObserver...');
|
||||
var observer = new MutationObserver(function(mutations) {
|
||||
if (document.getElementById("dpdshipping-widget-pudo-swipbox")) {
|
||||
console.log('[DPD SwipBox] Element pojawił się w DOM (MutationObserver)');
|
||||
observer.disconnect();
|
||||
dpsShippingSwipBoxCreateIframe();
|
||||
}
|
||||
});
|
||||
observer.observe(document.body, { childList: true, subtree: true });
|
||||
|
||||
// Timeout - zatrzymaj obserwację po 30 sekundach
|
||||
setTimeout(function() {
|
||||
observer.disconnect();
|
||||
}, 30000);
|
||||
}
|
||||
}
|
||||
|
||||
// Próba utworzenia iframe przy DOMContentLoaded
|
||||
if (document.readyState === 'loading') {
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
console.log('[DPD SwipBox] DOMContentLoaded');
|
||||
dpsShippingSwipBoxObserveDOM();
|
||||
});
|
||||
} else {
|
||||
// DOM już załadowany
|
||||
console.log('[DPD SwipBox] DOM już załadowany');
|
||||
dpsShippingSwipBoxObserveDOM();
|
||||
}
|
||||
|
||||
// Dodatkowa próba przy otwieraniu modala - nasłuchuj na zdarzenia modala
|
||||
$(document).ready(function() {
|
||||
console.log('[DPD SwipBox] jQuery ready');
|
||||
|
||||
// Nasłuchuj na otwieranie modala
|
||||
$(document).on('click', '.dpdshipping-pudo-swipbox-open-map-btn, .dpdshipping-pudo-swipbox-change-map-btn', function() {
|
||||
console.log('[DPD SwipBox] Kliknięto przycisk otwierania mapy');
|
||||
// Sprawdź ponownie po kliknięciu
|
||||
setTimeout(function() {
|
||||
console.log('[DPD SwipBox] Sprawdzam element po kliknięciu...');
|
||||
console.log('[DPD SwipBox] Modal:', document.getElementById('dpdshippingPudoSwipBoxModal'));
|
||||
console.log('[DPD SwipBox] Script element:', document.getElementById('dpdshipping-widget-pudo-swipbox'));
|
||||
dpsShippingSwipBoxCreateIframe();
|
||||
}, 200);
|
||||
});
|
||||
|
||||
// Nasłuchuj na zdarzenie show modala (Bootstrap)
|
||||
$(document).on('show.bs.modal shown.bs.modal', '#dpdshippingPudoSwipBoxModal', function() {
|
||||
console.log('[DPD SwipBox] Modal pokazywany (Bootstrap event)');
|
||||
dpsShippingSwipBoxCreateIframe();
|
||||
});
|
||||
});
|
||||
|
||||
// Event listener dla wiadomości z iframe
|
||||
if (!dpsShippingSwipBoxEventCreated) {
|
||||
var dpsShippingSwipBox_eventListener = window[window.addEventListener ? "addEventListener" : "attachEvent"];
|
||||
var dpsShippingSwipBox_messageEvent = ("attachEvent" === dpsShippingSwipBox_eventListener) ? "onmessage" : "message";
|
||||
dpsShippingSwipBox_eventListener(dpsShippingSwipBox_messageEvent, function (a) {
|
||||
if (typeof getDpdshippingIdPudoSwipBoxCarrier !== 'function' || typeof getDpdshippingSelectedCarrier !== 'function') {
|
||||
return;
|
||||
}
|
||||
if (getDpdshippingIdPudoSwipBoxCarrier() === getDpdshippingSelectedCarrier()) {
|
||||
var iframe = window.dpsShippingSwipBox_iframe || document.getElementById("dpdshipping-widget-pudo-swipbox-iframe");
|
||||
if (a.data && a.data.height && !isNaN(a.data.height)) {
|
||||
if (iframe) {
|
||||
iframe.style.height = a.data.height + "px";
|
||||
}
|
||||
} else if (a.data && a.data.point_id) {
|
||||
dpdShippingSwipBoxPointSelected(a.data.point_id);
|
||||
}
|
||||
}
|
||||
}, !1);
|
||||
dpsShippingSwipBoxEventCreated = true;
|
||||
}
|
||||
|
||||
function dpdShippingSwipBoxPointSelected(pudoSwipBoxe) {
|
||||
if (!pudoSwipBoxe) {
|
||||
console.error('[DPD SwipBox] Błąd: Brak ID punktu');
|
||||
return;
|
||||
}
|
||||
|
||||
$('.container_dpdshipping_pudo_swipbox_error').css("display", "none");
|
||||
$('.dpdshipping-pudo-swipbox-new-point').css("display", "none");
|
||||
$('.dpdshipping-pudo-swipbox-selected-point').css("display", "block");
|
||||
|
||||
if (typeof dpdshippingSavePudoCode === 'function') {
|
||||
dpdshippingSavePudoCode(pudoSwipBoxe, $('#dpdshippingPudoSwipBoxModal'));
|
||||
} else {
|
||||
console.error('[DPD SwipBox] Funkcja dpdshippingSavePudoCode nie jest dostępna');
|
||||
}
|
||||
|
||||
if (typeof dpdshippingGetPudoAddress === 'function') {
|
||||
dpdshippingGetPudoAddress(pudoSwipBoxe, $('.dpdshipping-swipbox-selected-point'));
|
||||
} else {
|
||||
console.error('[DPD SwipBox] Funkcja dpdshippingGetPudoAddress nie jest dostępna');
|
||||
}
|
||||
|
||||
console.log('[DPD SwipBox] Wybrano punkt:', pudoSwipBoxe);
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright 2025 DPD Polska Sp. z o. o.
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* Licensed under the EUPL-1.2 or later.
|
||||
* You may not use this work except in compliance with the Licence.
|
||||
*
|
||||
* You may obtain a copy of the Licence at:
|
||||
* https://joinup.ec.europa.eu/software/page/eupl
|
||||
* It is also bundled with this package in the file LICENSE.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the Licence is distributed on an AS IS basis,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the Licence for the specific language governing permissions
|
||||
* and limitations under the Licence.
|
||||
*
|
||||
* @author DPD Polska Sp. z o.o.
|
||||
* @copyright 2025 DPD Polska Sp. z o.o.
|
||||
* @license https://joinup.ec.europa.eu/software/page/eupl
|
||||
*/
|
||||
|
||||
$(document).ready(function () {
|
||||
setTimeout(() => {
|
||||
handleDpdShippingPudo()
|
||||
}, 2000);
|
||||
})
|
||||
|
||||
function dpdshippingDisableOrderProcessBtn() {
|
||||
$("#confirm_order").css("pointer-events", "none");
|
||||
}
|
||||
|
||||
function dpdshippingEnableOrderProcessBtn() {
|
||||
$("#confirm_order").css("pointer-events", "auto");
|
||||
}
|
||||
|
||||
33
modules/dpdshipping/views/js/index.php
Normal file
33
modules/dpdshipping/views/js/index.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright 2024 DPD Polska Sp. z o.o.
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* Licensed under the EUPL-1.2 or later.
|
||||
* You may not use this work except in compliance with the Licence.
|
||||
*
|
||||
* You may obtain a copy of the Licence at:
|
||||
* https://joinup.ec.europa.eu/software/page/eupl
|
||||
* It is also bundled with this package in the file LICENSE.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the Licence is distributed on an AS IS basis,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the Licence for the specific language governing permissions
|
||||
* and limitations under the Licence.
|
||||
*
|
||||
* @author DPD Polska Sp. z o.o.
|
||||
* @copyright 2024 DPD Polska Sp. z o.o.
|
||||
* @license https://joinup.ec.europa.eu/software/page/eupl
|
||||
*/
|
||||
|
||||
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
|
||||
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
|
||||
|
||||
header('Cache-Control: no-store, no-cache, must-revalidate');
|
||||
header('Cache-Control: post-check=0, pre-check=0', false);
|
||||
header('Pragma: no-cache');
|
||||
|
||||
header('Location: ../');
|
||||
exit;
|
||||
609
modules/dpdshipping/views/js/order-details.js
Normal file
609
modules/dpdshipping/views/js/order-details.js
Normal file
@@ -0,0 +1,609 @@
|
||||
/*
|
||||
* Copyright 2024 DPD Polska Sp. z o.o.
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* Licensed under the EUPL-1.2 or later.
|
||||
* You may not use this work except in compliance with the Licence.
|
||||
*
|
||||
* You may obtain a copy of the Licence at:
|
||||
* https://joinup.ec.europa.eu/software/page/eupl
|
||||
* It is also bundled with this package in the file LICENSE.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the Licence is distributed on an AS IS basis,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the Licence for the specific language governing permissions
|
||||
* and limitations under the Licence.
|
||||
*
|
||||
* @author DPD Polska Sp. z o.o.
|
||||
* @copyright 2024 DPD Polska Sp. z o.o.
|
||||
* @license https://joinup.ec.europa.eu/software/page/eupl
|
||||
*/
|
||||
|
||||
$(document).ready(function () {
|
||||
|
||||
handleDpdShippingFormCardBody();
|
||||
|
||||
changeTable($('#packageGroupType').val());
|
||||
|
||||
$(document).on('change', '#dpd_shipping_generate_shipping_service_guarantee', function () {
|
||||
changeVisibility(getCheckboxId(this), '.service_guarantee_type', '#dpd_shipping_generate_shipping_service_guarantee_type');
|
||||
changeVisibility(getCheckboxId(this), '.service_guarantee_value', '#dpd_shipping_generate_shipping_service_guarantee_value');
|
||||
});
|
||||
|
||||
changeVisibility('#dpd_shipping_generate_shipping_service_guarantee', '.service_guarantee_type', '#dpd_shipping_generate_shipping_service_guarantee_type');
|
||||
changeVisibility('#dpd_shipping_generate_shipping_service_guarantee', '.service_guarantee_value', '#dpd_shipping_generate_shipping_service_guarantee_value');
|
||||
|
||||
$(document).on('change', '#dpd_shipping_generate_shipping_service_cod', function () {
|
||||
changeVisibility(getCheckboxId(this), '.service_cod_value', '#dpd_shipping_generate_shipping_service_cod_value');
|
||||
changeVisibility(getCheckboxId(this), '.service_cod_currency', '#dpd_shipping_generate_shipping_service_cod_currency');
|
||||
});
|
||||
|
||||
changeVisibility('#dpd_shipping_generate_shipping_service_cod', '.service_cod_value', '#dpd_shipping_generate_shipping_service_cod_value');
|
||||
changeVisibility('#dpd_shipping_generate_shipping_service_cod', '.service_cod_currency', '#dpd_shipping_generate_shipping_service_cod_currency');
|
||||
|
||||
$(document).on('change', '#dpd_shipping_generate_shipping_service_self_con', function () {
|
||||
changeVisibility(getCheckboxId(this), '.service_self_con_value', '#dpd_shipping_generate_shipping_service_self_con_value');
|
||||
});
|
||||
|
||||
changeVisibility('#dpd_shipping_generate_shipping_service_self_con', '.service_self_con_value', '#dpd_shipping_generate_shipping_service_self_con_value');
|
||||
|
||||
$(document).on('change', '#dpd_shipping_generate_shipping_service_dpd_pickup', function () {
|
||||
changeVisibility(getCheckboxId(this), '.service_dpd_pickup_value', '#dpd_shipping_generate_shipping_service_dpd_pickup_value');
|
||||
changeVisibility(getCheckboxId(this), '.service_dpd_pickup_map', '#dpd_shipping_generate_shipping_service_dpd_pickup_map');
|
||||
|
||||
checkEmpikDpdPickup();
|
||||
});
|
||||
|
||||
changeVisibility('#dpd_shipping_generate_shipping_service_dpd_pickup', '.service_dpd_pickup_value', '#dpd_shipping_generate_shipping_service_dpd_pickup_value');
|
||||
changeVisibility('#dpd_shipping_generate_shipping_service_dpd_pickup', '.service_dpd_pickup_map', '#dpd_shipping_generate_shipping_service_dpd_pickup_map');
|
||||
|
||||
$(document).on('change', '#dpd_shipping_generate_shipping_service_declared_value', function () {
|
||||
changeVisibility(getCheckboxId(this), '.service_declared_value_value', '#dpd_shipping_generate_shipping_service_declared_value_value');
|
||||
changeVisibility(getCheckboxId(this), '.service_declared_value_currency', '#dpd_shipping_generate_shipping_service_declared_value_currency');
|
||||
});
|
||||
|
||||
changeVisibility('#dpd_shipping_generate_shipping_service_declared_value', '.service_declared_value_value', '#dpd_shipping_generate_shipping_service_declared_value_value');
|
||||
changeVisibility('#dpd_shipping_generate_shipping_service_declared_value', '.service_declared_value_currency', '#dpd_shipping_generate_shipping_service_declared_value_currency');
|
||||
|
||||
$(document).on('change', '#dpd_shipping_generate_shipping_service_dpd_food', function () {
|
||||
changeVisibility(getCheckboxId(this), '.service_dpd_food_value', '#dpd_shipping_generate_shipping_service_dpd_food_value');
|
||||
});
|
||||
|
||||
changeVisibility('#dpd_shipping_generate_shipping_service_dpd_food', '.service_dpd_food_value', '#dpd_shipping_generate_shipping_service_dpd_food_value');
|
||||
|
||||
$(document).on('change', '#dpd_shipping_generate_shipping_service_duty', function () {
|
||||
changeVisibility(getCheckboxId(this), '.service_duty_value', '#dpd_shipping_generate_shipping_service_duty_value');
|
||||
changeVisibility(getCheckboxId(this), '.service_duty_currency', '#dpd_shipping_generate_shipping_service_duty_currency');
|
||||
});
|
||||
|
||||
changeVisibility('#dpd_shipping_generate_shipping_service_duty', '.service_duty_value', '#dpd_shipping_generate_shipping_service_duty_value');
|
||||
changeVisibility('#dpd_shipping_generate_shipping_service_duty', '.service_duty_currency', '#dpd_shipping_generate_shipping_service_duty_currency');
|
||||
|
||||
$(document).on('change', '#dpd_shipping_generate_shipping_service_return_label', function () {
|
||||
changeVisibility(getCheckboxId(this), '.service_return_label_address_company', '#dpd_shipping_generate_shipping_service_return_label_address_company');
|
||||
changeVisibility(getCheckboxId(this), '.service_return_label_address_name', '#dpd_shipping_generate_shipping_service_return_label_address_name');
|
||||
changeVisibility(getCheckboxId(this), '.service_return_label_address_street', '#dpd_shipping_generate_shipping_service_return_label_address_street');
|
||||
changeVisibility(getCheckboxId(this), '.service_return_label_address_city', '#dpd_shipping_generate_shipping_service_return_label_address_city');
|
||||
changeVisibility(getCheckboxId(this), '.service_return_label_address_postcode', '#dpd_shipping_generate_shipping_service_return_label_address_postcode');
|
||||
changeVisibility(getCheckboxId(this), '.service_return_label_address_country', '#dpd_shipping_generate_shipping_service_return_label_address_country');
|
||||
changeVisibility(getCheckboxId(this), '.service_return_label_address_phone', '#dpd_shipping_generate_shipping_service_return_label_address_phone');
|
||||
changeVisibility(getCheckboxId(this), '.service_return_label_address_email', '#dpd_shipping_generate_shipping_service_return_label_address_email');
|
||||
});
|
||||
|
||||
changeVisibility('#dpd_shipping_generate_shipping_service_return_label', '.service_return_label_address_company', '#dpd_shipping_generate_shipping_service_return_label_address_company');
|
||||
changeVisibility('#dpd_shipping_generate_shipping_service_return_label', '.service_return_label_address_name', '#dpd_shipping_generate_shipping_service_return_label_address_name');
|
||||
changeVisibility('#dpd_shipping_generate_shipping_service_return_label', '.service_return_label_address_street', '#dpd_shipping_generate_shipping_service_return_label_address_street');
|
||||
changeVisibility('#dpd_shipping_generate_shipping_service_return_label', '.service_return_label_address_city', '#dpd_shipping_generate_shipping_service_return_label_address_city');
|
||||
changeVisibility('#dpd_shipping_generate_shipping_service_return_label', '.service_return_label_address_postcode', '#dpd_shipping_generate_shipping_service_return_label_address_postcode');
|
||||
changeVisibility('#dpd_shipping_generate_shipping_service_return_label', '.service_return_label_address_country', '#dpd_shipping_generate_shipping_service_return_label_address_country');
|
||||
changeVisibility('#dpd_shipping_generate_shipping_service_return_label', '.service_return_label_address_phone', '#dpd_shipping_generate_shipping_service_return_label_address_phone');
|
||||
changeVisibility('#dpd_shipping_generate_shipping_service_return_label', '.service_return_label_address_email', '#dpd_shipping_generate_shipping_service_return_label_address_email');
|
||||
|
||||
$(document).on('click', '.dpdshipping-remove-row', function () {
|
||||
removeRow(this)
|
||||
});
|
||||
|
||||
$(document).on('click', '#dpdShippingAddRow', function () {
|
||||
changeTable('addRow');
|
||||
});
|
||||
|
||||
$(document).on('click', '#dpdShippingSingleShipping', function () {
|
||||
changeTable('single');
|
||||
});
|
||||
|
||||
$(document).on('click', '#dpdShippingGroupShipping', function () {
|
||||
changeTable('group');
|
||||
});
|
||||
|
||||
$(document).on('click', '#dpdShippingPackageShipping', function () {
|
||||
changeTable('package');
|
||||
});
|
||||
|
||||
$(document).on('click', '#dpdShippingCalcShippingRows', function () {
|
||||
setDpdShippingCustomShippingRows();
|
||||
setDpdShippingCustomParcel();
|
||||
$('#dpdShippingParcelSummaryRow').removeClass('hidden');
|
||||
});
|
||||
|
||||
$(document).on('change', '.dpdShippingCustomParcelSelect', function () {
|
||||
setDpdShippingCustomParcel();
|
||||
});
|
||||
|
||||
$(document).on('click', '#dpdShippingCustomParcelSave', function () {
|
||||
changeTable('custom', getDpdShippingCustomParcel())
|
||||
});
|
||||
|
||||
$(document).on('click', '#dpdShippingCustomShipping', function () {
|
||||
$('#dpdShippingCalcShippingRows').click();
|
||||
});
|
||||
|
||||
$(document).on('change', '#dpdShippingSenderAddresses', function () {
|
||||
const address = $(this).find('option:selected').data('address');
|
||||
$('#dpd_shipping_generate_shipping_sender_address_company').val(address.company);
|
||||
$('#dpd_shipping_generate_shipping_sender_address_name').val(address.name);
|
||||
$('#dpd_shipping_generate_shipping_sender_address_street').val(address.street);
|
||||
$('#dpd_shipping_generate_shipping_sender_address_postcode').val(address.postcode);
|
||||
$('#dpd_shipping_generate_shipping_sender_address_country').val(address.country);
|
||||
$('#dpd_shipping_generate_shipping_sender_address_city').val(address.city);
|
||||
$('#dpd_shipping_generate_shipping_sender_address_phone').val(address.phone);
|
||||
$('#dpd_shipping_generate_shipping_sender_address_email').val(address.email);
|
||||
});
|
||||
|
||||
$(document).on('change', '#dpdShippingReceiverAddresses', function () {
|
||||
const address = $(this).find('option:selected').data('address');
|
||||
$('#dpd_shipping_generate_shipping_receiver_address_company').val(address.company);
|
||||
$('#dpd_shipping_generate_shipping_receiver_address_name').val(address.name);
|
||||
$('#dpd_shipping_generate_shipping_receiver_address_street').val(address.street);
|
||||
$('#dpd_shipping_generate_shipping_receiver_address_postcode').val(address.postcode);
|
||||
$('#dpd_shipping_generate_shipping_receiver_address_country').val(address.country);
|
||||
$('#dpd_shipping_generate_shipping_receiver_address_city').val(address.city);
|
||||
$('#dpd_shipping_generate_shipping_receiver_address_phone').val(address.phone);
|
||||
$('#dpd_shipping_generate_shipping_receiver_address_email').val(address.email);
|
||||
});
|
||||
|
||||
$(document).on('click', '.dpdshipping-tracking-detail-btn', function () {
|
||||
$(this).next(".dpdshipping-tracking-detail").toggleClass("hidden");
|
||||
});
|
||||
|
||||
showWeightAdr();
|
||||
|
||||
$(document).on('change', '#dpd_shipping_generate_shipping_service_adr', function () {
|
||||
showWeightAdr();
|
||||
});
|
||||
|
||||
function showWeightAdr() {
|
||||
if ($('#dpd_shipping_generate_shipping_service_adr').prop('checked')) {
|
||||
$(".dpdShippingWeightAdr").removeClass("hidden");
|
||||
} else {
|
||||
$(".dpdShippingWeightAdr").addClass("hidden");
|
||||
}
|
||||
}
|
||||
|
||||
function getCheckboxId(input) {
|
||||
return '#' + input.id;
|
||||
}
|
||||
|
||||
function changeVisibility(checkBoxId, relatedClass, input) {
|
||||
if ($(checkBoxId).is(':checked')) {
|
||||
$(relatedClass).removeClass('hidden');
|
||||
$(input).prop('disabled', false);
|
||||
if (input !== "#dpd_shipping_generate_shipping_service_guarantee_value")
|
||||
$(input).prop('required', true);
|
||||
|
||||
} else {
|
||||
$(relatedClass).addClass('hidden');
|
||||
$(input).prop('disabled', 'disabled');
|
||||
if (input !== "#dpd_shipping_generate_shipping_service_guarantee_value")
|
||||
$(input).prop('required', false);
|
||||
}
|
||||
}
|
||||
|
||||
function removeRow(button) {
|
||||
const rowCount = $('#packagesTable tr').length;
|
||||
if (rowCount > 2)
|
||||
$(button).closest('tr').remove();
|
||||
}
|
||||
|
||||
function changeTable(type, customData) {
|
||||
const lastContainer = $("#packagesTable tbody tr:last");
|
||||
const packagesTable = document.getElementById('packagesTable');
|
||||
if (!packagesTable) {
|
||||
console.error('Table with ID "packagesTable" not found.');
|
||||
return;
|
||||
}
|
||||
|
||||
const tbodyByTagName = packagesTable.getElementsByTagName('tbody')
|
||||
if (tbodyByTagName == null || tbodyByTagName.length === 0) {
|
||||
console.error('No <tbody> elements found in the table.');
|
||||
return;
|
||||
}
|
||||
|
||||
const tbody = tbodyByTagName[0];
|
||||
while (type !== "addRow" && tbody.firstChild) {
|
||||
tbody.removeChild(tbody.firstChild);
|
||||
}
|
||||
|
||||
// Create new rows based on the selected action
|
||||
if (type === 'single') {
|
||||
const clonedRow = lastContainer.clone();
|
||||
let data = getSingleRow()
|
||||
setInputsData(clonedRow, data);
|
||||
setIndexForNewRow(clonedRow);
|
||||
$("#packagesTable").append(clonedRow);
|
||||
} else if (type === 'group') {
|
||||
const productsData = $('#dpdShippingOrderProducts').data('products');
|
||||
Object.keys(productsData).forEach(function (index) {
|
||||
const product = productsData[index];
|
||||
const clonedRow = lastContainer.clone();
|
||||
let data = {
|
||||
weight: getProductWeight([product], true),
|
||||
weightAdr: null,
|
||||
customerData: getData([product], 300, 'customer-source'),
|
||||
content: getData([product], 300, 'content-source'),
|
||||
sizeX: '',
|
||||
sizeY: '',
|
||||
sizeZ: ''
|
||||
}
|
||||
setInputsData(clonedRow, data);
|
||||
setIndexForNewRow(clonedRow);
|
||||
$("#packagesTable").append(clonedRow);
|
||||
});
|
||||
} else if (type === 'package') {
|
||||
const productsData = $('#dpdShippingOrderProducts').data('products');
|
||||
Object.keys(productsData).forEach(function (index) {
|
||||
const product = productsData[index];
|
||||
for (let i = 0; i < Math.ceil(product.product_quantity); i++) {
|
||||
const clonedRow = lastContainer.clone();
|
||||
let data = {
|
||||
weight: getProductWeight([product], false),
|
||||
weightAdr: null,
|
||||
customerData: getData([product], 300, 'customer-source'),
|
||||
content: getData([product], 300, 'content-source'),
|
||||
sizeX: '',
|
||||
sizeY: '',
|
||||
sizeZ: ''
|
||||
}
|
||||
setInputsData(clonedRow, data);
|
||||
setIndexForNewRow(clonedRow);
|
||||
$("#packagesTable").append(clonedRow);
|
||||
}
|
||||
});
|
||||
} else if (type === 'addRow') {
|
||||
const clonedRow = lastContainer.clone();
|
||||
let data = {
|
||||
weight: 1.0,
|
||||
weightAdr: null,
|
||||
customerData: "",
|
||||
content: "",
|
||||
sizeX: "",
|
||||
sizeY: "",
|
||||
sizeZ: "",
|
||||
}
|
||||
setInputsData(clonedRow, data);
|
||||
setIndexForNewRow(clonedRow);
|
||||
$("#packagesTable").append(clonedRow);
|
||||
} else if (type === 'custom') {
|
||||
Object.keys(customData).forEach(function (index) {
|
||||
const parcel = customData[index];
|
||||
const clonedRow = lastContainer.clone();
|
||||
let data = {
|
||||
weight: parcel.product_weight,
|
||||
weightAdr: null,
|
||||
customerData: parcel.customerData,
|
||||
content: parcel.content,
|
||||
sizeX: '',
|
||||
sizeY: '',
|
||||
sizeZ: ''
|
||||
}
|
||||
setInputsData(clonedRow, data);
|
||||
setIndexForNewRow(clonedRow);
|
||||
$("#packagesTable").append(clonedRow);
|
||||
});
|
||||
}
|
||||
|
||||
function setInputsData(clonedRow, data) {
|
||||
|
||||
clonedRow.find('input').each(function () {
|
||||
const inputType = $(this).attr('fieldType');
|
||||
switch (inputType) {
|
||||
case 'weight':
|
||||
$(this).val(data.weight);
|
||||
break;
|
||||
case 'weightAdr':
|
||||
$(this).val(data.weightAdr);
|
||||
break;
|
||||
case 'customerData':
|
||||
$(this).val(data.customerData);
|
||||
break;
|
||||
case 'content':
|
||||
$(this).val(data.content);
|
||||
break;
|
||||
case 'sizeX':
|
||||
$(this).val(data.sizeX);
|
||||
break;
|
||||
case 'sizeY':
|
||||
$(this).val(data.sizeY);
|
||||
break;
|
||||
case 'sizeZ':
|
||||
$(this).val(data.sizeZ);
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function setIndexForNewRow(clonedRow) {
|
||||
function setIndexes() {
|
||||
const index = parseInt($("#packagesTable tbody tr").length);
|
||||
const currentName = $(this).attr('name');
|
||||
const newName = currentName.replace(/\[(\d+)\]/, '[' + index + ']');
|
||||
$(this).attr('name', newName);
|
||||
|
||||
const currentId = $(this).attr('id');
|
||||
const newId = currentId.replace(/\_(\d+)\_/, '_' + index + '_');
|
||||
$(this).attr('id', newId);
|
||||
}
|
||||
|
||||
clonedRow.find('input').each(function () {
|
||||
setIndexes.call(this);
|
||||
});
|
||||
|
||||
clonedRow.find('select').each(function () {
|
||||
setIndexes.call(this);
|
||||
});
|
||||
}
|
||||
|
||||
function getSingleRow() {
|
||||
const productsData = $('#dpdShippingOrderProducts').data('products');
|
||||
|
||||
return {
|
||||
weight: getProductWeight(productsData, true),
|
||||
weightAdr: null,
|
||||
customerData: getData(productsData, 300, 'customer-source'),
|
||||
content: getData(productsData, 300, 'content-source'),
|
||||
sizeX: '',
|
||||
sizeY: '',
|
||||
sizeZ: ''
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function setDpdShippingCustomShippingRows() {
|
||||
const parcels = Number($('#dpdShippingCustomShippingParcels').val());
|
||||
const newOptions = generateParcelsArray(parcels);
|
||||
|
||||
const elements = $('.dpdShippingCustomParcelSelect');
|
||||
|
||||
elements.each(function () {
|
||||
const select = $(this)
|
||||
select.empty();
|
||||
$.each(newOptions, function (index, value) {
|
||||
select.append($('<option>', {
|
||||
value: value,
|
||||
text: value
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
||||
function generateParcelsArray(size) {
|
||||
const array = [];
|
||||
for (let i = 1; i <= size; i++) {
|
||||
array.push(i);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
}
|
||||
|
||||
function setDpdShippingCustomParcel() {
|
||||
const summaryTable = $('.dpdShippingCustomParcelSummaryTable');
|
||||
const parcels = getDpdShippingCustomParcel();
|
||||
|
||||
let rows = "";
|
||||
Object.keys(parcels).forEach(function (parcel) {
|
||||
const parcelData = parcels[parcel];
|
||||
rows += '<tr>';
|
||||
rows += '<td>' + parcelData.parcel + '</td>';
|
||||
rows += '<td>' + parcelData.content + '</td>';
|
||||
rows += '<td>' + parcelData.customerData + '</td>';
|
||||
rows += '<td>' + parcelData.product_weight + '</td>';
|
||||
rows += '</tr>';
|
||||
});
|
||||
|
||||
summaryTable.empty();
|
||||
summaryTable.append(rows);
|
||||
}
|
||||
|
||||
function getDpdShippingCustomParcel() {
|
||||
|
||||
const parcels = {};
|
||||
getProducts().forEach(function (product) {
|
||||
if (!parcels[product.parcel]) {
|
||||
parcels[product.parcel] = [];
|
||||
}
|
||||
parcels[product.parcel].push(product);
|
||||
});
|
||||
|
||||
const result = []
|
||||
Object.keys(parcels).forEach(function (parcel) {
|
||||
const parcelData = parcels[parcel];
|
||||
|
||||
result.push({
|
||||
parcel: parcel,
|
||||
customerData: getData(parcelData, 300, 'customer-source'),
|
||||
content: getData(parcelData, 300, 'content-source'),
|
||||
product_weight: getProductWeight(parcelData, false),
|
||||
})
|
||||
});
|
||||
|
||||
return result;
|
||||
|
||||
function getProducts() {
|
||||
const products = [];
|
||||
|
||||
const parcels = getSelectValues('dpdShippingCustomShippingParcel');
|
||||
const productNames = getInputValues('dpdShippingCustomShippingProductName');
|
||||
const productIds = getInputValues('dpdShippingCustomShippingProductId');
|
||||
const productWeights = getInputValues('dpdShippingCustomShippingProductWeight');
|
||||
const productReferences = getInputValues('dpdShippingCustomShippingProductReference');
|
||||
|
||||
for (let i = 0; i < productIds.length; i++) {
|
||||
const product = {
|
||||
product_reference: productReferences[i],
|
||||
product_weight: productWeights[i],
|
||||
product_name: productNames[i],
|
||||
product_id: productIds[i],
|
||||
parcel: parcels[i],
|
||||
customerData: '',
|
||||
content: '',
|
||||
};
|
||||
products.push(product);
|
||||
}
|
||||
|
||||
return products;
|
||||
}
|
||||
|
||||
function getSelectValues(selectName) {
|
||||
return $('select[name^="' + selectName + '["]').map(function () {
|
||||
return $(this).val();
|
||||
}).get();
|
||||
}
|
||||
|
||||
function getInputValues(selectName) {
|
||||
return $('input[name^="' + selectName + '["]').map(function () {
|
||||
return $(this).val();
|
||||
}).get();
|
||||
}
|
||||
}
|
||||
|
||||
function getProductWeight(parcel, multiplyQuantity) {
|
||||
let sum = 0;
|
||||
parcel.forEach(function (product) {
|
||||
let weight = Number(product.product_weight);
|
||||
if (weight <= 0)
|
||||
weight = $('#dpdShippingDefaultWeight').data('default-weight');
|
||||
|
||||
if (multiplyQuantity)
|
||||
sum += weight * Number(product.product_quantity);
|
||||
else
|
||||
sum += weight;
|
||||
});
|
||||
|
||||
return sum.toFixed(2);
|
||||
}
|
||||
|
||||
|
||||
function getData(parcel, limit, sourceString) {
|
||||
const source = $('#dpdShippingSource').data(sourceString);
|
||||
const sourceStatic = $('#dpdShippingSource').data(sourceString + '-static');
|
||||
|
||||
const unique = [];
|
||||
parcel.forEach(function (product) {
|
||||
const dynamicField = getDynamicField(source, sourceStatic, product)
|
||||
if (!unique.includes(dynamicField)) {
|
||||
unique.push(dynamicField);
|
||||
}
|
||||
});
|
||||
|
||||
return getStringWithMaxLength(unique.join(', '), limit);
|
||||
}
|
||||
|
||||
function getDynamicField(source, sourceStatic, product) {
|
||||
if (source === "STATIC_VALUE")
|
||||
return sourceStatic;
|
||||
else if (source === "STATIC_VALUE_ONLY_FOR_EMPIK" && $('#dpdShippingOrderNumberEmpik').data('order-number-empik'))
|
||||
return sourceStatic;
|
||||
else if (source === "ORDER_NUMBER")
|
||||
return $('#dpdShippingOrderNumber').data('order-number');
|
||||
else if (source === "ORDER_ID")
|
||||
return $('#dpdShippingOrderId').data('order-id');
|
||||
else if (source === "INVOICE_NUMBER")
|
||||
return $('#dpdShippingInvoiceNumber').data('invoice-number');
|
||||
else if (source === "PRODUCT_INDEX")
|
||||
return product.product_reference;
|
||||
else if (source === "PRODUCT_NAME")
|
||||
return product.product_name;
|
||||
else if (source === "ORDER_NUMBER_EMPIK")
|
||||
return $('#dpdShippingOrderNumberEmpik').data('order-number-empik');
|
||||
return '';
|
||||
}
|
||||
|
||||
function getStringWithMaxLength(data, limit) {
|
||||
if (data.length > limit) {
|
||||
return data.substring(0, limit - 3) + '...';
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
$(document).on('click', '.dpdshipping-pudo-change-map-btn', (e) => {
|
||||
const dpdShippingWidgetPudoIframe = $("#dpdshiping-widget-pudo-iframe")
|
||||
const dpdReceiverCountryCode = document.getElementById("dpd_shipping_generate_shipping_receiver_address_country")?.value ?? "PL";
|
||||
const dpdPudoFinderUrl = $("#dpdPudoFinderUrl").data("dpd-pudo-finder-url")
|
||||
dpdShippingWidgetPudoIframe.attr("src", dpdPudoFinderUrl + "&query=" + dpdReceiverCountryCode?.toUpperCase());
|
||||
|
||||
showModal(e, '#dpdshippingPudoModal');
|
||||
});
|
||||
|
||||
function showModal(event, modalDiv) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
$(modalDiv).modal({
|
||||
backdrop: 'static',
|
||||
keyboard: false
|
||||
})
|
||||
}
|
||||
|
||||
function handleDpdShippingFormCardBody() {
|
||||
const dpdCarrierValue = $("#dpdShippingIsDpdCarrier").data("dpd-carrier");
|
||||
const isDpdCarrier = dpdCarrierValue === 1 || dpdCarrierValue === "1";
|
||||
|
||||
if (!isDpdCarrier) {
|
||||
$('form[name="dpd_shipping_generate_shipping"] .card-body').toggle();
|
||||
$('form[name="dpd_shipping_generate_shipping"] .card-footer').toggle();
|
||||
$('.dpdApiPayer').toggle();
|
||||
|
||||
const toggleButton = $("#dpdToggleButton");
|
||||
const icon = toggleButton.find("span.material-icons");
|
||||
icon.text("expand_more");
|
||||
}
|
||||
|
||||
$('#dpdToggleButton').click(function (e) {
|
||||
e.preventDefault();
|
||||
const dpdCardBody = $('form[name="dpd_shipping_generate_shipping"] .card-body')
|
||||
dpdCardBody.toggle();
|
||||
$('form[name="dpd_shipping_generate_shipping"] .card-footer').toggle();
|
||||
$('.dpdApiPayer').toggle();
|
||||
|
||||
const icon = $(this).find("span.material-icons");
|
||||
if (dpdCardBody.is(":visible")) {
|
||||
icon.text("expand_less");
|
||||
} else {
|
||||
icon.text("expand_more");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function checkEmpikDpdPickup() {
|
||||
const dpdShippingSource = $('#dpdShippingSource').data('order-source');
|
||||
const dpdPickupCheckbox = $('#dpd_shipping_generate_shipping_service_dpd_pickup');
|
||||
const dpdEmpikAlert = $('.dpdShippingEmpikDpdPickupAlert');
|
||||
|
||||
const toggleEmpikAlert = () => {
|
||||
const isEmpik = dpdShippingSource === 'DELIVERY_EMPIK_STORE';
|
||||
const isChecked = dpdPickupCheckbox.is(':checked');
|
||||
|
||||
if (isEmpik && !isChecked) {
|
||||
dpdEmpikAlert.show();
|
||||
} else {
|
||||
dpdEmpikAlert.hide();
|
||||
}
|
||||
};
|
||||
|
||||
toggleEmpikAlert();
|
||||
dpdPickupCheckbox.on('change', toggleEmpikAlert);
|
||||
}
|
||||
|
||||
checkEmpikDpdPickup();
|
||||
}
|
||||
);
|
||||
42
modules/dpdshipping/views/js/pickup-courier-grid.js
Normal file
42
modules/dpdshipping/views/js/pickup-courier-grid.js
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright 2024 DPD Polska Sp. z o.o.
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* Licensed under the EUPL-1.2 or later.
|
||||
* You may not use this work except in compliance with the Licence.
|
||||
*
|
||||
* You may obtain a copy of the Licence at:
|
||||
* https://joinup.ec.europa.eu/software/page/eupl
|
||||
* It is also bundled with this package in the file LICENSE.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the Licence is distributed on an AS IS basis,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the Licence for the specific language governing permissions
|
||||
* and limitations under the Licence.
|
||||
*
|
||||
* @author DPD Polska Sp. z o.o.
|
||||
* @copyright 2024 DPD Polska Sp. z o.o.
|
||||
* @license https://joinup.ec.europa.eu/software/page/eupl
|
||||
*/
|
||||
|
||||
$(document).ready(function () {
|
||||
window.prestashop.component.initComponents(
|
||||
[
|
||||
'Grid'
|
||||
],
|
||||
);
|
||||
const grid = new window.prestashop.component.Grid('dpdshipping_pickup_courier');
|
||||
grid.addExtension(new window.prestashop.component.GridExtensions.BulkActionCheckboxExtension());
|
||||
// grid.addExtension(new window.prestashop.component.GridExtensions.ExportToSqlManagerExtension());
|
||||
grid.addExtension(new window.prestashop.component.GridExtensions.ReloadListExtension());
|
||||
grid.addExtension(new window.prestashop.component.GridExtensions.SortingExtension());
|
||||
grid.addExtension(new window.prestashop.component.GridExtensions.FiltersResetExtension());
|
||||
grid.addExtension(new window.prestashop.component.GridExtensions.SubmitRowActionExtension());
|
||||
grid.addExtension(new window.prestashop.component.GridExtensions.SubmitBulkActionExtension());
|
||||
grid.addExtension(new window.prestashop.component.GridExtensions.AjaxBulkActionExtension());
|
||||
grid.addExtension(new window.prestashop.component.GridExtensions.FiltersSubmitButtonEnablerExtension());
|
||||
grid.addExtension(new window.prestashop.component.GridExtensions.AsyncToggleColumnExtension());
|
||||
grid.addExtension(new window.prestashop.component.GridExtensions.PositionExtension(grid));
|
||||
});
|
||||
42
modules/dpdshipping/views/js/shipping-history-grid.js
Normal file
42
modules/dpdshipping/views/js/shipping-history-grid.js
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright 2024 DPD Polska Sp. z o.o.
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* Licensed under the EUPL-1.2 or later.
|
||||
* You may not use this work except in compliance with the Licence.
|
||||
*
|
||||
* You may obtain a copy of the Licence at:
|
||||
* https://joinup.ec.europa.eu/software/page/eupl
|
||||
* It is also bundled with this package in the file LICENSE.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the Licence is distributed on an AS IS basis,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the Licence for the specific language governing permissions
|
||||
* and limitations under the Licence.
|
||||
*
|
||||
* @author DPD Polska Sp. z o.o.
|
||||
* @copyright 2024 DPD Polska Sp. z o.o.
|
||||
* @license https://joinup.ec.europa.eu/software/page/eupl
|
||||
*/
|
||||
|
||||
$(document).ready(function () {
|
||||
window.prestashop.component.initComponents(
|
||||
[
|
||||
'Grid'
|
||||
],
|
||||
);
|
||||
const grid = new window.prestashop.component.Grid('dpdshipping_shipping_history');
|
||||
grid.addExtension(new window.prestashop.component.GridExtensions.BulkActionCheckboxExtension());
|
||||
// grid.addExtension(new window.prestashop.component.GridExtensions.ExportToSqlManagerExtension());
|
||||
grid.addExtension(new window.prestashop.component.GridExtensions.ReloadListExtension());
|
||||
grid.addExtension(new window.prestashop.component.GridExtensions.SortingExtension());
|
||||
grid.addExtension(new window.prestashop.component.GridExtensions.FiltersResetExtension());
|
||||
grid.addExtension(new window.prestashop.component.GridExtensions.SubmitRowActionExtension());
|
||||
grid.addExtension(new window.prestashop.component.GridExtensions.SubmitBulkActionExtension());
|
||||
grid.addExtension(new window.prestashop.component.GridExtensions.AjaxBulkActionExtension());
|
||||
grid.addExtension(new window.prestashop.component.GridExtensions.FiltersSubmitButtonEnablerExtension());
|
||||
grid.addExtension(new window.prestashop.component.GridExtensions.AsyncToggleColumnExtension());
|
||||
grid.addExtension(new window.prestashop.component.GridExtensions.PositionExtension(grid));
|
||||
});
|
||||
Reference in New Issue
Block a user