/* 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(); $_TNT_LOGIN = ''; $_TNT_PASSWORD = ''; $_TNT_ACCOUNTNUMBER = ''; //calculate total weight $w = 0; foreach ($DATA['items'] as $i) { $w += $i['quantity']*$i['grams']/1000; } $packages = array( array('weight'=>$w, 'length'=>18, 'width'=>12, 'height'=>4), ); $TNT = new TNTAPI($_TNT_LOGIN,$_TNT_PASSWORD,$_TNT_ACCOUNTNUMBER); $TNT->setOrigin('',$DATA['origin']['city'],$DATA['origin']['province'],$DATA['origin']['postal_code'],''); $TNT->setDestination('',$DATA['destination']['city'],$DATA['destination']['province'],$DATA['destination']['postal_code'],'',''); $r = $TNT->getRate($packages); if ($r) { foreach ($r as $_r) { $_RATES[] = array( "service_name" => $_r['name'], "service_code" => $_r['name'], "total_price" => $_r['amount']*100, //in cents "currency" => "AUD", ); } } return $_RATES; /* do not edit below this line */ }