/* 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(); $_ARAMEX_PIN = ''; //account pin $_ARAMEX_ENTITY = ''; //entity code $_ARAMEX_ACCOUNT = ''; //account number $_ARAMEX_ACCOUNT_CC = ''; //acount country code $_ARAMEX_USER = ''; //account email $_ARAMEX_PASS = ''; //account password $w = 0; foreach ($DATA['items'] as $i) { $w += $i['quantity']*$i['grams']/1000; } //use CM and KG $packages = array( array('length'=>100, 'width'=>20, 'height'=>20, 'weight'=>$w), ); $AR = new AramexAPI($_ARAMEX_USER,$_ARAMEX_PASS,$_ARAMEX_PIN,$_ARAMEX_ENTITY,$_ARAMEX_ACCOUNT,$_ARAMEX_ACCOUNT_CC); $AR->setOrigin($DATA['origin']['address1'],$DATA['origin']['address2'],$DATA['origin']['address3'],$DATA['origin']['city'],$DATA['origin']['province'],$DATA['origin']['postal_code'],$DATA['origin']['country']); $AR->setDestination($DATA['destination']['address1'],$DATA['destination']['address2'],$DATA['destination']['address3'],$DATA['destination']['city'],$DATA['destination']['province'],$DATA['destination']['postal_code'],$DATA['destination']['country']); $r = $AR->getRate($packages,'METRIC','PPX',$e); if ($r) { foreach ($r as $_r) { $_RATES[] = array( "service_name" => $_r['name'], "service_code" => $_r['code'], "total_price" => $_r['amount']*100, //in cents "currency" => $_r['currency'], ); } } return $_RATES; /* do not edit below this line */ }