Example #1
0
 static function getSingpostInternationalFormula($params, $controller, $shippingMethod, $shippingCountry, $shippingCity)
 {
     $formula = function ($n, $items, $cart, $controller) use($shippingCountry) {
         $weight = Helper_Cart::getTotalWeightOfItems($items);
         $zone = Helper_Cart::_getSingpostZoneFromCountry($shippingCountry);
         $fee = 0;
         if ($zone == 'zone1') {
             $steps = array(20 => 0.5, 50 => 0.7, 100 => 1.1);
             foreach ($steps as $step => $val) {
                 if ($weight <= $step) {
                     $fee = $val;
                     break;
                 }
             }
             if (!$fee) {
                 $fee = 1.1 + ceil(($weight - 100) / 100) * 1.1;
             }
         } else {
             if ($zone == 'zone2') {
                 if ($weight <= 20) {
                     $fee = 0.7;
                 }
                 if (!$fee) {
                     $fee = 0.7 + ceil(($weight - 20) / 10) * 0.25;
                 }
             } else {
                 if ($weight <= 20) {
                     $fee = 1.3;
                 }
                 if (!$fee) {
                     $fee = 1.3 + ceil(($weight - 20) / 10) * 0.35;
                 }
             }
         }
         return 2.2 + $fee;
     };
     return $formula;
 }