The repo for Purrform's main BigCommerce store.
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request #8 from Teser301/check-invalid-dates

fix: Refactor date validation logic in checkout.html

authored by

Rogerio Romao and committed by
GitHub
dce4b16e 70ea3823

+33 -2
+1 -1
config.json
··· 1 1 { 2 - "name": "DEV Theme - store msg externally", 2 + "name": "DEV Theme - check invalid dates", 3 3 "version": "6.10.0", 4 4 "template_engine": "handlebars_v4", 5 5 "meta": {
+32 -1
templates/pages/checkout.html
··· 437 437 }); 438 438 439 439 // ------------------------------------------------------// 440 + const disabledDates = []; // we will need to access this in multiple functions 441 + 442 + // ------------------------------------------------------// 440 443 // This handles 'datepicker' in 'shipping' 441 444 const shippingSelector = '#checkout-shipping-options'; 442 445 ready(shippingSelector, (shippingOptionsElement) => { ··· 473 476 // Create calendar and attach date picker logic here 474 477 let dailyDeliveryLimit = 250; 475 478 const dailySlotValues = {}; 476 - const disabledDates = []; 477 479 478 480 // get delivery dates from middleware 479 481 fetch('https://purrform-apps-027e.onrender.com/deliveryDates') ··· 487 489 disabledDates.push(...data.unavailableDates); 488 490 for (const [date, slots] of Object.entries(data.dateSlots)) { 489 491 dailySlotValues[date] = slots; 492 + if (slots <= 0) { 493 + disabledDates.push(date); 494 + } 490 495 } 491 496 if (data.perDay) { 492 497 dailyDeliveryLimit = data.perDay; ··· 793 798 const deliveryInstructions = data.customerMessage; 794 799 795 800 if (deliveryInstructions?.trim()) { 801 + // need to check if the date is valid 802 + if (!deliveryInstructions.includes(' | ')) { 803 + missingWarn.textContent = 804 + 'Invalid delivery date. Please edit your shipping details above and select a valid delivery date.'; 805 + missingWarn.style.display = 'block'; 806 + return; 807 + } 808 + 809 + const date = deliveryInstructions.split(' | ')[0]; 810 + if (disabledDates.includes(date)) { 811 + missingWarn.textContent = 812 + 'This delivery date cannot be selected. Please edit your shipping details above and select another delivery date.'; 813 + missingWarn.style.display = 'block'; 814 + return; 815 + } 816 + 817 + // check if the date is in the past 818 + const today = new Date(); 819 + const selectedDate = new Date(date); 820 + if (selectedDate < today) { 821 + missingWarn.textContent = 822 + 'This delivery date is in the past. Please edit your shipping details above and select another delivery date.'; 823 + missingWarn.style.display = 'block'; 824 + return; 825 + } 826 + 796 827 paymentContinueButton.click(); 797 828 } else { 798 829 missingWarn.style.display = 'block';