close ad
Databridge V2 with MySQLi support IS Now Available!
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

Shipping calculation - best approach and advice on database driven shipping rates please.

Thread began 8/10/2015 12:43 pm by Nathon Jones Web Design | Last modified 8/10/2015 8:54 pm by Nathon Jones Web Design | 453 views | 3 replies

Ray BorduinWebAssist

We populate the list with standard ISO country codes. It seems like your shipping rates really only require "UK" and "Europe", and "international" rates. So your rates table could probably just have 1, 2, or 3 in a Region list to determine that.

So if you had a rates table that looked like this:

RateID   |  MaxWeight   |  Region   |  Rate
-------------------------------------------------------
1 | 6 | 1 | 5.5




Then you set a session variable for the Region{

php:
<?php


$inEurope 
=  array();
$inEurope[] = "AL";
$inEurope[] = "AD";
$inEurope[] = "AT";
$inEurope[] = "BY";
$inEurope[] = "BE";
$inEurope[] = "BA";
$inEurope[] = "BG";
$inEurope[] = "HR";
$inEurope[] = "CY";
$inEurope[] = "CZ";
$inEurope[] = "DK";
$inEurope[] = "EE";
$inEurope[] = "FO";
$inEurope[] = "FI";
$inEurope[] = "FR";
$inEurope[] = "DE";
$inEurope[] = "GI";
$inEurope[] = "GR";
$inEurope[] = "HU";
$inEurope[] = "IS";
$inEurope[] = "IE";
$inEurope[] = "IT";
$inEurope[] = "LV";
$inEurope[] = "LI";
$inEurope[] = "LT";
$inEurope[] = "LU";
$inEurope[] = "MK";
$inEurope[] = "MT";
$inEurope[] = "MD";
$inEurope[] = "MC";
$inEurope[] = "NL";
$inEurope[] = "NO";
$inEurope[] = "PL";
$inEurope[] = "PT";
$inEurope[] = "RO"
$inEurope[] = "RU"
$inEurope[] = "SM"
$inEurope[] = "RS"
$inEurope[] = "SK"
$inEurope[] = "SI"
$inEurope[] = "ES"
$inEurope[] = "SE"
$inEurope[] = "CH"
$inEurope[] = "UA"
$inEurope[] = "VA"
$inEurope[] = "RS"
$inEurope[] = "IM"
$inEurope[] = "RS"
$inEurope[] = "ME"


if (!isset($_SESSION['ShipRegion'])) $_SESSION['ShipRegion'] = 1;

if (isset(
$_POST['Country_2'])) {
  if (
$_POST['Country_2'] == "GB") {
    
$_SESSION['ShipRegion'] = 1;
  } else if (
in_array($_POST['Country_2'],$inEurope[] )) {
    
$_SESSION['ShipRegion'] = 2;
  } else {
    
$_SESSION['ShipRegion'] = 3;
  }
}
?>



AND your SQL statement looks something like:

SELECT * FROM ShipRates WHERE Region = regionParam and MaxWeight <= weightParam ORDER BY MaxWeight ASC LIMIT 1

Take the "Rate" result from that query and save it as a session variable and you should be able to use that in your eCart query.

(note: I just googled European ISO country codes, and that list may be incomplete, add or remove lines as necessary)

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...