import wixWindow from 'wix-window'; import wixData from 'wix-data'; import { getCurrentCart } from 'backend/cart.jsw' $w.onReady(function () { $w('#updateTimeButton').hide(); getCurrentCart() .then((response) => { const cartId = response._id; if (response.lineItems.length > 0) { $w('#updateTimeButton').show(); findDelivery(cartId).then(() => { displayLightbox(cartId); }); } $w('#updateTimeButton').onClick((event) => { updateDeliveryTime(cartId); }); }); }); async function findDelivery(cartId) { wixData.query('deliveries') .eq('cartId', cartId) .find() .then((results) => { if (results.items.length > 0) { displayDeliveryTime(results.items[0]); } else { $w('#deliveryDate').text = 'Delivery day'; $w('#deliveryTime').text = 'Delivery time'; } }) .catch((err) => { console.error(err); }); } function updateDeliveryTime(cartId) { displayLightbox(cartId); } function displayDeliveryTime(data) { $w('#deliveryDate').text = data.deliveryDate.toDateString(); $w('#deliveryTime').text = data.deliveryTime; } function displayLightbox(cartId) { wixWindow.openLightbox('delivery details', { cartId: cartId }) .then((result) => { displayDeliveryTime(result); }); }
top of page

My cart

Cart is empty

Please choose correct delivery date before submitting

bottom of page