protected function _formRateRequest($purpose) { if (!Mage::getStoreConfig('shipping/shipusa/active')) { return Mage_Usa_Model_Shipping_Carrier_Fedex::_formRateRequest($purpose); } $r = $this->_rawRequest; $date = date('c'); if (!$this->getConfigData('saturday_pickup')) { if (date('w') == 6) { $date = date('c', time() + 172800); //adds 2 days if it's a Saturday. if ($this->getDebugFlag()) { Mage::helper('wsalogger/log')->postInfo('usashipping', 'Date modified to ', $date); } } else { if (date('w') == 0) { $date = date('c', time() + 86400); //adds 1 day if it's a Sunday. if ($this->getDebugFlag()) { Mage::helper('wsalogger/log')->postInfo('usashipping', 'Date modified to ', $date); } } } } if (!Mage::helper('wsacommon')->checkItems('c2hpcHBpbmcvc2hpcHVzYS9zaGlwX29uY2U=', 'aWdsb29tZQ==', 'c2hpcHBpbmcvc2hpcHVzYS9zZXJpYWw=')) { $message = base64_decode('U2VyaWFsIEtleSBJcyBOT1QgVmFsaWQgZm9yIFdlYlNob3BBcHBzIERpbWVuc2lvbmFsIFNoaXBwaW5n'); Mage::helper('wsalogger/log')->postCritical('usashipping', 'Fatal Error', $message); Mage::log($message); return Mage::getModel('shipping/rate_result'); } $fedReq['Version'] = $this->getVersionInfo(); $displayTransitTime = $this->getConfigData('display_transit_time'); if ($displayTransitTime) { $fedReq['ReturnTransitAndCommit'] = true; } else { $fedReq['ReturnTransitAndCommit'] = false; } $currentCurrencyCode = Mage::app()->getStore()->getCurrentCurrencyCode(); if ($r->getOrigCountry() == self::USA_COUNTRY_ID && $r->getDestCountry() == self::CANADA_COUNTRY_ID || $r->getOrigCountry() == self::CANADA_COUNTRY_ID && $r->getDestCountry() == self::USA_COUNTRY_ID) { $fedReq['RequestedShipment']['CustomsClearanceDetail'] = array('CustomsValue' => array('Amount' => $r->getValue(), 'Currency' => $currentCurrencyCode)); } $fedReq['RequestedShipment']['DropoffType'] = $r->getDropoffType(); // valid values REGULAR_PICKUP, REQUEST_COURIER, ... $fedReq['RequestedShipment']['ShipTimestamp'] = $date; $fedReq['RequestedShipment']['ServiceType'] = $r->getService(); // valid values STANDARD_OVERNIGHT, PRIORITY_OVERNIGHT, FEDEX_GROUND, ... $fedReq['RequestedShipment']['PackagingType'] = $r->getPackaging(); // valid values FEDEX_BOX, FEDEX_PAK, FEDEX_TUBE, YOUR_PACKAGING, ... if ($this->getConfigFlag('monetary_value')) { $currencyCode = $r->getOrigCountry() == 'CA' ? 'CAD' : 'USD'; $fedReq['RequestedShipment']['TotalInsuredValue'] = array('Amount' => $r->getValue(), 'Currency' => $currencyCode); } $fedReq['RequestedShipment']['Shipper'] = array('Address' => array('PostalCode' => $r->getOrigPostal(), 'CountryCode' => $r->getOrigCountry(), 'Residential' => $r->getDestType())); $fedReq['RequestedShipment']['Recipient'] = array('Address' => array('PostalCode' => $r->getDestPostal(), 'CountryCode' => $r->getDestCountry(), 'Residential' => $r->getDestType())); // $fedReq['RequestedShipment']['ShippingChargesPayment'] = array('PaymentType' => 'SENDER', // 'Payor' => array('AccountNumber' => '510087704', // 'CountryCode' => 'US')); $fedReq['RequestedShipment']['RateRequestTypes'] = $this->getConfigData('request_type'); $fedReq['RequestedShipment']['PackageDetail'] = 'INDIVIDUAL_PACKAGES'; // Or PACKAGE_SUMMARY $boxes = Mage::helper('shipusa')->getStdBoxes($this->_request->getAllItems(), $r->getIgnoreFreeItems()); if (is_null($boxes)) { return Mage::getModel('shipping/rate_result'); } //$fedReq['RequestedShipment']['PackageCount'] = count($boxes); Can't be caluclated here. May be modified below by split shipments. $this->_numBoxes = count($boxes); $splitIndPackage = $this->getConfigData('break_multiples'); $splitMaxWeight = $this->getConfigData('max_multiple_weight'); $maxPackageWeight = $r->getMaxPackageWeight(); $unitMeasure = $r->getUnitMeasure(); // here for historic reasons & compatibility with older magento versions if ($unitMeasure != 'KG') { $unitMeasure = 'LB'; } $handProdFee = 0; foreach ($boxes as $box) { $billableWeight = $box['weight']; $dimDetails = array(); $dimDetails['GroupPackageCount'] = 1; if ($purpose == self::RATE_REQUEST_GENERAL && $this->getConfigFlag('monetary_value')) { $dimDetails['InsuredValue'] = array('Currency' => $currencyCode, 'Amount' => $box['price']); } if ($splitIndPackage && is_numeric($splitMaxWeight) && $splitMaxWeight > $maxPackageWeight && $billableWeight < $splitMaxWeight) { for ($remainingWeight = $billableWeight; $remainingWeight > 0;) { if ($remainingWeight - $maxPackageWeight < 0) { $billableWeight = $remainingWeight; $remainingWeight = 0; } else { $billableWeight = $maxPackageWeight; $remainingWeight -= $maxPackageWeight; } if ($this->getDebugFlag()) { Mage::helper('wsalogger/log')->postInfo('usashipping', 'Adjusting Box Weight for FedEx Original Weight/New Weight', $box['weight'] . ' / ' . $billableWeight); } $dimDetails['Weight'] = array('Value' => $billableWeight, 'Units' => $unitMeasure); if ($box['length'] != 0 && $box['width'] != 0 && $box['height'] != 0) { $dimDetails['Dimensions'] = array('Length' => $box['length'], 'Width' => $box['width'], 'Height' => $box['height'], 'Units' => 'IN'); } $fedReq['RequestedShipment']['RequestedPackageLineItems'][] = $dimDetails; if (!$this->_applyHandlingPackage && $box['handling_fee'] > $handProdFee) { $handProdFee = $box['handling_fee']; } else { if ($this->_applyHandlingPackage) { $handProdFee += $box['handling_fee']; } } } } else { $dimDetails['Weight'] = array('Value' => $box['weight'], 'Units' => $unitMeasure); if ($box['length'] != 0 && $box['width'] != 0 && $box['height'] != 0) { $dimDetails['Dimensions'] = array('Length' => $box['length'], 'Width' => $box['width'], 'Height' => $box['height'], 'Units' => 'IN'); } $fedReq['RequestedShipment']['RequestedPackageLineItems'][] = $dimDetails; if (!$this->_applyHandlingPackage && $box['handling_fee'] > $handProdFee) { $handProdFee = $box['handling_fee']; } else { if ($this->_applyHandlingPackage) { $handProdFee += $box['handling_fee']; } } } } if ($purpose == self::RATE_REQUEST_SMARTPOST) { $fedReq['RequestedShipment']['ServiceType'] = self::RATE_REQUEST_SMARTPOST; $fedReq['RequestedShipment']['SmartPostDetail'] = array('Indicia' => (double) $r->getWeight() >= 1 ? 'PARCEL_SELECT' : 'PRESORTED_STANDARD', 'HubId' => $this->getConfigData('smartpost_hubid')); } if (array_key_exists('RequestedPackageLineItems', $fedReq['RequestedShipment'])) { $fedReq['RequestedShipment']['PackageCount'] = count($fedReq['RequestedShipment']['RequestedPackageLineItems']); } $this->getDebugFlag() ? Mage::helper('wsalogger/log')->postInfo('usashipping', 'Overall HandlingProduct Fee Applied', $handProdFee) : false; $fedReq['WebAuthenticationDetail'] = array('UserCredential' => array('Key' => $r->getKey(), 'Password' => $r->getPassword())); $fedReq['ClientDetail'] = array('AccountNumber' => $r->getAccount(), 'MeterNumber' => $r->getMeterNumber()); $this->_handlingProductFee = $handProdFee; return $fedReq; }