Wprowadzenie kraju ostatniego zamówienia do localStorage i sprawdzenie go przy uzupełnianiu danych o płatnościach i dostawie

This commit is contained in:
2024-01-16 13:09:02 +01:00
parent 8462d4932c
commit d3582a5c50
4 changed files with 107 additions and 38 deletions

View File

@@ -7,23 +7,23 @@ var stocks_list_more_txt=<iai:variable vid="więcej informacji"/>;var stocks_lis
// Zmienna trzymająca informacje o customowych markerach
// [wysokosc, szerokosc] w pikselach
const defaultIconSize = [50,45];
const defaultMarkerSize = [50,45];
const mapMarkerIcons = {
inpost: L.icon({
iconUrl: "/data/include/deliveries/markers/inpost/marker_locker.png",
iconSize: defaultIconSize,
iconSize: defaultMarkerSize,
className: ""
}),
default: L.icon({
iconUrl: "/gfx/standards/marker-icon.png",
iconSize: defaultIconSize,
iconSize: defaultMarkerSize,
className: ""
}),
// default: "/gfx/standards/marker-icon.png"
// custom : "/data/include/cms/map_marker/testMarkerIcon.svg?v=1703749620844"
orlen: L.icon({
iconUrl: "/data/include/deliveries/markers/paczkaOrlen/marker_orlen.png",
iconSize: defaultIconSize,
iconSize: defaultMarkerSize,
className: ""
}),
}
@@ -927,7 +927,7 @@ 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(localStorage.getItem("prevPaymentMethod") && localStorage.getItem("prevDeliveryMethod") && firstLoad){
else if(firstLoad && localStorage.getItem("prevCountry") && localStorage.getItem("prevCountry") === document.getElementById("client_region").value){
const prevPaymentMethod = JSON.parse(localStorage.getItem("prevPaymentMethod"));
// Zaznaczenie metod płatności które nie tworzą popupa
@@ -1651,15 +1651,34 @@ document.querySelector(".order2_button_order").addEventListener("click", async (
// Przerwanie składania zamówienia jeśli w trakcie walidacji wystąpił błąd
if (app_shop.vars.validation === 0) {
// Scroll do elementów z błędem
if(document.getElementById("order2_terms_conditions").checked && document.getElementById("order2_cancel").checked){
const errorEl = document.querySelector(".--error.has-error");
if(errorEl) scrollToHeight(errorEl)
else if(!document.querySelector(`input[name="payform_id"]:checked`)) scrollToHeight(document.querySelector("#checkout_step3_1 h2"));
else if(!document.querySelector(`input[name="shipping"]:checked`)) scrollToHeight(document.querySelector("#checkout_step2_1 h2"));
const errorEl = document.querySelector(".--error.has-error");
let scrolledToElement;
let alertMessage = "";
// Element sprawdzający czy regulamin jest zaznaczony
let termsAndConditions = document.getElementById("order2_terms_conditions").checked && document.getElementById("order2_cancel").checked;
if(!termsAndConditions) alertMessage += `${<iai:variable vid="Zatwierdź"/>} ${<iai:variable vid="Regulamin"/>}!<br/>`;
// Błąd w formularzu
if(errorEl){
scrolledToElement = errorEl;
alertMessage += `${<iai:variable vid="W formularzu wystąpiły błędy"/>}<br/>`;
}// Sprawdź metodę płatności i dostawy(scrollowanie do formularza ważniejsze)
if(!document.querySelector(`input[name="payform_id"]:checked`)){
scrolledToElement = errorEl || document.querySelector("#checkout_step3_1 h2");
alertMessage += `${<iai:variable vid="Proszę wybrać metodę płatności"/>}<br/>`;
}
Alertek.show_alert(`${<iai:variable vid="W formularzu wystąpiły błędy"/>}`);
return app_shop.fn.ajaxLoadSite(0), !1;
if(!document.querySelector(`input[name="shipping"]:checked`)){
scrolledToElement = errorEl || document.querySelector("#checkout_step2_1 h2");
alertMessage += `${<iai:variable vid="Proszę wybrać dostępną metodę dostawy"/>}`;
}
// Jeśli użytkownik zatwierdził regulamin, przescrolluj do elementu z błędem
if(termsAndConditions) scrollToHeight(scrolledToElement);
// Pokaż error i przerwij składanie zamówienia
Alertek.show_alert(alertMessage);
return app_shop.fn.ajaxLoadSite(0);
}
// Rejestracja użytkownika i/lub złożenie zamówienia
@@ -1677,7 +1696,9 @@ document.querySelector(".order2_button_order").addEventListener("click", async (
});
// Przescrolluj do
function scrollToHeight(scrollToEl){
const yOffset = app_shop.vars.view === 1 ? -100 : -45;
let yOffset = -45;
if(app_shop.vars.view === 1) yOffset = -100;
if(app_shop.vars.view === 2) yOffset = -75;
const y = scrollToEl.getBoundingClientRect().top + window.pageYOffset + yOffset;
window.scrollTo({top: y, behavior: 'smooth'});
}
@@ -1835,6 +1856,8 @@ function sendOrder(data){
},
success: function (e) {
if(e.location){
// Zapisanie państwa żeby sprawdzić czy się zgadza
const usedCountry = document.getElementById("deliver_to_billingaddr").checked ? document.getElementById("delivery_region").value : document.getElementById("client_region").value;
// Zapisanie płatności i dostawy na następny raz
const paymentInput = document.querySelector(`input[name="payform_id"]:checked`)
const usedPaymentMethod = {
@@ -1859,6 +1882,7 @@ function sendOrder(data){
localStorage.setItem("prevPaymentMethod", JSON.stringify(usedPaymentMethod));
localStorage.setItem("prevDeliveryMethod", JSON.stringify(usedDeliveryMethod));
localStorage.setItem("prevCountry", usedCountry);
// Przeniesienie na stonę informacji o zamóieniu
window.location.href = e.location;