I was tasked to come up with a way to set 2 shipping rates per country, example;
UK: 1st kilo of weight = £5.00, subsequent half kilo’s £0.75
USA: 1st kilo = £8.00, subsequent half kilo’s £1.25
and so on, for EVERY country, and EVERY price is different!
As every price is different, zones.php nor table.php won’t really work as it would be far too much work to set up 200 zones [ 1 per country ], then add the price/weight ratios in…
So, my idea was to add a couple extra rows in the countries table of the database;
countries_cost_post
countries_post_extra
“post” to hold the value of the charge for the 1st kilo and “extra” to hold the value of each half kilo thereafter. Easy as 123. Then I had to amend admin/countries.php to allow me to both show, insert new and edit countries to add the shipping charges. Again, not too difficult. I then had to change the file /includes/classes/order.php to grab the value of the two new database entries based on shipping address. A little more difficult as this class file is quite complicated.
All done? Not by a long shot!
Now I had to create a whole new shipping method, which I called “Clubosc Localization”. This basically grabs the value of the shipping address “post” and “extra”, then multiplies by the appropriate weight to get the correct cost. Here’s the pertinent code from the file;
[php]
$error = false;
// up to 1 kgs, charge 1 kilo
$shipping_cost = $order->delivery[‘country’][‘countries_post_cost’];
// over 1 kgs, charge extra per half kilo
if ($shipping_weight > 1) {
$the_weight = $shipping_weight-1; // removing the first kilo
$down = $the_weight/0.5;
$up = ceil($down)*0.5; //making remainder up to next half kilo
$shipping_cost += (($up*2) * $order->delivery[‘country’][‘countries_post_extra’]);
}
if ($shipping_cost == 0) $error = true;
[/php]
The $up $down bit might not make much sense, but if you read this previous post, you’ll get an idea of what I am doing with that.
All in all, quite a complicated shipping module, one which needs lots of input in the “countries” table to work properly. I did also put in a check so that an error message is displayed if the $shipping_cost works out to zero (or in other words, the shop owner has not given the country a charge!).
Phew.
Thank you for this contribution. Pls i need to add a flat shipping to each country, mine is not as complicated as yours because, am not adding weight, the shipping cost is going to be the same per country irrespective of the weight.
I will appreciate your support in implementing this in osCommerce V2.2
Thanks for your prompt response.
Rgds/Kay
Use table rates. Or zone rates.