Update Apaczka shipment methods and add support for ApaczkaP2P

This commit is contained in:
2024-10-23 18:06:52 +02:00
parent a9b111bb86
commit b6d6146e1f
3 changed files with 38 additions and 40 deletions

View File

@@ -1,6 +1,6 @@
// ==UserScript== // ==UserScript==
// @name A // @name A
// @version 2.0 // @version 2.2
// @grant none // @grant none
// ==/UserScript== // ==/UserScript==
@@ -94,10 +94,11 @@
const buttons = [ const buttons = [
createButton('Apaczka D2D Inpost', '#7039df', 'ApaczkaD2D'), createButton('Apaczka D2D Inpost', '#7039df', 'ApaczkaD2D'),
createButton('Furgonetka P2D Inpost', '#007bff', 'P2D.inpost', 'RZE14N||RZE14N'), createButton('Apaczka P2P Inpost', '#7039df', 'ApaczkaP2P'),
createButton('Furgonetka D2P Inpost', '#28a745', 'D2P.inpost'), createButton('Furgonetka P2D Inpost', '#ff7800', 'P2D.inpost', 'RZE14N||RZE14N'),
createButton('Furgonetka D2P Inpost', '#ff7800', 'D2P.inpost'),
createButton('Furgonetka D2D Inpost', '#ff7800', 'D2D.inpostkurier'), createButton('Furgonetka D2D Inpost', '#ff7800', 'D2D.inpostkurier'),
createButton('Furgonetka P2P Inpost', '#ffc107', 'P2P.inpost', 'RZE14N||RZE14N') createButton('Furgonetka P2P Inpost', '#ff7800', 'P2P.inpost', 'RZE14N||RZE14N')
]; ];
buttons.forEach(button => buttonContainer.appendChild(button)); buttons.forEach(button => buttonContainer.appendChild(button));
@@ -414,8 +415,12 @@
if (method.startsWith('Apaczka')) { if (method.startsWith('Apaczka')) {
console.log('Ustawianie wysyłki Apaczka...'); console.log('Ustawianie wysyłki Apaczka...');
await setCarrierAccount(); await setCarrierAccount();
await setPackageTypeApaczka(); await setShipmentMethodApaczka(method);
await setShipmentMethodApaczka();
if (method === 'ApaczkaP2P') {
await setDropoffPoint('RZE14N||RZE14N');
}
await setPreferencesContentApaczka(); await setPreferencesContentApaczka();
await setParcelWeight('1'); await setParcelWeight('1');
await submitShipment(); await submitShipment();
@@ -457,40 +462,33 @@
} }
/** /**
* Funkcja ustawiająca typ paczki na "PACZKA" dla Apaczki. * Funkcja ustawiająca metodę wysyłki na podstawie typu Apaczki.
* @returns {Promise<void>} * Upewnia się, że select nie jest pusty przed ustawieniem wartości.
*/ * @param {string} method - Typ Apaczki ('ApaczkaD2D' lub 'ApaczkaP2P').
function setPackageTypeApaczka() { * @returns {Promise<void>}
return waitForElement('#warehousebundle_shipment_packageType').then(packageTypeElement => { */
packageTypeElement.value = 'PACZKA'; function setShipmentMethodApaczka(method) {
const event = new Event('change', { bubbles: true }); return retryUntilSuccess(() => {
packageTypeElement.dispatchEvent(event); return new Promise((resolve, reject) => {
console.log('Typ paczki ustawiony na PACZKA.'); const methodElement = document.getElementById('warehousebundle_shipment_method'); console.log( methodElement );
}).catch(error => { if (methodElement) {
console.error('Nie udało się ustawić typu paczki:', error); if (methodElement.options.length > 0) {
throw error; methodElement.value = (method === 'ApaczkaP2P') ? '41' : '42';
}); const event = new Event('change', { bubbles: true });
} methodElement.dispatchEvent(event);
console.log(`Metoda wysyłki ustawiona na ${(method === 'ApaczkaP2P') ? '49 (ApaczkaP2P)' : '42 (ApaczkaD2D)'}.`);
/** resolve();
* Funkcja ustawiająca metodę wysyłki na "42" dla Apaczki. } else {
* @returns {Promise<void>} reject('Select #warehousebundle_shipment_method jest pusty.');
*/ }
function setShipmentMethodApaczka() { } else {
return retryUntilSuccess(() => { reject('Nie znaleziono elementu warehousebundle_shipment_method');
return new Promise((resolve, reject) => { }
const methodElement = document.getElementById('warehousebundle_shipment_method'); });
if (methodElement) { }, 500, 20).catch(error => {
methodElement.value = '42'; console.error('Nie udało się ustawić metody wysyłki:', error);
const event = new Event('change', { bubbles: true }); throw error;
methodElement.dispatchEvent(event); });
console.log('Metoda wysyłki ustawiona na 42 (Apaczka).');
resolve();
} else {
reject('Nie znaleziono elementu warehousebundle_shipment_method');
}
});
});
} }
/** /**

Binary file not shown.

BIN
templates/.DS_Store vendored

Binary file not shown.