Assuming you are using OpenCart 0.7.8:
Change your
/catalog/extension/shipping/zone.php as follows:
Code: Select all
<?php
class ShippingZone extends Shipping {
function __construct(&$locator) {
$this->address =& $locator->get('address');
$this->cart =& $locator->get('cart');
$this->config =& $locator->get('config');
$this->currency =& $locator->get('currency');
$this->database =& $locator->get('database');
$this->language =& $locator->get('language');
$this->session =& $locator->get('session');
$this->tax =& $locator->get('tax');
$this->config =& $locator->get('config');
$this->weight =& $locator->get('weight');
$this->language->load('extension/shipping/zone.php');
}
function getWeight() {
$language = $this->language;
$languageId = $language->languages[$language->code]['language_id'];
$total = 0;
foreach ($this->cart->products as $product) {
$productId = $product['product_id'];
$weight = $this->weight->convert($product['weight'] * $product['quantity'], $product['weight_class_id'], $this->config->get('config_weight_class_id'));
$total += $weight;
}
$defaultWeightClassId = $this->config->get('config_weight_class_id');
$kgWeightClassId = 0;
if ($row = $this->database->getRow( "select weight_class_id from `weight_class` where `unit`='kg' and language_id=$languageId;" )) {
$kgWeightClassId = $row['weight_class_id'];
}
if ($kgWeightClassId == 0) {
$error = $this->language->get('text_zone_error_unit' );
}
$weight = $this->weight->convert( $total, $defaultWeightClassId, $kgWeightClassId );
return $weight;
}
function quote() {
$quote_data = array();
$results = $this->database->cache('geo_zone', "select * from geo_zone order by name");
foreach ($results as $result) {
if ($this->config->get('zone_' . $result['geo_zone_id'] . '_status')) {
if ($this->database->getRows("select * from zone_to_geo_zone where geo_zone_id = '" . (int)$result['geo_zone_id'] . "' and country_id = '" . (int)$this->address->getCountryId($this->session->get('shipping_address_id')) . "' and (zone_id = '" . (int)$this->address->getZoneId($this->session->get('shipping_address_id')) . "' or zone_id = '0')")) {
$status = true;
} else {
$status = false;
}
} else {
$status = false;
}
if ($status) {
$cost = 0;
$rates = explode(',', $this->config->get('zone_' . $result['geo_zone_id'] . '_cost'));
foreach ($rates as $rate) {
$array = explode(':', $rate);
if ($this->cart->getWeight() <= $array[0]) {
$cost = @$array[1];
break;
}
}
$quote_data[$result['geo_zone_id']] = array(
'id' => 'zone_' . $result['geo_zone_id'],
'title' => $result['name'],
'cost' => $cost,
'text' => $this->currency->format($this->tax->calculate($cost, $this->config->get('zone_tax_class_id'), $this->config->get('config_tax')))
);
}
}
$weight = $this->getWeight();
$method_data = array();
if ($quote_data) {
$method_data = array(
'id' => 'zone',
'title' => $this->language->get('text_zone_title'),
'quote' => $quote_data,
'tax_class_id' => $this->config->get('zone_tax_class_id'),
'sort_order' => $this->config->get('zone_sort_order'),
'error' => (($weight < 6.0) || (weight > 20.0)) ? $this->language->get('text_zone_error_weight' ) : false
);
}
return $method_data;
}
}
?>
Also use the following modified
/catalog/language/english/extension/shipping/zone.php file:
Code: Select all
<?php
// Text
$_['text_zone_title'] = 'Zone Shipping';
$_['text_zone_error_unit'] = "Unable to convert product weights in 'kg' units";
$_['text_zone_error_weight'] = "The weight must be at least 6 kg and no more than 20 kg.";
?>
As regards setting up Geo Zones and tax classes:
Please read Bruce's document on this which you can find at:
http://www.opencart.com/contribution/ca ... egory_id/6
and follow its instructions.