Wprowadzenie drobnych poprawek i przekierowania ze strony order1 na place-order

This commit is contained in:
2024-01-18 08:10:53 +01:00
parent aee6659f67
commit 7c1c1b97dd
4 changed files with 83 additions and 32 deletions

View File

@@ -129,9 +129,18 @@ function loadMap() {
// Jesli nie ma informacji potrzebnej do mapy, zapisz wiadomosc do errora
let errorMessage = "";
if(!clientStreet) errorMessage += `${<iai:variable vid="Wpisz ulicę i numer domu klienta"/>} <br>`;
if(!clientZipCode) errorMessage += `${<iai:variable vid="Podaj kod pocztowy adresu dostawy"/>} <br>`;
if(!clientCity) errorMessage += `${<iai:variable vid="Wpisz miasto odbiorcy przesyłki"/>}`;
if(!clientStreet){
errorMessage += `${<iai:variable vid="Wpisz ulicę i numer domu klienta"/>} <br>`;
addErrorMessage(document.getElementById("client_street"), <iai:variable vid="Wpisz ulicę i numer domu klienta"/>)
}
if(!clientZipCode){
errorMessage += `${<iai:variable vid="Podaj kod pocztowy adresu dostawy"/>} <br>`;
addErrorMessage(document.getElementById("client_zipcode"), <iai:variable vid="Podaj kod pocztowy adresu dostawy"/>)
}
if(!clientCity){
errorMessage += `${<iai:variable vid="Wpisz miasto odbiorcy przesyłki"/>}`;
addErrorMessage(document.getElementById("client_city"), <iai:variable vid="Wpisz miasto odbiorcy przesyłki"/>)
}
// Zablokuj wybranie mapy jak nie ma adresu
if(errorMessage !== ""){
@@ -762,7 +771,7 @@ const SET_REGION = (setRegionInput) => JSON.stringify({
});
// Zmiana regionu dostawy
async function changeRegion(payAndDelData = null, firstLoad = false) {
async function changeRegion(payAndDelData = null) {
// Pobranie informacji o regionie z formularza
const clientRegion = document.getElementById("client_region").value;
const deliveryRegion = document.getElementById("deliver_to_billingaddr").checked ? document.getElementById("delivery_region").value : clientRegion;
@@ -780,11 +789,11 @@ async function changeRegion(payAndDelData = null, firstLoad = false) {
if (status !== 'success') return alert("Błąd podczas zmiany kraju. Przeładuj stronę jeszcze raz.");
// Pobranie nowych metod płatności i dostaw
getNewPaymentsAndDeliveries(payAndDelData, firstLoad);
getNewPaymentsAndDeliveries(payAndDelData);
};
// Załadowanie metod dostaw i płatności
function getNewPaymentsAndDeliveries(data = null, firstLoad = false) {
function getNewPaymentsAndDeliveries(data = null) {
// Wyczyszczenie zapisanych poprzednich metod płatności
prevPayment = undefined;
prevShipping = undefined;
@@ -822,6 +831,10 @@ function getNewPaymentsAndDeliveries(data = null, firstLoad = false) {
e.dvp.forEach(function (method) {
dvpMarkup += prepareDeliveryMarkup(method, deliveryId);
});
// Dane do zaznaczenia płatności i dostawy jeśli wcześniej na tej przeglądarce(localStorage) było już zamówienie
const prevOrderInfo = JSON.parse(localStorage.getItem("prevOrderInfo"));
console.log(prevOrderInfo);
// Wstawienie metod dostaw na strone
const deliveryMarkup = `<div id="osc_order1"><div id="osc_order1_prepaid" style="${paymentValue === "cash" ? "display:none;" : "display:block;"}">${prepaidMarkup}</div><div id="osc_order1_dvp" style="${paymentValue === "cash" ? "display:block;" : "display:none;"}">${dvpMarkup}</div></div>`;
@@ -931,8 +944,8 @@ const checkedPayment = paymentValue === method.id;
if(!pointExists) selectedShipping.checked = false;
});
}// Sprawdzenie czy użytkownik ma zapisane poprzednio użyte metody w przeglądarce(tylko przy pierwszym załadowaniu strony)
else if(firstLoad && localStorage.getItem("prevCountry") && localStorage.getItem("prevCountry") === document.getElementById("client_region").value){
const prevPaymentMethod = JSON.parse(localStorage.getItem("prevPaymentMethod"));
else if(firstTimeLoadPage && prevOrderInfo && prevOrderInfo?.prevCountry === document.getElementById("client_region").value){
const prevPaymentMethod = prevOrderInfo.prevPaymentMethod;
// Zaznaczenie metod płatności które nie tworzą popupa
if(prevPaymentMethod.id !== "payitem_2" && prevPaymentMethod.group !== "card" && prevPaymentMethod.group !== "transfer"){
@@ -944,7 +957,7 @@ const checkedPayment = paymentValue === method.id;
}
// Poprzednia dostawa
const prevDeliveryMethod = JSON.parse(localStorage.getItem("prevDeliveryMethod"));
const prevDeliveryMethod = prevOrderInfo.prevDeliveryMethod;
const prevDeliveryInput = document.querySelector(`input#${prevDeliveryMethod.id}`);
// Sprawdzenie czy istnieje metoda dostawy (na wypadek gdyby była usunięta lub klient zamawiał do innego kraju)
@@ -982,6 +995,8 @@ const checkedPayment = paymentValue === method.id;
if(firstInput) deliveryDate(firstInput.value, firstInput.dataset.delivery, firstInput.dataset.pickuppoint);
calculateBasketCost();
app_shop.fn.ajaxLoadSite(0);
firstTimeLoadPage = false;
},
});
};
@@ -1874,9 +1889,13 @@ function sendOrder(data){
} : false
};
localStorage.setItem("prevPaymentMethod", JSON.stringify(usedPaymentMethod));
localStorage.setItem("prevDeliveryMethod", JSON.stringify(usedDeliveryMethod));
localStorage.setItem("prevCountry", usedCountry);
const prevOrderInfo = {
prevPaymentMethod: usedPaymentMethod,
prevDeliveryMethod: usedDeliveryMethod,
prevCountry: usedCountry
}
localStorage.setItem("prevOrderInfo", JSON.stringify(prevOrderInfo));
// Przeniesienie na stonę informacji o zamóieniu
window.location.href = e.location;
@@ -2047,11 +2066,12 @@ async function fetchData(options = {}) {
}
}
let firstTimeLoadPage = true;
function initOSCOP(){
// Element z numerem edycji jeśli jest
const editNumber = document.getElementById("edit-number");
if(document.querySelector(".ajax_cop").childElementCount && !editNumber) changeRegion(null, true);
if(document.querySelector(".ajax_cop").childElementCount && !editNumber) changeRegion(null);
// Jeśli edycja zamówienia uzupełnij dane (niewiadomo jak z voucherem bo go się nie da edytować)
if(editNumber){
@@ -2135,6 +2155,7 @@ if(editNumber){
// Pobranie danych o edytowanym zamówieniu
async function getEditData(){
const data = await fetchData({
data: ORDER_DETAILS(`OrderDetailsInput: {
orderNumber: ${editNumber.value},
@@ -2187,9 +2208,9 @@ if(editNumber){
// Metody płatności i dostaw
if(document.getElementById("delivery_region").value !== document.getElementById("client_region").value) changeRegion(orderData);
else getNewPaymentsAndDeliveries(orderData, true);
else getNewPaymentsAndDeliveries(orderData);
// Jeśli nie było dostawy na inny adres uzupełnij metody dostaw i płatności
}else getNewPaymentsAndDeliveries(orderData, true);
}else getNewPaymentsAndDeliveries(orderData);
// Uzupełnienie uwag dla sklepu/kuriera
if(orderDetails.remarks){