/* 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(); $_RL_KEY = 'YOUR_API_KEY_HERE'; //calculate total weight $w = 0; foreach ($DATA['items'] as $i) { $w += $i['quantity']*round($i['grams']/1000*2.20462,2); } //pull from UPS $isresidential = true; if ($DATA['destination']['company_name'] !== null && $DATA['destination']['company_name'] != '') $isresidential = false; $packages = array( array('weight'=>$w, 'length'=>5, 'width'=>5, 'height'=>5, 'class'=>55.0), ); $RLoptions = array( 'DestinationLiftgate' => true, ); $rl = new RLCarriersAPI($_RL_KEY); $rl->setOrigin($DATA['origin']['city'],$DATA['origin']['province'],$DATA['origin']['postal_code'],$DATA['origin']['country']); $rl->setDestination($DATA['destination']['city'],$DATA['destination']['province'],$DATA['destination']['postal_code'],$DATA['destination']['country'],$isresidential); $rl->setOptions($RLoptions); $r = $rl->getRate($packages); if ($r) { 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 */ }