Mage_Shipping_Model_Rate_Result Class Reference

List of all members.

Public Member Functions

 reset ()
 setError ($error)
 getError ()
 append ($result)
 getAllRates ()
 getRateById ($id)
 getRatesByCarrier ($carrier)
 asArray ()
 getCheapestRate ()
 sortRatesByPrice ()

Protected Attributes

 $_rates = array()
 $_error = null


Detailed Description

Definition at line 28 of file Result.php.


Member Function Documentation

append ( result  ) 

Add a rate to the result

Parameters:
Mage_Shipping_Model_Rate_Result_Abstract|Mage_Shipping_Model_Rate_Result $result

Definition at line 57 of file Result.php.

00058     {
00059         if ($result instanceof Mage_Shipping_Model_Rate_Result_Abstract) {
00060             $this->_rates[] = $result;
00061         }
00062         elseif ($result instanceof Mage_Shipping_Model_Rate_Result) {
00063             $rates = $result->getAllRates();
00064             foreach ($rates as $rate) {
00065                 $this->append($rate);
00066             }
00067         }
00068         return $this;
00069     }

asArray (  ) 

Definition at line 103 of file Result.php.

00104     {
00105         $currencyFilter = Mage::app()->getStore()->getPriceFilter();
00106         $rates = array();
00107         $allRates = $this->getAllRates();
00108         foreach ($allRates as $rate) {
00109             $rates[$rate->getCarrier()]['title'] = $rate->getCarrierTitle();
00110             $rates[$rate->getCarrier()]['methods'][$rate->getMethod()] = array(
00111                 'title'=>$rate->getMethodTitle(),
00112                 'price'=>$rate->getPrice(),
00113                 'price_formatted'=>$currencyFilter->filter($rate->getPrice()),
00114             );
00115         }
00116         return $rates;
00117     }

getAllRates (  ) 

Return all quotes in the result

Definition at line 74 of file Result.php.

00075     {
00076         return $this->_rates;
00077     }

getCheapestRate (  ) 

Definition at line 119 of file Result.php.

00120     {
00121         $cheapest = null;
00122         $minPrice = 100000;
00123         foreach ($this->getAllRates() as $rate) {
00124             if (is_numeric($rate->getPrice()) && $rate->getPrice()<$minPrice) {
00125                 $cheapest = $rate;
00126                 $minPrice = $rate->getPrice();
00127             }
00128         }
00129         return $cheapest;
00130     }

getError (  ) 

Definition at line 47 of file Result.php.

00048     {
00049         return $this->_error;
00050     }

getRateById ( id  ) 

Return rate by id in array

Definition at line 82 of file Result.php.

00083     {
00084         return isset($this->_rates[$id]) ? $this->_rates[$id] : null;
00085     }

getRatesByCarrier ( carrier  ) 

Return quotes for specified type

Parameters:
string $type

Definition at line 92 of file Result.php.

00093     {
00094         $result = array();
00095         foreach ($this->_rates as $rate) {
00096             if ($rate->getCarrier()===$carrier) {
00097                 $result[] = $rate;
00098             }
00099         }
00100         return $result;
00101     }

reset (  ) 

Reset result

Definition at line 36 of file Result.php.

00037     {
00038         $this->_rates = array();
00039         return $this;
00040     }

setError ( error  ) 

Definition at line 42 of file Result.php.

00043     {
00044         $this->_error = $error;
00045     }

sortRatesByPrice (  ) 

Sort rates by price from min to max

Returns:
Mage_Shipping_Model_Rate_Result

Definition at line 137 of file Result.php.

00138     {
00139         if (!is_array($this->_rates) || !count($this->_rates)) {
00140             return $this;
00141         }
00142         /* @var $rate Mage_Shipping_Model_Rate_Result_Method */
00143         foreach ($this->_rates as $i => $rate) {
00144             $tmp[$i] = $rate->getPrice();
00145         }
00146 
00147         natsort($tmp);
00148 
00149         foreach ($tmp as $i => $price) {
00150             $result[] = $this->_rates[$i];
00151         }
00152 
00153         $this->reset();
00154         $this->_rates = $result;
00155         return $this;
00156     }


Member Data Documentation

$_error = null [protected]

Definition at line 31 of file Result.php.

$_rates = array() [protected]

Definition at line 30 of file Result.php.


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:24:51 2009 for Magento by  doxygen 1.5.8