Example #1
0
 public function setRequest(Mage_Shipping_Model_Rate_Request $request)
 {
     $this->_request = $request;
     $r = new Varien_Object();
     $r->setStoreId($request->getStoreId());
     if ($request->getLimitMethod()) {
         $r->setService($request->getLimitMethod());
     }
     if ($request->getDhlId()) {
         $id = $request->getDhlId();
     } else {
         $id = $this->getConfigData('id');
     }
     $r->setId($id);
     if ($request->getDhlPassword()) {
         $password = $request->getDhlPassword();
     } else {
         $password = $this->getConfigData('password');
     }
     $r->setPassword($password);
     if ($request->getDhlAccount()) {
         $accountNbr = $request->getDhlAccount();
     } else {
         $accountNbr = $this->getConfigData('account');
     }
     $r->setAccountNbr($accountNbr);
     if ($request->getDhlShippingKey()) {
         $shippingKey = $request->getDhlShippingKey();
     } else {
         $shippingKey = $this->getConfigData('shipping_key');
     }
     $r->setShippingKey($shippingKey);
     if ($request->getDhlShippingIntlKey()) {
         $shippingKey = $request->getDhlShippingIntlKey();
     } else {
         $shippingKey = $this->getConfigData('shipping_intlkey');
     }
     $r->setShippingIntlKey($shippingKey);
     if ($request->getDhlShipmentType()) {
         $shipmentType = $request->getDhlShipmentType();
     } else {
         $shipmentType = $this->getConfigData('shipment_type');
     }
     $r->setShipmentType($shipmentType);
     if ($request->getDhlDutiable()) {
         $shipmentDutible = $request->getDhlDutiable();
     } else {
         $shipmentDutible = $this->getConfigData('dutiable');
     }
     $r->setDutiable($shipmentDutible);
     if ($request->getDhlDutyPaymentType()) {
         $dutypaytype = $request->getDhlDutyPaymentType();
     } else {
         $dutypaytype = $this->getConfigData('dutypaymenttype');
     }
     $r->setDutyPaymentType($dutypaytype);
     if ($request->getDhlContentDesc()) {
         $contentdesc = $request->getDhlContentDesc();
     } else {
         $contentdesc = $this->getConfigData('contentdesc');
     }
     $r->setContentDesc($contentdesc);
     if ($request->getDestPostcode()) {
         $r->setDestPostal($request->getDestPostcode());
     }
     if ($request->getOrigCountry()) {
         $origCountry = $request->getOrigCountry();
     } else {
         $origCountry = Mage::getStoreConfig('shipping/origin/country_id', $this->getStore());
     }
     $r->setOrigCountry($origCountry);
     /*
      * DHL only accepts weight as a whole number. Maximum length is 3 digits.
      */
     $weight = $this->getTotalNumOfBoxes($request->getPackageWeight());
     $shippingWeight = round(max(1, $weight), 0);
     $r->setValue(round($request->getPackageValue(), 2));
     $r->setValueWithDiscount($request->getPackageValueWithDiscount());
     $r->setDestStreet(Mage::helper('core/string')->substr($request->getDestStreet(), 0, 35));
     $r->setDestCity($request->getDestCity());
     if ($request->getDestCountryId()) {
         $destCountry = $request->getDestCountryId();
     } else {
         $destCountry = self::USA_COUNTRY_ID;
     }
     //for DHL, puero rico state for US will assume as puerto rico country
     //for puerto rico, dhl will ship as international
     if ($destCountry == self::USA_COUNTRY_ID && ($request->getDestPostcode() == '00912' || $request->getDestRegionCode() == self::PUERTORICO_COUNTRY_ID)) {
         $destCountry = self::PUERTORICO_COUNTRY_ID;
     }
     $r->setDestCountryId($destCountry);
     $r->setDestState($request->getDestRegionCode());
     $r->setWeight($shippingWeight);
     $r->setFreeMethodWeight($request->getFreeMethodWeight());
     $this->_rawRequest = $r;
     //        $methods = explode(',', $this->getConfigData('allowed_methods'));
     //
     //        $freeMethod = $this->getConfigData('free_method');
     //
     //        $internationcode = $this->getCode('international_searvice');
     //        $minOrderAmount = $this->getConfigData('cutoff_cost') ? $this->getConfigData('cutoff_cost') : 0;
     //        if ($shippingWeight>0) {
     //             $this->_rawRequest->setWeight($shippingWeight);
     //             $this->_getQuotes();
     //            foreach ($methods as $method) {
     //                if(($method==$internationcode && ($r->getDestCountryId() != self::USA_COUNTRY_ID)) ||
     //                ($method!=$internationcode && ($r->getDestCountryId() == self::USA_COUNTRY_ID)))
     //                {
     //                    $weight = $freeMethod==$method && $this->getConfigData('cutoff_cost') <= $r->getValue() ? 0 : $shippingWeight;
     //                    if ($weight>0) {
     //                        $this->_rawRequest->setWeight($weight);
     //                	    $this->_rawRequest->setService($method);
     //                        $this->_getQuotes();
     //                    } else {
     //                        $this->_dhlRates[$method] = array(
     //                            'term' => $this->getCode('service', $method),
     //                            'price_total' => 0,
     //                        );
     //                    }
     //                }
     //            }
     //        } else {
     //           $this->_errors[] = Mage::helper('usa')->__('Please enter the package weight');
     //        }
     return $this;
 }
Example #2
0
 public function process(Mage_Shipping_Model_Rate_Request $request)
 {
     $this->_request = $request;
     $r = new Varien_Object();
     if ($request->getLimitMethod()) {
         $r->setService($request->getLimitMethod());
     }
     if ($request->getDhlId()) {
         $id = $request->getDhlId();
     } else {
         $id = $this->getConfigData('id');
     }
     $r->setId($id);
     if ($request->getDhlPassword()) {
         $password = $request->getDhlPassword();
     } else {
         $password = $this->getConfigData('password');
     }
     $r->setPassword($password);
     if ($request->getDhlAccount()) {
         $accountNbr = $request->getDhlAccount();
     } else {
         $accountNbr = $this->getConfigData('account');
     }
     $r->setAccountNbr($accountNbr);
     if ($request->getDhlShippingKey()) {
         $shippingKey = $request->getDhlShippingKey();
     } else {
         $shippingKey = $this->getConfigData('shipping_key');
     }
     $r->setShippingKey($shippingKey);
     if ($request->getDhlShippingIntlKey()) {
         $shippingKey = $request->getDhlShippingIntlKey();
     } else {
         $shippingKey = $this->getConfigData('shipping_intlkey');
     }
     $r->setShippingIntlKey($shippingKey);
     if ($request->getDhlShipmentType()) {
         $shipmentType = $request->getDhlShipmentType();
     } else {
         $shipmentType = $this->getConfigData('shipment_type');
     }
     $r->setShipmentType($shipmentType);
     if ($request->getDhlDutiable()) {
         $shipmentDutible = $request->getDhlDutiable();
     } else {
         $shipmentDutible = $this->getConfigData('dutiable');
     }
     $r->setDutiable($shipmentDutible);
     if ($request->getDhlDutyPaymentType()) {
         $dutypaytype = $request->getDhlDutyPaymentType();
     } else {
         $dutypaytype = $this->getConfigData('dutypaymenttype');
     }
     $r->setDutyPaymentType($dutypaytype);
     if ($request->getDhlContentDesc()) {
         $contentdesc = $request->getDhlContentDesc();
     } else {
         $contentdesc = $this->getConfigData('contentdesc');
     }
     $r->setContentDesc($contentdesc);
     if ($request->getDestPostcode()) {
         $r->setDestPostal($request->getDestPostcode());
     }
     if ($request->getOrigCountry()) {
         $origCountry = $request->getOrigCountry();
     } else {
         $origCountry = Mage::getStoreConfig('shipping/origin/country_id', $this->getStore());
     }
     $r->setOrigCountry($origCountry);
     /*
      * DHL only accepts weight as a whole number. Maximum length is 3 digits.
      */
     $shippingWeight = round(min(1, $request->getPackageWeight()), 0);
     $freeMethodWeight = round(min(1, $request->getFreeMethodWeight()), 0);
     $r->setValue(round($request->getPackageValue(), 2));
     $r->setDestStreet(substr($request->getDestStreet(), 0, 35));
     $r->setDestCity($request->getDestCity());
     $r->setDestCountryId($request->getDestCountryId());
     $r->setDestState($request->getDestRegionCode());
     $this->_rawRequest = $r;
     $methods = explode(',', $this->getConfigData('allowed_methods'));
     $freeMethod = $this->getConfigData('free_method');
     $internationcode = $this->getCode('international_searvice');
     foreach ($methods as $method) {
         if ($method == $internationcode && $r->getDestCountryId() != self::USA_COUNTRY_ID || $method != $internationcode && $r->getDestCountryId() == self::USA_COUNTRY_ID) {
             $weight = $freeMethod == $method ? $freeMethodWeight : $shippingWeight;
             if ($weight > 0) {
                 $this->_rawRequest->setWeight($weight);
                 $this->_rawRequest->setService($method);
                 $this->_getQuotes();
             } else {
                 $this->_dhlRates[$method] = array('term' => $this->getCode('service', $method), 'price_total' => 0);
             }
         }
     }
     return $this;
 }