Jumprit's Knowledge

Jumprit's knowledge and references to share.

Australia Post International Shipping OpenCart —

1. First add countries to Geo Zone.

Optional step:
I used vqmod module to add all countries in 1 go.

2. Edit
catalog/model/shipping/auspost.php
to accept other countries, simply by creating an if (other countries than AU) statement, and it “seems” to fix the problem, and work flawlessly. We’ve only enabled “AIR” as the other service type available, and not chosen to use express, and calling the “$address[‘iso_code_2’]” variable for country ID type.

<?php
/*
* @package      MijoShop
* @copyright   2009-2013 Mijosoft LLC, mijosoft.com
* @license      GNU/GPL http://www.gnu.org/copyleft/gpl.html
* @license      GNU/GPL based on AceShop www.joomace.net
*/

// No Permission
defined(‘_JEXEC’) or die(‘Restricted access’);

class ModelShippingAusPost extends Model {
public function getQuote($address) {
$this->language->load(‘shipping/auspost’);

$query = $this->db->query(“SELECT * FROM ” . DB_PREFIX . “zone_to_geo_zone WHERE geo_zone_id = ‘” . (int)$this->config->get(‘auspost_geo_zone_id’) . “‘ AND country_id = ‘” . (int)$address[‘country_id’] . “‘ AND (zone_id = ‘” . (int)$address[‘zone_id’] . “‘ OR zone_id = ‘0’)”);

if (!$this->config->get(‘auspost_geo_zone_id’)) {
$status = true;
} elseif ($query->num_rows) {
$status = true;
} else {
$status = false;
}

$error = ”;

$quote_data = array();

//if ($address[‘iso_code_2’] == ‘AU’)
//$service = ‘standard’;
//else
//$service = ‘AIR’;

if ($status) {
$weight = $this->weight->convert($this->cart->getWeight(), $this->config->get(‘config_weight_class_id’), $this->config->get(‘auspost_weight_class_id’));

if ($this->config->get(‘auspost_standard’) && $address[‘iso_code_2’] == ‘AU’) {
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, ‘http://drc.edeliver.com.au/ratecalc.asp?pickup_postcode=’ . urlencode($this->config->get(‘auspost_postcode’)) . ‘&destination_postcode=’ . urlencode($address[‘postcode’]) . ‘&height=70&width=70&length=70&country=AU&service_type=standard&quantity=1&weight=’ . urlencode($weight));

curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

$response = curl_exec($curl);

curl_close($curl);

if ($response) {
$response_info = array();

$parts = explode(“\n”, trim($response));

foreach ($parts as $part) {
list($key, $value) = explode(‘=’, $part);

$response_info[$key] = $value;
}

if ($response_info[‘err_msg’] != ‘OK’) {
$error = $response_info[‘err_msg’];
} else {
$title = $this->language->get(‘text_standard’);

if ($this->config->get(‘auspost_display_time’)) {
$title .= ‘ (‘ . $response_info[‘days’] . ‘ ‘ . $this->language->get(‘text_eta’) . ‘)’;
}

$quote_data[‘standard’] = array(
‘code’         => ‘auspost.standard’,
‘title’        => $title,
‘cost’         => $this->currency->convert($response_info[‘charge’], ‘AUD’, $this->config->get(‘config_currency’)),
‘tax_class_id’ => $this->config->get(‘auspost_tax_class_id’),
‘text’         => $this->currency->format($this->tax->calculate($this->currency->convert($response_info[‘charge’], ‘AUD’, $this->currency->getCode()), $this->config->get(‘auspost_tax_class_id’), $this->config->get(‘config_tax’)), $this->currency->getCode(), 1.0000000)
);
}
}
}

if ($address[‘iso_code_2’] != ‘AU’)
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, ‘http://drc.edeliver.com.au/ratecalc.asp?pickup_postcode=’ . urlencode($this->config->get(‘auspost_postcode’)) . ‘&destination_postcode=’ . urlencode($address[‘postcode’]) . ‘&height=70&width=70&length=70&country=’.$address[‘iso_code_2′].’&service_type=AIR&quantity=1&weight=’ . urlencode($weight));

curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

$response = curl_exec($curl);

curl_close($curl);

if ($response) {
$response_info = array();

$parts = explode(“\n”, trim($response));

foreach ($parts as $part) {
list($key, $value) = explode(‘=’, $part);

$response_info[$key] = $value;
}

if ($response_info[‘err_msg’] != ‘OK’) {
$error = $response_info[‘err_msg’];
} else {
$title = $this->language->get(‘text_standard’);

if ($this->config->get(‘auspost_display_time’)) {
$title .= ‘ (‘ . $response_info[‘days’] . ‘ ‘ . $this->language->get(‘text_eta’) . ‘)’;
}

$quote_data[‘standard’] = array(
‘code’         => ‘auspost.standard’,
‘title’        => $title,
‘cost’         => $this->currency->convert($response_info[‘charge’], ‘AUD’, $this->config->get(‘config_currency’)),
‘tax_class_id’ => $this->config->get(‘auspost_tax_class_id’),
‘text’         => $this->currency->format($this->tax->calculate($this->currency->convert($response_info[‘charge’], ‘AUD’, $this->currency->getCode()), $this->config->get(‘auspost_tax_class_id’), $this->config->get(‘config_tax’)), $this->currency->getCode(), 1.0000000)
);
}
}
}

if ($this->config->get(‘auspost_express’) && $address[‘iso_code_2’] == ‘AU’) {
$curl = curl_init();

curl_setopt($curl, CURLOPT_URL, ‘http://drc.edeliver.com.au/ratecalc.asp?pickup_postcode=’ . urlencode($this->config->get(‘auspost_postcode’)) . ‘&destination_postcode=’ . urlencode($address[‘postcode’]) . ‘&height=70&width=70&length=70&country=AU&service_type=express&quantity=1&weight=’ . urlencode($weight));
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

$response = curl_exec($curl);

curl_close($curl);

if ($response) {
$response_info = array();

$parts = explode(“\n”, trim($response));

foreach ($parts as $part) {
list($key, $value) = explode(‘=’, $part);

$response_info[$key] = $value;
}

if ($response_info[‘err_msg’] != ‘OK’) {
$error = $response_info[‘err_msg’];
} else {
$title = $this->language->get(‘text_express’);

if ($this->config->get(‘auspost_display_time’)) {
$title .= ‘ (‘ . $response_info[‘days’] . ‘ ‘ . $this->language->get(‘text_eta’) . ‘)’;
}

$quote_data[‘express’] = array(
‘code’         => ‘auspost.express’,
‘title’        => $title,
‘cost’         => $this->currency->convert($response_info[‘charge’], ‘AUD’, $this->config->get(‘config_currency’)),
‘tax_class_id’ => $this->config->get(‘auspost_tax_class_id’),
‘text’         => $this->currency->format($this->tax->calculate($this->currency->convert($response_info[‘charge’], ‘AUD’, $this->currency->getCode()), $this->config->get(‘auspost_tax_class_id’), $this->config->get(‘config_tax’)), $this->currency->getCode(), 1.0000000)
);
}
}
}
}

$method_data = array();

if ($quote_data) {
$method_data = array(
‘code’       => ‘auspost’,
‘title’      => $this->language->get(‘text_title’),
‘quote’      => $quote_data,
‘sort_order’ => $this->config->get(‘auspost_sort_order’),
‘error’      => $error
);
}

return $method_data;
}
}
?>

3. Activate the newly created Geo Zone on step 1 in the Module>Shipping>Australia Post

Original post: http://forum.opencart.com/viewtopic.php?f=114&t=123252


Categorised as: Opencart



Leave a Reply