FedEx Magento .
, FedEx , ( ): -
, :
protected function _getQuotes()
{
$this->_result = Mage::getModel('shipping/rate_result');
$allowedMethods = explode(',', $this->getConfigData('allowed_methods'));
if (in_array(self::RATE_REQUEST_SMARTPOST, $allowedMethods)) {
$response = $this->_doRatesRequest(self::RATE_REQUEST_SMARTPOST);
$preparedSmartpost = $this->_prepareRateResponse($response);
if (!$preparedSmartpost->getError()) {
$this->_result->append($preparedSmartpost);
}
}
$response = $this->_doRatesRequest(self::RATE_REQUEST_GENERAL);
$preparedGeneral = $this->_prepareRateResponse($response);
if (!$preparedGeneral->getError() || ($this->_result->getError() && $preparedGeneral->getError())) {
$this->_result->append($preparedGeneral);
}
return $this->_result;
}
, 1: , Magento , admin. : SMARTPOST .
ANSWER 2: , , ,
$ratesRequest['RequestedShipment']['ServiceType'] = 'INTERNATIONAL_ECONOMY';
*
//file: app/code/core/Mage/Usa/Modell/Shipping/Carrier/Fedex.php
//file: app/code/local/Mage/Usa/Modell/Shipping/Carrier/Fedex.php
:
protected function _getQuotes()
{
$this->_result = Mage::getModel('shipping/rate_result');
$allowedMethods = explode(',', $this->getConfigData('allowed_methods'));
if(count($allowedMethods)==1){
$response = $this->_doRatesRequest($allowedMethods[0]);
$preparedSingleRate = $this->_prepareRateResponse($response);
if (!$preparedSingleRate->getError() || ($this->_result->getError() && $preparedSingleRate->getError())) {
$this->_result->append($preparedSingleRate);
}
}else{
if (in_array(self::RATE_REQUEST_SMARTPOST, $allowedMethods)) {
$response = $this->_doRatesRequest(self::RATE_REQUEST_SMARTPOST);
$preparedSmartpost = $this->_prepareRateResponse($response);
if (!$preparedSmartpost->getError()) {
$this->_result->append($preparedSmartpost);
}
}
$response = $this->_doRatesRequest(self::RATE_REQUEST_GENERAL);
$preparedGeneral = $this->_prepareRateResponse($response);
if (!$preparedGeneral->getError() || ($this->_result->getError() && $preparedGeneral->getError())) {
$this->_result->append($preparedGeneral);
}
}
return $this->_result;
}
_formRateRequest , :
protected function _formRateRequest($purpose)
{
$r = $this->_rawRequest;
if ($purpose == self::RATE_REQUEST_GENERAL) {
$ratesRequest['RequestedShipment']['RequestedPackageLineItems'][0]['InsuredValue'] = array(
'Amount' => $r->getValue(),
'Currency' => $this->getCurrencyCode()
);
} else if ($purpose == self::RATE_REQUEST_SMARTPOST) {
$ratesRequest['RequestedShipment']['ServiceType'] = self::RATE_REQUEST_SMARTPOST;
$ratesRequest['RequestedShipment']['SmartPostDetail'] = array(
'Indicia' => ((float)$r->getWeight() >= 1) ? 'PARCEL_SELECT' : 'PRESORTED_STANDARD',
'HubId' => $this->getConfigData('smartpost_hubid')
);
} else {
$ratesRequest['RequestedShipment']['RequestedPackageLineItems'][0]['InsuredValue'] = array(
'Amount' => $r->getValue(),
'Currency' => $this->getCurrencyCode()
);
$ratesRequest['RequestedShipment']['ServiceType'] = $purpose;
}
return $ratesRequest;
}
. .
, ( var/log/shipping_fedex.log) :
protected function _getQuotes()
{
$this->_result = Mage::getModel('shipping/rate_result');
$allowedMethods = explode(',', $this->getConfigData('allowed_methods'));
if(count($allowedMethods)==1){
$time_start = microtime(true);
$response = $this->_doRatesRequest($allowedMethods[0]);
$preparedSingleRate = $this->_prepareRateResponse($response);
if (!$preparedSingleRate->getError() || ($this->_result->getError() && $preparedSingleRate->getError())) {
$this->_result->append($preparedSingleRate);
}
$time_end = microtime(true);
$time = $time_end - $time_start;
$this->_debug('Polled '.$allowedMethods[0].' in '.$time.' seconds');
}else{
$time_start = microtime(true);
if (in_array(self::RATE_REQUEST_SMARTPOST, $allowedMethods)) {
$response = $this->_doRatesRequest(self::RATE_REQUEST_SMARTPOST);
$preparedSmartpost = $this->_prepareRateResponse($response);
if (!$preparedSmartpost->getError()) {
$this->_result->append($preparedSmartpost);
}
}
$time_end = microtime(true);
$time = $time_end - $time_start;
$this->_debug('Polled SMART_POST in '.$time.' seconds');
$time_start = microtime(true);
$response = $this->_doRatesRequest(self::RATE_REQUEST_GENERAL);
$preparedGeneral = $this->_prepareRateResponse($response);
if (!$preparedGeneral->getError() || ($this->_result->getError() && $preparedGeneral->getError())) {
$this->_result->append($preparedGeneral);
}
$time_end = microtime(true);
$time = $time_end - $time_start;
$this->_debug('Polled all methods in '.$time.' seconds');
}
return $this->_result;
}
FedEx, , :
Polled SMART_POST in 1.1807501316071 seconds
Polled SMART_POST in 1.3307409286499 seconds
Polled all methods in 0.78275394439697 seconds
Polled all methods in 2.0135650634766 seconds
Polled all methods in 1.3563330173492 seconds
Polled FEDEX_2_DAY in 3.1365180015564 seconds
Polled FEDEX_2_DAY in 3.6471431255341 seconds
Polled FEDEX_2_DAY in 2.1428818702698 seconds
Polled INTERNATIONAL_ECONOMY in 2.2340540885925 seconds
Polled INTERNATIONAL_ECONOMY in 2.9664940834045 seconds
, .
* , , , " , Mage_Usa_Model_Shipping_Carrier_Fedex".
** : , , "USD", FedEx , SMART_POST, , , .