Restricting Address for Online Ordering Food

Hi I’m wondering can anyone help me. I’m currently building a website for online food ordering. It not a multi vendor site its just one takeaway and I’m struggling to work out how I can restrict orders being placed outside the delivery area. Basically I want the customer to receive a message that only collection is available for your address if their address is not on a list of zones or whatever.

Can anyone please give me advice or point me in the right direction. The system is built on OSCommerce but it has been totally ripped appart and changed for my needs.

well the person has to add in their address in order to place an order correct?
So take the part where they input a zip code,
then you decide which zip codes you plan on servicing and do something like(this is just an example):
[php]
$zip=$_POST[‘zipcode’];
$goodzip=85002;
$goodzip1=85004;
$goodzip2=85006;

if($zip != $goodzip || $zip != $goodzip1 || $zip != $goodzip2){die("Sorry we do not service your area, please move to our service area and try us again! ");}
[/php]

or if there is a straight range of area codes that your service:

[php]
$zip=$_POST[‘zipcode’];

if($zip > 85002 || $zip < 85009){ die("Sorry we do not service your area, please move to our service area and try us again! ");}
[/php]

Or, use the “In-Array” option…

[php]
$zip=$_POST[‘zipcode’];
$zipcodes = array(‘85002’, ‘85004’, ‘85006’);

if(in_array($zip, $zipcodes, true){die("Sorry we do not service your area, please move to our service area and try us again! ");}
[/php]
Easier than a lot of compares, especially if you have a lot of zipcodes… Enjoy!

Thank you for the answers but I should have said in the orignal post I’m in Ireland and we have no zip codes and delivery might be available for half an area and not all which is why I’m having problems…

Ireland??? My friend just came back from there. She said is was beautiful there! I saw some great pictures!

Anyway, You would have to create a mapping system to indicate where the location is and then put them into the same type of table. But most would depend on how your address work. Here in the US, we have States, Counties, Cities, Streets and finally addresses (Numbers on houses). What do you have there?

You can still use the same array set up as I mentioned. It will still work for you. Just have to create a larger array made up of more details. Example, if you have streets marked out, enter all the ones you deliver to. If you deliver only to “part” of a street, you would have to mark the stopping point. This can be done with multiple arrays or even better a “Multiple-Dimensional” array where the street name along with the stopping point would be entered. Multiple Dimensional arrays are like $Locations[$StreetName][$AddressToStopAt] …
You could make up a map of the delivery area and part of the online-ordering would involve them clicking on where they are at. That is not too tricky.

Lots of options. But, let us know the “States/Counties/Cities/Streets” layout of Ireland and we might be able to come up with something for you…

One more note on Ireland postal codes.
This is a good read: http://en.wikipedia.org/wiki/Postal_codes_in_the_Republic_of_Ireland

Make your program easy to change as your delivery postal codes will be there one day soon!

HaHa thanks for the wiki link but living in Ireland I can tell you that they have been talking about postal codes for years. I’ll be an old man before the governement gets around to it :wink:

Anyway…We have the following

number / address / area / town / county

and it looks like this

25 Fake Street
Fake Avenue
Fake Town
Dublin
Ireland

and some places have a post code from Dublin 1 to 24. I can’t post links but google Dublin post codes and look at the link on DublinTourist(dot)com

Well, that is simple enough. But, be warned… You will have to create a list of all areas you deliver to. This would have to contain all of your area down to the smallest details. Perhaps even notes on which door is used. This master database table would be large. First, a good map of the area you will deliver to. Next a database to hold customer info including the locations. Next a second table with just the locations and a yes/no field allowing delivery or not. I will give you my thoughts on it. (Sorry a lot to cover…)

First, in most food delivery systems that I know about (Have worked for a pizza delivery shop), everything is based on either phone-number or full-name. So, pick some thing to use as your index. Next create a database that has all of your info need. Create a table in it called Clients or Customers, something similar. This would include the data you mentioned:

Name, PhoneNumber, address-county, address-town, address-area, address-street, address-number

Each of these items would be a separate field in the table. Whenever a new customer calls or stops in, you would fill out the above info on the system and check if it is an area you deliver to. To verify they are in a deliverable area would involve another table. This table would have similar fields. These depend on how you layout your delivery area. Let’s say you delivery to all of one county. You would have these fields:

address-county, address-town, address-area, address-street, address-number, AllowDeliveryToHere

This would involve a bit of code to check for. Put “yes” or “no” into the last field. First, if you deliver to all areas of one county, you could use a wildcard such as “" and put it into all of the fields for that county. When checking to see if the new customer’s address is okay for delivery, you check each field. If it contains the wildcard char, then move to the next field. Basically, you match each entry starting with the largest, the county. If the county is not a deliverable one, it would contain a “NO” and the routine would stop and indicate NO-DELIVERY-TO-THIS-ADDRESS. (Do not bother checking the small parts if this happens.) If you only deliver to one certain street in that county, you would have to put ‘yes’ in the county, town, are and some other code in the address-street to indicate the ‘this street only’. That would be "” in everything, in address-street, you would have all the street names and all except the one street would have “NO” in the AllowDeliveryTo field. As you develop your database you can always add a field if needed, but, then you have to go back and enter data for all your previously created locations, so it is very important to lay out the tables before creating the code. Another idea is a general layout on paper before creating the tables. Right down a few areas you deliver to, put them in a list sorted out with the fields we have been talking about and see how they would be listed in the table. Or start with an EXCEL spreadsheet with the few dozen sample deliveries and see how they would fit into your new tables. Once the delivery areas tables have been created, then you can work on the code to fill them and use them.

Whew! A tricky subject. Here in the States, it is easier as you can usually use zipcode or local phone number area codes. Hmmm, what is your phone system like? Does every delivery area have a phone? Perhaps that might be a way to go.

Lots for you to think about. Hope I didn’t make it more confusing for you… Good luck…

Hi ErnieAlex,

no you didn’t make it more confusing, I was already confused :wink: and your post confirmed what I was thinking which is going to be a right pain to complete. The phone number is a no go as there is no set number for areas and most people use mobiles (cell phones) which doesn’t help and besides you could have someone living in area #1 with landline number starting 45 and then they move to area #2 which is 46 but most people carry their numbers so then their living in area #2 with an area #1 45 number. They only way they loose the number is moving county and the prefix changes. But anyway I’ll stop waffeling since 90% use mobiles and they could be living anywhere in Ireland with multiple operators…

I was thinking that maybe I could have an a drop down selection for delivery area where if their area is not listed they could only order for collection…

So a form with:

Name
House/Apt number:
Street Address:
Area: (Area #1, Area #2, Area #3, etc) (Drop Down selection)
Town: (Drop down baced on Area selection)
Phone:

This might be the way to go but I need to give the option of ordering and paying online for collections outside the delivery areas and if I use this method I might just need a selection field of “other area” giving a blank field to input their area and then a message telling the customer “collection is only available for this area”…

This might be the simplist option because inputting all the area details in the database will take me forever…

There is a company here that offers an auto find address and would handle the message of delivery / collection but they want €15,000 to set it up and €7500 per year which is way way out of the budget of the customer. They handle Dominos.ie which is the best online ordering for food available in Ireland. I have to say it is really cool. You just input your house number and street address and it auto finds your delivery store but at that kind of money it’s just not cost effective for small take aways etc.

Anyway thanks for all the help and anymore feed back is appricated and by the way I’m always looking for freelancers for PHP projects so if anyone is interested in some work drop me a message with samples of previous work and I’ll come back to you when I need someone for the next project…

One other idea might be to use the GIS info for your area. Not sure how much is available in Ireland.
Here in the States, it is widely available. Every street in the US is mapped and available as a free download.
It is in a table format and can easily be put into a database. I just checked and found a ton of info available for Ireland. It comes with all streets mapped for you and some resources are fully programmable. You could just add in your yes/no column for your uses.

Here is one example site:  http://www.irish-surveyors.ie/index.php/resources/117-online-mapping-resources

I found this by Google with “GIS map data Ireland”, but, only grabbed one for you as an example.

To use this type of data, you have to learn about GIS a little. I have downloaded it for my town and made a 3D-map of the city for a project I am working on. I can not believe that I forgot to mention this earlier. The GIS data comes in various formats. You would be looking for the ROAD or STREET mapping as these would have the data your are looking for. Just one more idea for you. Good luck…

Thanks ErnieAlex I just did a google and found loads of sources of information and downloads that I can look at. This might be the answer to my prayers. I now have the weekend to work this out. Thanks again for all the help and information.

:smiley:

No problem. I am glad I remember that option.

I think you may use zip code option for this problem. You may decide which zip-code area you are able to serve and allow those only.

<a href=“http://www.chefoncalldelivery.com/”]food on-line

Using this code and this page you should be able to return a numerical distance variable and then check that against some defined limit. I know this code is for US postal codes but reading the page will tell you how to use addresses for any location.

[php]<?php
function curl_request($sURL,$sQueryString=null)
{
$cURL=curl_init();
curl_setopt($cURL,CURLOPT_URL,$sURL.’?’.$sQueryString);
curl_setopt($cURL,CURLOPT_RETURNTRANSFER, TRUE);
$cResponse=trim(curl_exec($cURL));
curl_close($cURL);
return $cResponse;
}

$sResponse=curl_request(‘http://maps.googleapis.com/maps/api/distancematrix/json’,
‘origins=04429&destinations=02135&mode=driving&units=imperial&sensor=false’);
$oJSON=json_decode($sResponse);
if ($oJSON->status==‘OK’)
$fDistanceInMiles=(float)preg_replace(’/[^\d.]/’,’’,$oJSON->rows[0]->elements[0]->distance->text);
else
$fDistanceInMiles=0;

echo 'Distance in Miles: '.$fDistanceInMiles.PHP_EOL;[/php]

https://developers.google.com/maps/documentation/distancematrix/

This is a dead thread. Why post in it. LOCKED

This topic is NOT locked. It is open and any new and improved code for this project is welcomed!

Thank you Andrew for your post. I will look at this new code for a project I can use it in.

Sponsor our Newsletter | Privacy Policy | Terms of Service