/* 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(); $defaultL = 5; $defaultW = 5; $defaultH = 5; $_YAKIT_USERNAME = 'YOUR YAKIT USERNAME'; $_YAKIT_INTEGRATION_ID = 'YOUR YAKIT INTERGRATION ID'; $packages = array(); foreach ($DATA['items'] as $i) { $i['wt'] = round($i['grams']/1000*2.20462,2); $i['origin'] = 'US'; for ($j=0; $j<$i['quantity']; $j++) { $packages[] = array( 'length'=> $defaultL, 'width' => $defaultW, 'height' => $defaultH, 'weight' => $i['wt'], 'yakit_items' => array( array( 'productId' => $i['sku'], 'displayName' => $i['name'], 'description' => $i['name'], 'countryOfOrigin' => $i['origin'], 'itemWeight' => $i['wt'], 'itemWeightUnit' => 'lb', 'value' => $i['price']/100, 'quantity' => 1, ), ), ); } } $isResidential = true; $yk = new YakitAPI($_YAKIT_USERNAME,$_YAKIT_INTEGRATION_ID); $yk->setDestination($DATA['destination']['province'],$DATA['destination']['postal_code'],$DATA['destination']['country'],$isResidential); $r = $yk->getRate($packages,'IMPERIAL'); 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 */ }