/* This macro will be parsed as PHP code (see http://www.php.net) The calculateshipping function is called every time a shipping calculation request is made by Shopify. The function must return an array of available shipping options, otherwise no shipping options will be returned to your customers. */ function calculateshipping($DATA) { /* do not edit above this line */ $_RATES = array(); //uses Australia Post's Digital Services API $startrack_account = ''; $startrack_api_key = ''; $startrack_api_password = ''; $w = 0; foreach ($DATA['items'] as $i) { $w += $i['quantity']*($i['grams']/1000); } //dimensions to 1 decimal place only $packages = array( array('weight'=>$w, 'length'=>12, 'width'=>8.7, 'height'=>6), ); //postcode and city MUST be valid in order for rates to return $startrack = new AustPostEParcelAPI($startrack_account,$startrack_api_key,$startrack_api_password); $startrack->setOrigin($DATA['origin']['province'],$DATA['origin']['postal_code'],$DATA['origin']['country'],$DATA['origin']['city']); $startrack->setDestination($DATA['destination']['province'],$DATA['destination']['postal_code'],$DATA['destination']['country'],$DATA['destination']['city']); $r = $startrack->getRate($packages); if ($r) { foreach ($r as $_r) { $_RATES[] = array( "service_name" => $_r['name'], "service_code" => $_r['code'], "total_price" => $_r['amount']*100, "currency" => "AUD", ); } } return $_RATES; /* do not edit below this line */ }