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
00029
00030
00031
00032
00033
00034
00035
00036 class Mage_Payment_Model_Config
00037 {
00038 protected static $_methods;
00039
00040
00041
00042
00043
00044
00045
00046 public function getActiveMethods($store=null)
00047 {
00048 $methods = array();
00049 $config = Mage::getStoreConfig('payment', $store);
00050 foreach ($config as $code => $methodConfig) {
00051 if (Mage::getStoreConfigFlag('payment/'.$code.'/active', $store)) {
00052 $methods[$code] = $this->_getMethod($code, $methodConfig);
00053 }
00054 }
00055 return $methods;
00056 }
00057
00058
00059
00060
00061
00062
00063
00064 public function getAllMethods($store=null)
00065 {
00066 $methods = array();
00067 $config = Mage::getStoreConfig('payment', $store);
00068 foreach ($config as $code => $methodConfig) {
00069 $methods[$code] = $this->_getMethod($code, $methodConfig);
00070 }
00071 return $methods;
00072 }
00073
00074 protected function _getMethod($code, $config, $store=null)
00075 {
00076 if (isset(self::$_methods[$code])) {
00077 return self::$_methods[$code];
00078 }
00079 $modelName = $config['model'];
00080 $method = Mage::getModel($modelName);
00081 $method->setId($code)->setStore($store);
00082 self::$_methods[$code] = $method;
00083 return self::$_methods[$code];
00084 }
00085
00086
00087
00088
00089
00090
00091 public function getCcTypes()
00092 {
00093 $_types = Mage::getConfig()->getNode('global/payment/cc/types')->asArray();
00094
00095 uasort($_types, array('Mage_Payment_Model_Config', 'compareCcTypes'));
00096
00097 $types = array();
00098 foreach ($_types as $data) {
00099 $types[$data['code']] = $data['name'];
00100 }
00101 return $types;
00102 }
00103
00104
00105
00106
00107
00108
00109 public function getMonths()
00110 {
00111 $data = Mage::app()->getLocale()->getTranslationList('month');
00112 foreach ($data as $key => $value) {
00113 $monthNum = ($key < 10) ? '0'.$key : $key;
00114 $data[$key] = $monthNum . ' - ' . $value;
00115 }
00116 return $data;
00117 }
00118
00119
00120
00121
00122
00123
00124 public function getYears()
00125 {
00126 $years = array();
00127 $first = date("Y");
00128
00129 for ($index=0; $index <= 10; $index++) {
00130 $year = $first + $index;
00131 $years[$year] = $year;
00132 }
00133 return $years;
00134 }
00135
00136
00137
00138
00139
00140
00141
00142
00143 static function compareCcTypes($a, $b)
00144 {
00145 if (!isset($a['order'])) {
00146 $a['order'] = 0;
00147 }
00148
00149 if (!isset($b['order'])) {
00150 $b['order'] = 0;
00151 }
00152
00153 if ($a['order'] == $b['order']) {
00154 return 0;
00155 } else if ($a['order'] > $b['order']) {
00156 return 1;
00157 } else {
00158 return -1;
00159 }
00160
00161 }
00162 }