/* 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(); $isresidential = true; if ($DATA['destination']['company_name'] !== null && $DATA['destination']['company_name'] != '') $isresidential = false; $w = 0; foreach($DATA['items'] as $item) { $w += $item['quantity']*$item['grams']/1000; } $w = $w*2.20462; if ($w < 1) $w = 1; $packages = array( array('weight'=>$w, 'length'=>6, 'width'=>5, 'height'=>4), ); $_FEDEX_ACCOUNT = '1111111'; $_FEDEX_METER = '22222222'; $_FEDEX_KEY = 'YOUR_KEY_HERE'; $_FEDEX_PASSWORD = 'YOUR_PASSWORD_HERE'; $fedex = new FedExAPI($_FEDEX_ACCOUNT,$_FEDEX_METER,$_FEDEX_KEY,$_FEDEX_PASSWORD); $fedex_options = array(); $fedex_options['RequestedShipment']['ServiceType'] = 'SMART_POST'; $fedex_options['RequestedShipment']['SmartPostDetail']['Indicia'] = 'PARCEL_SELECT'; $fedex_options['RequestedShipment']['SmartPostDetail']['HubId'] = '5281'; $fedex->setOrigin($DATA['origin']['province'],$DATA['origin']['postal_code'],$DATA['origin']['country']); $fedex->setDestination($DATA['destination']['province'],$DATA['destination']['postal_code'],$DATA['destination']['country'],$isresidential); $fedex->setOptions($fedex_options); $r = $fedex->getRate($packages,'IMPERIAL'); foreach ($r as $_r) { $_RATES[] = array( "service_name" => $_r['name'], "service_code" => $_r['code'], "total_price" => $_r['amount']*100, //in cents "currency" => "USD", ); } return $_RATES; /* do not edit below this line */ }