Post by dpawweb » Thu Apr 10, 2014 4:15 pm

Hi All,

I setup our site to use Australia Post, and only had the one Geo Zone setup for Australia, so we could offer pickup locally.

We had our first international order, and I came to find out the Auspost shipping module doesn't show if your postal address is outside of Australia.

As a stop-gap measure i've:
Temporarily created Geo Zones for the top 20 countries that visit us;
Enabled Weight based pickup for all these countries, and used Auspost Rate calculator http://auspost.com.au/apps/postage-calculator.html to determine prices for each.

Question, why does the auspost shipping module not handle other countries? the rate calculator can handle them.

My colleague managed to modify this 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.

I'm wondering if there is a reason why this was never setup, or have i missed something?

if this is a fix, i'd love to see it refined and put into the core.

File:catalog/model/shipping/auspost.php

here's the code, i'd love someone else to test, comment and improve.

Code: Select all

<?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;
	}
}
?>

Newbie

Posts

Joined
Thu Apr 10, 2014 4:02 pm
Who is online

Users browsing this forum: No registered users and 12 guests