close ad
WARNING: Do Not Install the DREAMWEAVER CC 2017 or 2018 Update »
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

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 Ray Borduin | 334 views | 3 replies |

Nathon Jones Web Design

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

The shipping we're configuring is calculated by weight. When the contents of the cart reaches a particular weight we want the corresponding Shipping Charge to be applied:

UK
up to 6kg - £7.00
6kg-12kg - £10.00
etc

Europe
up to 6kg - £10.00
6kg-12kg - £15.00
etc

USA & Rest of World
up to 6kg - £15.00
6kg-12kg - £20.00
etc

Each product has a weight value (a field in the product database) which we've bound to the pre-set Weight column in the Add to Cart behaviour. We can also see the total weight, for the entire cart contents, using the pre-set TotalWeight column so we can perform a calculation, although I'm not sure how, in order to establish the total shipping charge.

Here's where I'm confused....

The customer has to select a country from the country drop down menu however this is automatically installed by the eCart Checkout Wizard and doesn't, as far as I can see, correspond with any shipping charges unless, perhaps, if you use one of the pre-installed carriers (UPS etc).

If a customer selects, for example, France then how do I make sure that the correct shipping charge is applied?

I'm aware that I probably need to create a Shipping Rates table, but I'm completely confused about what fields this should have:
ShippingRegionID - (unique row ID)
ShippingRegionTitle - (Europe, USA, Rest of World etc)
ShippingRegionRate6kg - (price)
ShippingRegionRate12kg - (price)
ShippingRegionRate18kg - (price)
ShippingRegionRate24kg+ - (price)

I then need to create a country table which lists all of the countries that we ship to that also includes the ShippingRegionID and then do an INNER JOIN to link the country to the correct region and rate?

Checking eCart, I can create Shipping Rules but I don't see any tie in with "Country" in the triggers section.

My brain feels like mush with it all so I'd appreciate guidance on the best approach to this because I feel like I'm over-complicating things.

Thank you.
NJ

Sign in to reply to this post

Ray BorduinWebAssist

If you create a shipping table you can add a recordset that filters and returns the correct shipping charge on the confirm_cart.php page.

Then store the value returned by the Recordset as a session variable. The rule in the cart can then just charge the amount stored in that session variable when that session variable is defined.

Sign in to reply to this post

Nathon Jones Web Design

So I query the recordset using the country that the customer has selected from the drop-down menu?

eCart Checkout Wizard pre-fills the Country drop down menu AND features a unique set of country codes. I assume that these codes are needed for passing to various payment providers - in our case Sage Pay - so I'm confused about how I edit this and am nervous about changing these codes in case they cause problems further down the line. PayPal, for example, needs specific country codes for verifying a billing address, if I remember correctly.

I'm lost with this Ray. How do we use the eCart Country drop down menu to decide what the shipping cost will be to the customer?

Will I have to copy EVERY country code into my new Shipping table and create a corresponding shipping price, making sure not to edit the country title or country code?

I'd appreciate your advice on it as I'm really not sure how we establish what the shipping cost for the customer should be based on the country drop down menu that eCart has created.

Thank you.
NJ

EDIT:

The eCart Country drop down menu looks like this..

<select class="formMenufield_Medium" name="Country" id="Country" rel="<?php echo(WA_coalesce(array(WA_getSavedFormValue("CheckoutWizard_NewFromBlank_Default","Country"),(isset($_GET["invalid"])?ValidatedField("confirmcart","Country"):"")))); ?>" tabindex="8" title="Please select your country." required>
<option value="" <?php if (!(strcmp("", WA_coalesce(array(WA_getSavedFormValue("CheckoutWizard_NewFromBlank_Default","Country"),(isset($_GET["invalid"])?ValidatedField("confirmcart","Country"):"")))))) {echo "selected=\"selected\"";} ?>>Select Country</option>
<option value="US" <?php if (!(strcmp("US", WA_coalesce(array(WA_getSavedFormValue("CheckoutWizard_NewFromBlank_Default","Country"),(isset($_GET["invalid"])?ValidatedField("confirmcart","Country"):"")))))) {echo "selected=\"selected\"";} ?>>United States</option>
<option value="GB" <?php if (!(strcmp("GB", WA_coalesce(array(WA_getSavedFormValue("CheckoutWizard_NewFromBlank_Default","Country"),(isset($_GET["invalid"])?ValidatedField("confirmcart","Country"):"")))))) {echo "selected=\"selected\"";} ?>>United Kingdom</option>
<option value="AL" <?php if (!(strcmp("AL", WA_coalesce(array(WA_getSavedFormValue("CheckoutWizard_NewFromBlank_Default","Country"),(isset($_GET["invalid"])?ValidatedField("confirmcart","Country"):"")))))) {echo "selected=\"selected\"";} ?>>Albania</option>

...etc.

If I need to associate a shipping price to whatever country the user selects then I'll need to database drive this list, won't I?

I still don't understand, however, how I then extract, also, the shipping price so that I can capture it and store it as a session value.

Thank you.
NJ

Sign in to reply to this post

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)

Sign in to reply to this post

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...