/* 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(); $DATA = enrichProductDetails($DATA); $countProductTypes = array(); foreach ($DATA['items'] as $i) { if (!isset($i['product_type'])) { //product type not found, default to 'other' $i['product_type'] = 'other'; } //count qty of product types if (!isset($countProductTypes[$i['product_type']])) $countProductTypes[$i['product_type']] = 0; //initialise new product type $countProductTypes[$i['product_type']] += $i['quantity']; //increment counter } $rate = 0; //contains the aggregate rate foreach ($countProductTypes as $product_type => $qty) { //assign rate as $1 for each qty for each product type $rate += 1 * $qty; } //display final rate $_RATES[] = array( "service_name" => 'Standard Shipping', "service_code" => 'STANDARD', "total_price" => $rate*100, //in cents "currency" => "USD", ); return $_RATES; /* do not edit below this line */ }