00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 class Mage_Shipping_Model_Config extends Varien_Object
00029 {
00030 protected static $_carriers;
00031
00032
00033
00034
00035
00036
00037
00038 public function getActiveCarriers($store=null)
00039 {
00040 $carriers = array();
00041 $config = Mage::getStoreConfig('carriers', $store);
00042 foreach ($config as $code => $carrierConfig) {
00043 if (Mage::getStoreConfigFlag('carriers/'.$code.'/active', $store)) {
00044 $carriers[$code] = $this->_getCarrier($code, $carrierConfig, $store);
00045 }
00046 }
00047 return $carriers;
00048 }
00049
00050
00051
00052
00053
00054
00055
00056 public function getAllCarriers($store=null)
00057 {
00058 $carriers = array();
00059 $config = Mage::getStoreConfig('carriers', $store);
00060 foreach ($config as $code => $carrierConfig) {
00061 $carriers[$code] = $this->_getCarrier($code, $carrierConfig, $store);
00062 }
00063 return $carriers;
00064 }
00065
00066
00067
00068
00069
00070
00071
00072
00073 public function getCarrierInstance($carrierCode, $store=null)
00074 {
00075 $carrierConfig = Mage::getStoreConfig('carriers/'.$carrierCode, $store);
00076 if (!empty($carrierConfig)) {
00077 return $this->_getCarrier($carrierCode, $carrierConfig, $store);
00078 }
00079 return false;
00080 }
00081
00082 protected function _getCarrier($code, $config, $store=null)
00083 {
00084
00085
00086
00087
00088
00089 if (!isset($config['model'])) {
00090 throw Mage::exception('Mage_Shipping', 'Invalid model for shipping method: '.$code);
00091 }
00092 $modelName = $config['model'];
00093 $carrier = Mage::getModel($modelName);
00094 $carrier->setId($code)->setStore($store);
00095 self::$_carriers[$code] = $carrier;
00096 return self::$_carriers[$code];
00097 }
00098 }