Skip to content

add delivery radius updates#210

Open
parinaB wants to merge 2 commits into
PatelHarsh2006:mainfrom
parinaB:main
Open

add delivery radius updates#210
parinaB wants to merge 2 commits into
PatelHarsh2006:mainfrom
parinaB:main

Conversation

@parinaB
Copy link
Copy Markdown

@parinaB parinaB commented May 24, 2026

[Feature Add] Enhanced Delivery Radius Validation with Real-Time Eligibility Feedback

🔗 Related Issue

Closes #72


🧩 Problem

The previous checkout flow had zero delivery radius validation — clicking "Place Order" would immediately confirm any order regardless of the user's location. There was no feedback, no location check, and no error handling.


✅ What This PR Does

Introduces a complete delivery eligibility system triggered at checkout:

  • 📍 Fetches user's real-time GPS coordinates via the Geolocation API
  • 📐 Calculates Haversine distance from the restaurant origin
  • 🟢 Within 5 km → eligible, order proceeds
  • 🟠 5–8 km → blocked with a "just outside range" message
  • 🔴 Beyond 8 km → blocked with a clear area-not-served message
  • ⚠️ Handles all edge cases: permission denied, GPS unavailable, request timeout
  • 🔘 Checkout button disables + shows "Checking location..." during async check
  • Inline styled status block replaces all alert() calls for delivery feedback

📁 Files Changed

File Change
js/main.js -> Added haversineDistance(), getDeliveryZone(), checkDeliveryEligibility(), showDeliveryStatus() — replaced window.checkout with async guarded version
cart.html --> Added <div id="delivery-status" aria-live="polite"> above checkout button

📸 Screenshots

Screenshot 2026-05-24 at 9 07 29 PM Screenshot 2026-05-24 at 9 04 59 PM Screenshot 2026-05-24 at 9 09 12 PM

🧪 How to Test

  1. Add items to cart
  2. Click Place Order
  3. Allow location when prompted
  4. Observe inline delivery status message
  5. To test rejection: deny location permission → error message appears

📝 Notes

  • Restaurant coordinates are currently a placeholder (to be updated by maintainer)
  • Uses maximumAge: 60000 to avoid redundant GPS calls on repeat attempts
  • Orange theme preserved throughout; no style regressions
  • Fully accessible — status block uses aria-live="polite"

@parinaB
Copy link
Copy Markdown
Author

parinaB commented May 27, 2026

@PatelHarsh2006 any reviews or updates?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve Delivery Radius Validation and User Feedback During Checkout

1 participant