/* 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(); $_REDPACK_ID = 'YOUR REDPACK ID'; $_REDPACK_PIN = 'YOUR REDAPCK PIN'; $w = 0; foreach ($DATA['items'] as $i) { $w += $i['quantity']*$i['grams']; } $packages = array( array('weight'=>round($w/1000,1), 'length'=>10, 'width'=>10, 'height'=>10), ); $RP = new RedpackAPI($_REDPACK_ID,$_REDPACK_PIN); $RP->setOrigin(null,null,$DATA['origin']['postal_code'],null); $RP->setDestination(null,null,$DATA['destination']['postal_code'],null,false); $r = $RP->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" => "MXN", ); } } return $_RATES; /* do not edit below this line */ }