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

@@ -132,9 +132,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 !== ""){
@@ -758,7 +767,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;
@@ -776,11 +785,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;
@@ -819,6 +828,10 @@ function getNewPaymentsAndDeliveries(data = null, firstLoad = false) {
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>`;
const previousDeliveries = document.getElementById("osc_order1");
@@ -927,8 +940,8 @@ function getNewPaymentsAndDeliveries(data = null, firstLoad = false) {
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"){
@@ -940,7 +953,7 @@ function getNewPaymentsAndDeliveries(data = null, firstLoad = false) {
}
// 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)
@@ -978,6 +991,8 @@ function getNewPaymentsAndDeliveries(data = null, firstLoad = false) {
if(firstInput) deliveryDate(firstInput.value, firstInput.dataset.delivery, firstInput.dataset.pickuppoint);
calculateBasketCost();
app_shop.fn.ajaxLoadSite(0);
firstTimeLoadPage = false;
},
});
};
@@ -1870,9 +1885,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;
@@ -2043,11 +2062,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){
@@ -2131,6 +2151,7 @@ function initOSCOP(){
// Pobranie danych o edytowanym zamówieniu
async function getEditData(){
const data = await fetchData({
data: ORDER_DETAILS(`OrderDetailsInput: {
orderNumber: ${editNumber.value},
@@ -2183,9 +2204,9 @@ function initOSCOP(){
// 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){