Advertisement
Guest User

Model/Excellence.php

a guest
Jul 2nd, 2012
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.92 KB | None | 0 0
  1. <?php
  2. class Excellence_Ship_Model_Carrier_Excellence extends Mage_Shipping_Model_Carrier_Abstract
  3. implements Mage_Shipping_Model_Carrier_Interface {
  4.     protected $_code = 'excellence';
  5.  
  6.     public function collectRates(Mage_Shipping_Model_Rate_Request $request)
  7.     {
  8.         if (!Mage::getStoreConfig('carriers/'.$this->_code.'/active')) {
  9.             return false;
  10.         }
  11.        
  12.         include_once $_SERVER['DOCUMENT_ROOT'] . "/UPS_API/api.php";
  13.         $to_address = array(
  14.             "name" => ".",
  15.             "address" => ".",
  16.             "city" => ".",
  17.             "state" => ".",
  18.             "zip" => $request->getDestPostcode()
  19.         );
  20.         $from_address = array(
  21.             "name" => ".",
  22.             "address" => ".",
  23.             "city" => ".",
  24.             "state" => ".",
  25.             "zip" => $request->getPostcode()
  26.         );
  27.         $ups_freight_obj = new UPS_Freight("not", "real", "info");
  28.         $ups_freight_obj->set_to($to_address);
  29.         $ups_freight_obj->set_from($from_address);
  30.  
  31.         // $rate = 0;
  32.         // $success = 0;
  33.  
  34.         // foreach ($request->getAllItems() as $item) {
  35.         //  $weight_in_lbs = (double)$item->getWeight();
  36.         //  $from_address['zip'] = $item->getWarehouse()->getOrigin()->getData('postcode');
  37.         //  $tmp = $ups_freight_obj->get_rate($weight_in_lbs,$residential, $liftgate);
  38.         //  if($tmp) {
  39.         //      $rate += $tmp;
  40.         //      $success++;
  41.         //  }
  42.         // }
  43.        
  44.         // if($success == count($request->getAllItems())) {
  45.         //  $show = true;
  46.         // } else {
  47.         //      $show = false;
  48.         // }
  49.        
  50.        
  51.  
  52.         $handling = Mage::getStoreConfig('carriers/'.$this->_code.'/handling');
  53.         $result = Mage::getModel('shipping/rate_result');
  54.         foreach($this->getAllowedMethods() as $m) {
  55.  
  56.                 $rate = 0;
  57.                
  58.                 foreach ($request->getAllItems() as $item) {
  59.                     $weight_in_lbs = (double)$item->getWeight();
  60.                     $from_address['zip'] = $item->getWarehouse()->getOrigin()->getData('postcode');
  61.  
  62.                     if($m == "Freight") {
  63.                         $tmp = $ups_freight_obj->get_rate($weight_in_lbs,false, false);
  64.                     } else if ($m == "Freight (Lift Gate)") {
  65.                         $tmp = $ups_freight_obj->get_rate($weight_in_lbs,false, true);
  66.                     } else if ($m == "Freight (Residential)") {
  67.                         $tmp = $ups_freight_obj->get_rate($weight_in_lbs,true, false);
  68.                     } else if ($m == "Freight (Lift Gate & Residential)") {
  69.                         $tmp = $ups_freight_obj->get_rate($weight_in_lbs,true, true);
  70.                     } else {
  71.                         $tmp = 999999999;
  72.                     }
  73.                     // $tmp = $ups_freight_obj->get_rate($weight_in_lbs,$residential, $liftgate);
  74.                     if($tmp) {
  75.                         $rate += $tmp;
  76.                     }
  77.                 }
  78.  
  79.                 $rate = $rate * 0.52;
  80.  
  81.                 $method = Mage::getModel('shipping/rate_result_method');
  82.                 $method->setCarrier($this->_code);
  83.                 $method->setMethod($this->_code);
  84.                 $method->setCarrierTitle($this->getConfigData('title'));
  85.                 $method->setMethodTitle($m);
  86.                 $method->setPrice($rate);
  87.                 $method->setCost($rate);
  88.                 if ($rate > 0) {
  89.                     $result->append($method);
  90.                 } else {
  91.                     $error = Mage::getModel('shipping/rate_result_error');
  92.                     $error->setCarrier($this->_code);
  93.                     $error->setCarrierTitle($this->getConfigData('name'));
  94.                     $error->setErrorMessage($this->getConfigData('specificerrmsg'));
  95.                     $result->append($error);
  96.                 }
  97.             }
  98.         return $result;
  99.     }
  100.     public function getAllowedMethods()
  101.     {
  102.         return array(
  103.             "freight-lift-gate-residential" => "Freight (Lift Gate & Residential)",
  104.             "freight-residential" => "Freight (Residential)",
  105.             "freight-lift-gate" => "Freight (Lift Gate)",
  106.             "freight" => "Freight"
  107.         );
  108.     }
  109.     public function toOptionArray() {
  110.          
  111.          $tmp = array(
  112.             array('value' => 'ups-freight', 'label'=>Mage::helper('adminhtml')->__('UPS Freight')),
  113.             array('value' => 'ups-freight-lift-gate', 'label'=>Mage::helper('adminhtml')->__('UPS Freight (Lift Gate)')),
  114.             array('value' => 'ups-freight-residential', 'label'=>Mage::helper('adminhtml')->__('UPS Freight (Residential)')),
  115.             array('value' => 'ups-freight-lift-gate-residential', 'label'=>Mage::helper('adminhtml')->__('UPS Freight (Lift Gate and Residential)'))
  116.         );
  117.  
  118.          return $tmp;
  119.     }
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement