1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26:
27: 28: 29: 30: 31: 32: 33: 34: 35:
36: class Mage_Payment_Model_Config
37: {
38: protected static $_methods;
39:
40: 41: 42: 43: 44: 45:
46: public function getActiveMethods($store=null)
47: {
48: $methods = array();
49: $config = Mage::getStoreConfig('payment', $store);
50: foreach ($config as $code => $methodConfig) {
51: if (Mage::getStoreConfigFlag('payment/'.$code.'/active', $store)) {
52: if (array_key_exists('model', $methodConfig)) {
53: $methodModel = Mage::getModel($methodConfig['model']);
54: if ($methodModel && $methodModel->getConfigData('active', $store)) {
55: $methods[$code] = $this->_getMethod($code, $methodConfig);
56: }
57: }
58: }
59: }
60: return $methods;
61: }
62:
63: 64: 65: 66: 67: 68:
69: public function getAllMethods($store=null)
70: {
71: $methods = array();
72: $config = Mage::getStoreConfig('payment', $store);
73: foreach ($config as $code => $methodConfig) {
74: $data = $this->_getMethod($code, $methodConfig);
75: if (false !== $data) {
76: $methods[$code] = $data;
77: }
78: }
79: return $methods;
80: }
81:
82: protected function _getMethod($code, $config, $store=null)
83: {
84: if (isset(self::$_methods[$code])) {
85: return self::$_methods[$code];
86: }
87: if (empty($config['model'])) {
88: return false;
89: }
90: $modelName = $config['model'];
91:
92: $className = Mage::getConfig()->getModelClassName($modelName);
93: if (!mageFindClassFile($className)) {
94: return false;
95: }
96:
97: $method = Mage::getModel($modelName);
98: $method->setId($code)->setStore($store);
99: self::$_methods[$code] = $method;
100: return self::$_methods[$code];
101: }
102:
103: 104: 105: 106: 107:
108: public function getCcTypes()
109: {
110: $_types = Mage::getConfig()->getNode('global/payment/cc/types')->asArray();
111:
112: uasort($_types, array('Mage_Payment_Model_Config', 'compareCcTypes'));
113:
114: $types = array();
115: foreach ($_types as $data) {
116: if (isset($data['code']) && isset($data['name'])) {
117: $types[$data['code']] = $data['name'];
118: }
119: }
120: return $types;
121: }
122:
123: 124: 125: 126: 127:
128: public function getMonths()
129: {
130: $data = Mage::app()->getLocale()->getTranslationList('month');
131: foreach ($data as $key => $value) {
132: $monthNum = ($key < 10) ? '0'.$key : $key;
133: $data[$key] = $monthNum . ' - ' . $value;
134: }
135: return $data;
136: }
137:
138: 139: 140: 141: 142:
143: public function getYears()
144: {
145: $years = array();
146: $first = date("Y");
147:
148: for ($index=0; $index <= 10; $index++) {
149: $year = $first + $index;
150: $years[$year] = $year;
151: }
152: return $years;
153: }
154:
155: 156: 157: 158: 159: 160: 161:
162: static function compareCcTypes($a, $b)
163: {
164: if (!isset($a['order'])) {
165: $a['order'] = 0;
166: }
167:
168: if (!isset($b['order'])) {
169: $b['order'] = 0;
170: }
171:
172: if ($a['order'] == $b['order']) {
173: return 0;
174: } else if ($a['order'] > $b['order']) {
175: return 1;
176: } else {
177: return -1;
178: }
179:
180: }
181: }
182: