Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Excellence_Ship_Model_Carrier_Excellence extends Mage_Shipping_Model_Carrier_Abstract
- implements Mage_Shipping_Model_Carrier_Interface {
- protected $_code = 'excellence';
- public function collectRates(Mage_Shipping_Model_Rate_Request $request)
- {
- if (!Mage::getStoreConfig('carriers/'.$this->_code.'/active')) {
- return false;
- }
- include_once $_SERVER['DOCUMENT_ROOT'] . "/UPS_API/api.php";
- $to_address = array(
- "name" => ".",
- "address" => ".",
- "city" => ".",
- "state" => ".",
- "zip" => $request->getDestPostcode()
- );
- $from_address = array(
- "name" => ".",
- "address" => ".",
- "city" => ".",
- "state" => ".",
- "zip" => $request->getPostcode()
- );
- $ups_freight_obj = new UPS_Freight("not", "real", "info");
- $ups_freight_obj->set_to($to_address);
- $ups_freight_obj->set_from($from_address);
- // $rate = 0;
- // $success = 0;
- // foreach ($request->getAllItems() as $item) {
- // $weight_in_lbs = (double)$item->getWeight();
- // $from_address['zip'] = $item->getWarehouse()->getOrigin()->getData('postcode');
- // $tmp = $ups_freight_obj->get_rate($weight_in_lbs,$residential, $liftgate);
- // if($tmp) {
- // $rate += $tmp;
- // $success++;
- // }
- // }
- // if($success == count($request->getAllItems())) {
- // $show = true;
- // } else {
- // $show = false;
- // }
- $handling = Mage::getStoreConfig('carriers/'.$this->_code.'/handling');
- $result = Mage::getModel('shipping/rate_result');
- foreach($this->getAllowedMethods() as $m) {
- $rate = 0;
- foreach ($request->getAllItems() as $item) {
- $weight_in_lbs = (double)$item->getWeight();
- $from_address['zip'] = $item->getWarehouse()->getOrigin()->getData('postcode');
- if($m == "Freight") {
- $tmp = $ups_freight_obj->get_rate($weight_in_lbs,false, false);
- } else if ($m == "Freight (Lift Gate)") {
- $tmp = $ups_freight_obj->get_rate($weight_in_lbs,false, true);
- } else if ($m == "Freight (Residential)") {
- $tmp = $ups_freight_obj->get_rate($weight_in_lbs,true, false);
- } else if ($m == "Freight (Lift Gate & Residential)") {
- $tmp = $ups_freight_obj->get_rate($weight_in_lbs,true, true);
- } else {
- $tmp = 999999999;
- }
- // $tmp = $ups_freight_obj->get_rate($weight_in_lbs,$residential, $liftgate);
- if($tmp) {
- $rate += $tmp;
- }
- }
- $rate = $rate * 0.52;
- $method = Mage::getModel('shipping/rate_result_method');
- $method->setCarrier($this->_code);
- $method->setMethod($this->_code);
- $method->setCarrierTitle($this->getConfigData('title'));
- $method->setMethodTitle($m);
- $method->setPrice($rate);
- $method->setCost($rate);
- if ($rate > 0) {
- $result->append($method);
- } else {
- $error = Mage::getModel('shipping/rate_result_error');
- $error->setCarrier($this->_code);
- $error->setCarrierTitle($this->getConfigData('name'));
- $error->setErrorMessage($this->getConfigData('specificerrmsg'));
- $result->append($error);
- }
- }
- return $result;
- }
- public function getAllowedMethods()
- {
- return array(
- "freight-lift-gate-residential" => "Freight (Lift Gate & Residential)",
- "freight-residential" => "Freight (Residential)",
- "freight-lift-gate" => "Freight (Lift Gate)",
- "freight" => "Freight"
- );
- }
- public function toOptionArray() {
- $tmp = array(
- array('value' => 'ups-freight', 'label'=>Mage::helper('adminhtml')->__('UPS Freight')),
- array('value' => 'ups-freight-lift-gate', 'label'=>Mage::helper('adminhtml')->__('UPS Freight (Lift Gate)')),
- array('value' => 'ups-freight-residential', 'label'=>Mage::helper('adminhtml')->__('UPS Freight (Residential)')),
- array('value' => 'ups-freight-lift-gate-residential', 'label'=>Mage::helper('adminhtml')->__('UPS Freight (Lift Gate and Residential)'))
- );
- return $tmp;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement