Ejemplo n.º 1
0
 public function getFedexRates($id_zone, $is_cart, $cart, $product_weight, $dest_zip, $dest_state, $dest_country, $currency, $product, $id_product_attribute, $qty)
 {
     $rates = array();
     if (file_exists(dirname(__FILE__) . '/../../fedex/classes/RateAvailableServices.php')) {
         include_once dirname(__FILE__) . '/../../fedex/fedex.php';
         include_once dirname(__FILE__) . '/../../fedex/classes/RateAvailableServices.php';
         $fedex = new Fedex();
         if ($fedex->active) {
             // Get handling cost (once)
             $handling = Configuration::get('PS_SHIPPING_HANDLING');
             $carriers = $fedex->getCarriers($id_zone, $cart, $is_cart, $product);
             foreach ($carriers as $carrier) {
                 //check if Fedex module is new or old
                 if (get_parent_class($fedex) == 'PrestoChangeoCarrierModule') {
                     $fedexRate = new FedexRate();
                     $amount = $fedexRate->getRate($carrier['id_carrier'], $carrier['id_zone'], $is_cart != '' ? $cart->getTotalWeight() : max($product_weight, 0.001), $dest_zip, $dest_state, $dest_country, "", $is_cart != '' ? 0 : $product->getPrice(true, $id_product_attribute, 6, NULL, false, true, $qty), $is_cart != '' ? 0 : $product->id, $is_cart != '' ? 0 : $id_product_attribute, $qty);
                 } else {
                     $amount = getFedexRate($carrier['id_carrier'], $carrier['id_zone'], $is_cart != '' ? $cart->getTotalWeight() : max($product_weight, 0.001), $dest_zip, $dest_state, $dest_country, $is_cart != '' ? 0 : $product->getPrice(true, $id_product_attribute, 6, NULL, false, true, $qty), $is_cart != '' ? 0 : $product->id, $is_cart != '' ? 0 : $id_product_attribute, $qty);
                 }
                 // Add product spercific cost + handling fee
                 if ($amount > 0) {
                     $amount += $this->getExtraShippingCost($carrier, $handling, $is_cart != '' ? $cart->getProducts() : array(), $product, $qty);
                 }
                 // Apply shipping tax if needed
                 if (!Tax::excludeTaxeOption()) {
                     $carrierTax = Tax::getCarrierTaxRate($carrier['id_carrier']);
                 }
                 if (isset($carrierTax) && $amount !== false) {
                     $amount *= 1 + $carrierTax / 100;
                 }
                 $amount = $amount === false ? -1 : Tools::convertPrice($amount, $currency);
                 if ($amount > 0) {
                     $rates[$carrier['name']] = array(Tools::displayPrice($amount, $currency, false), $carrier['id_carrier']);
                 } elseif ($amount !== false && $amount == 0) {
                     $rates[$carrier['name']] = array($fedex->l('Free!'), $carrier['id_carrier']);
                 }
             }
         }
     }
     return $rates;
 }