php - Magento Shipping Method Loading speed -
in e-commerce site, have configured fedex shipping shipping api. in methods, i've choose 1 allow method "international economy". though have 1 method allow, checking logs of fedex, seems api query methods , return result. because of this, took @ least minute return shipping rates.
is normal magento? or there anyway speed query speed or there modification or hack can make query allow method?
kindly advise.
thank you.
i have seen few questions fedex magento , speed recently.
i not convinced fedex request causing delay, figure out (and answer questions):-
the code sends out requests is:
//file: app/code/core/mage/usa/modell/shipping/carrier/fedex.php //class: mage_usa_model_shipping_carrier_fedex //function: _getquotes() protected function _getquotes() { $this->_result = mage::getmodel('shipping/rate_result'); // make separate request smart post method $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); } } // make general request methods $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; }
so answer 1: yes, magento collect methods irrespective of methods allowed via admin. in 2 requests, 1 smartpost , 1 other methods.
answer 2: if want ask single service type seeking set, example,
$ratesrequest['requestedshipment']['servicetype'] = 'international_economy';
for testing*, copy file from
//file: app/code/core/mage/usa/modell/shipping/carrier/fedex.php
to
//file: app/code/local/mage/usa/modell/shipping/carrier/fedex.php
and change code to:
//file: app/code/local/mage/usa/modell/shipping/carrier/fedex.php //class: mage_usa_model_shipping_carrier_fedex //function: _getquotes() protected function _getquotes() { $this->_result = mage::getmodel('shipping/rate_result'); // make separate request smart post method $allowedmethods = explode(',', $this->getconfigdata('allowed_methods')); //a little test code me; can omit //echo(nl2br(print_r($allowedmethods,true))); //exit(); /* array<br /> (<br /> [0] => europe_first_international_priority<br /> [1] => fedex_1_day_freight<br /> [2] => fedex_2_day_freight<br /> [3] => fedex_2_day<br /> [4] => fedex_2_day_am<br /> [5] => fedex_3_day_freight<br /> [6] => fedex_express_saver<br /> [7] => fedex_ground<br /> [8] => first_overnight<br /> [9] => ground_home_delivery<br /> [10] => international_economy<br /> [11] => international_economy_freight<br /> [12] => international_first<br /> [13] => international_ground<br /> [14] => international_priority<br /> [15] => international_priority_freight<br /> [16] => priority_overnight<br /> [17] => smart_post<br /> [18] => standard_overnight<br /> [19] => fedex_freight<br /> [20] => fedex_national_freight<br /> )<br /> */ //this new bit (non core) if(count($allowedmethods)==1){ //then there 1 method use $response = $this->_doratesrequest($allowedmethods[0]); $preparedsinglerate = $this->_preparerateresponse($response); if (!$preparedsinglerate->geterror() || ($this->_result->geterror() && $preparedsinglerate->geterror())) { $this->_result->append($preparedsinglerate); } }else{ //revert default treatment: 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); } } // make general request methods $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; }
and edit end of function _formraterequest
in same file cope specific rate request purpose:
//file: app/code/local/mage/usa/modell/shipping/carrier/fedex.php //class: mage_usa_model_shipping_carrier_fedex //function: 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 { //this new bit (non core) $ratesrequest['requestedshipment']['requestedpackagelineitems'][0]['insuredvalue'] = array( 'amount' => $r->getvalue(), 'currency' => $this->getcurrencycode() ); $ratesrequest['requestedshipment']['servicetype'] = $purpose; } return $ratesrequest; }//end function _formraterequest
that should fetch rate want. but might not solve speed issues.
you can run timing tests adding timers , logging (to var/log/shipping_fedex.log
) this:
//file: app/code/local/mage/usa/modell/shipping/carrier/fedex.php //class: mage_usa_model_shipping_carrier_fedex //function: protected function _getquotes() { $this->_result = mage::getmodel('shipping/rate_result'); // make separate request smart post method $allowedmethods = explode(',', $this->getconfigdata('allowed_methods')); //this new bit (non core) if(count($allowedmethods)==1){ //then there 1 method use $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{ //revert default treatment: $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'); // make general request methods $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 methods in '.$time.' seconds'); } return $this->_result; }
i'm hitting fedex sandbox worth record these timings in log file:
//file: var/log/shipping_fedex.log polled smart_post in 1.1807501316071 seconds polled smart_post in 1.3307409286499 seconds polled methods in 0.78275394439697 seconds //returns warning 556 [message] => there no valid services available. polled methods in 2.0135650634766 seconds //returns 8 valid shipping methods polled methods in 1.3563330173492 seconds //returns international_economy , international_priority //single service request results 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
so load files timers , let know get.
*for production of course customary here 'make own module extends class mage_usa_model_shipping_carrier_fedex
'.
**notes : had force currency code sent in request 'usd
' fedex return shipping rates service types other smart_post, if testing thing out that.
Comments
Post a Comment