Naprawa buga ze zwracaniem wartości z funkcji async
This commit is contained in:
@@ -822,7 +822,7 @@ function getNewPaymentsAndDeliveries(data = null, firstLoad = false) {
|
||||
});
|
||||
|
||||
// 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 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");
|
||||
if(previousDeliveries) previousDeliveries.remove();
|
||||
document.querySelector(".ajax_cop .step2_sub").insertAdjacentHTML("beforeend",deliveryMarkup);
|
||||
@@ -838,9 +838,11 @@ function getNewPaymentsAndDeliveries(data = null, firstLoad = false) {
|
||||
|
||||
// Przygotowanie Płatności
|
||||
e.prepaids_method.forEach(function (method) {
|
||||
const checkedPayment = paymentValue === method.id;
|
||||
|
||||
const markup = `
|
||||
<label class="osc_item" for="payitem_${method.id}">
|
||||
<input id="payitem_${method.id}" value="${method.id}" type="radio" name="payform_id" ${paymentValue === method.id ? "checked" : ""} data-group="${method.group}">
|
||||
<input id="payitem_${method.id}" value="${method.id}" type="radio" name="payform_id" ${checkedPayment ? "checked" : ""} data-group="${method.group}">
|
||||
<div class="photo">
|
||||
<img src="${method.icon}" alt="${method.name}">
|
||||
</div>
|
||||
@@ -914,7 +916,7 @@ function getNewPaymentsAndDeliveries(data = null, firstLoad = false) {
|
||||
// Wstawienie pickuppoint jeśli edycja i istnieje
|
||||
if(data?.pickupData !== undefined && data?.pickupData !== null){
|
||||
const selectedShipping = document.querySelector(`#cop_seection2 input#${deliveryId}`);
|
||||
const pointExists = checkPrevPickupPoint(
|
||||
checkPrevPickupPoint(
|
||||
selectedShipping.parentElement.querySelector(".fselectedPoint"),
|
||||
data.pickupData.id,
|
||||
data.pickupData.name,
|
||||
@@ -922,11 +924,10 @@ function getNewPaymentsAndDeliveries(data = null, firstLoad = false) {
|
||||
data.pickupData.address.city,
|
||||
data.pickupData.address.postcode,
|
||||
data.deliveryMethodId
|
||||
);
|
||||
|
||||
// Odznaczenie punktu jeśli punkt odbioru nie istnieje(Wcześniej był zaznaczony przy edycji)
|
||||
if(!pointExists) selectedShipping.checked = false;
|
||||
|
||||
).then(pointExists=>{
|
||||
// Odznaczenie punktu jeśli punkt odbioru nie istnieje(Wcześniej był zaznaczony przy edycji)
|
||||
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){
|
||||
const prevPaymentMethod = JSON.parse(localStorage.getItem("prevPaymentMethod"));
|
||||
@@ -946,7 +947,7 @@ function getNewPaymentsAndDeliveries(data = null, firstLoad = false) {
|
||||
if(prevDeliveryInput){
|
||||
// sprawdzenie czy dostawa miała punkt odbioru
|
||||
if(prevDeliveryMethod.fselectedPoint){
|
||||
const pointExists = checkPrevPickupPoint(
|
||||
checkPrevPickupPoint(
|
||||
prevDeliveryInput.parentElement.querySelector(".fselectedPoint"),
|
||||
prevDeliveryMethod.fselectedPoint.deliveryPointId,
|
||||
prevDeliveryMethod.fselectedPoint.name,
|
||||
@@ -954,13 +955,21 @@ function getNewPaymentsAndDeliveries(data = null, firstLoad = false) {
|
||||
prevDeliveryMethod.fselectedPoint.city,
|
||||
prevDeliveryMethod.fselectedPoint.zipcode,
|
||||
prevDeliveryMethod.fselectedPoint.courierId
|
||||
);
|
||||
if(pointExists) prevDeliveryInput.checked = true;
|
||||
).then(pointExists=>{
|
||||
if(pointExists) prevDeliveryInput.checked = true;
|
||||
});
|
||||
}else{
|
||||
prevDeliveryInput.checked = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Zaznaczenie karty/banku w przypadku edycji
|
||||
const checkedPayment = document.querySelector(`#osc_prepaids_method input[name="payform_id"]:checked`)
|
||||
if(checkedPayment && (checkedPayment.dataset.group === "card" || checkedPayment.dataset.group === "transfer")){
|
||||
cloneElement(checkedPayment);
|
||||
}
|
||||
// Przeładowanie mapy
|
||||
loadMap();
|
||||
// Przeliczenie kosztu dostawy
|
||||
@@ -1039,6 +1048,7 @@ const SEARCH_PICKUP_POINTS_QUERY = (searchPickupPointsInput) => JSON.stringify({
|
||||
}`,
|
||||
})
|
||||
async function checkPrevPickupPoint(selectedPoint, deliveryPointId, name, street, city, zipcode, courierId){
|
||||
if(!name || !city || !zipcode) return false;
|
||||
// Pobranie punktów z tym samym id co poprzedni
|
||||
app_shop.fn.ajaxLoadSite(1)
|
||||
const resultData = await fetchData({
|
||||
@@ -1160,7 +1170,7 @@ function removePrevClone(){
|
||||
}
|
||||
|
||||
// Utworzenie modala po kliknieciu na "przelewy online" lub "karta platnicza"
|
||||
let ifChosenNewPaymentMethod=false;
|
||||
let ifChosenNewPaymentMethod = false;
|
||||
function showPaymentMethodModal(method){
|
||||
app_shop.fn.paymentModal = new Modal({
|
||||
element: $(`.${method}__methods`),
|
||||
@@ -1481,7 +1491,7 @@ async function updateCode(){
|
||||
// Pokazanie błędu
|
||||
const { message } = rebateStatus?.data?.activateRebateCode?.error;
|
||||
addError(rebateCode);
|
||||
rebateCode.insertAdjacentHTML("afterend",`<span class="help-block validate_message text-danger">${message}.</span>`);
|
||||
addErrorMessage(rebateCode, message);
|
||||
// Schowaj kod (show=false, error=true)
|
||||
toggleActiveCode(false, true);
|
||||
}
|
||||
@@ -1521,7 +1531,7 @@ function toggleActiveCode(show, error=false){
|
||||
rebateOptionWrapper.style.display = show ? "none" : "flex";
|
||||
rebateActiveWrapper.style.display = show ? "block" : "none";
|
||||
|
||||
if(!error)rebateCodeContainer.classList.remove("--fade-in");
|
||||
if(!error) rebateCodeContainer.classList.remove("--fade-in");
|
||||
else rebateCodeContainer.classList.add("--fade-in");
|
||||
|
||||
// zmień wartości
|
||||
@@ -1558,7 +1568,7 @@ rebateCode.addEventListener("keydown", e=>{
|
||||
// ZŁOŻENIE ZAMÓWIENIA
|
||||
|
||||
// Zwaliduj wszystkie dostępne inputy zawierające dane klienta i dane adresowe
|
||||
function validateAllInputs(){
|
||||
async function validateAllInputs(){
|
||||
// Zmienna trzymająca informację czy wystąpił jakiś błąd
|
||||
let allGood = true;
|
||||
|
||||
@@ -1569,12 +1579,12 @@ function validateAllInputs(){
|
||||
}
|
||||
if(!document.querySelector(".--logged")){
|
||||
// Sprawdzenie emaila i telefonu
|
||||
allGood = validateRequest(document.getElementById("client_email"), true) && allGood;
|
||||
allGood = await validateRequest(document.getElementById("client_email"), true) && allGood;
|
||||
allGood = validatePhone(document.getElementById("client_phone")) && allGood;
|
||||
// Sprawdzenie nazwy firmy i nipu
|
||||
if(document.getElementById("client_type1").checked){
|
||||
allGood = validateNotEmpty(document.getElementById("client_firm")) && allGood;
|
||||
allGood = validateRequest(document.getElementById("client_nip"), true) && allGood;
|
||||
allGood = await validateRequest(document.getElementById("client_nip"), true) && allGood;
|
||||
}
|
||||
// Sprawdzenie reszty pól
|
||||
allGood = validateFormInputs("client") && allGood;
|
||||
@@ -1586,13 +1596,13 @@ function validateAllInputs(){
|
||||
}
|
||||
return allGood
|
||||
}
|
||||
function validateFormInputs(query){
|
||||
async function validateFormInputs(query){
|
||||
let isFormGood = true;
|
||||
|
||||
isFormGood = validateNotEmpty(document.getElementById(`${query}_firstname`)) && isFormGood;
|
||||
isFormGood = validateNotEmpty(document.getElementById(`${query}_lastname`)) && isFormGood;
|
||||
isFormGood = validateStreet(document.getElementById(`${query}_street`)) && isFormGood;
|
||||
isFormGood = validateRequest(document.getElementById(`${query}_zipcode`),true) && isFormGood;
|
||||
isFormGood = await validateRequest(document.getElementById(`${query}_zipcode`),true) && isFormGood;
|
||||
isFormGood = validateNotEmpty(document.getElementById(`${query}_city`)) && isFormGood;
|
||||
|
||||
return isFormGood;
|
||||
|
||||
Reference in New Issue
Block a user