Ejemplo n.º 1
0
 /**
  * Get shipping methods.
  */
 function get_shipping_methods($cart)
 {
     // Let cart override?
     if ($cart['shipping_methods']) {
         $methods = $cart['shipping_methods'];
     } else {
         // Zip and weight required.
         if (!$cart['order']['shipping']['zip'] || !$cart['weight']) {
             return false;
         }
         // Params used to cache shipping methods.
         $params = array('country' => $cart['order']['shipping']['country'], 'zip' => $cart['order']['shipping']['zip'], 'weight' => $cart['weight'], 'discounts' => $cart['discounts']);
         // Cache for 1 hour.
         $cache_uri = "/cache/shipping_methods/" . md5(serialize($params)) . "?expire=3600";
         $methods = get($cache_uri);
         // Not cached?
         if (count($methods) == 0) {
             // Get available methods.
             $methods = get("/shipments/methods", $params);
             // Put result in cache?
             if ($methods && !$methods['errors']) {
                 put($cache_uri, $methods);
             }
         }
     }
     // Apply discounts.
     $methods = Discounts::apply_shipping($cart, $methods, $cart['discounts']);
     return $methods;
 }