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: class Mage_Customer_Helper_Address extends Mage_Core_Helper_Abstract
33: {
34: 35: 36:
37: const XML_PATH_VIV_DISABLE_AUTO_ASSIGN_DEFAULT = 'customer/create_account/viv_disable_auto_group_assign_default';
38: const XML_PATH_VIV_ON_EACH_TRANSACTION = 'customer/create_account/viv_on_each_transaction';
39: const XML_PATH_VAT_VALIDATION_ENABLED = 'customer/create_account/auto_group_assign';
40: const XML_PATH_VIV_TAX_CALCULATION_ADDRESS_TYPE = 'customer/create_account/tax_calculation_address_type';
41: const XML_PATH_VAT_FRONTEND_VISIBILITY = 'customer/create_account/vat_frontend_visibility';
42:
43: 44: 45: 46: 47:
48: protected $_attributes;
49:
50: 51: 52: 53: 54:
55: protected $_config = array();
56:
57: 58: 59: 60: 61:
62: protected $_streetLines = array();
63: protected $_formatTemplate = array();
64:
65: 66: 67:
68: public function getBookUrl()
69: {
70:
71: }
72:
73: public function getEditUrl()
74: {
75:
76: }
77:
78: public function getDeleteUrl()
79: {
80:
81: }
82:
83: public function getCreateUrl()
84: {
85:
86: }
87:
88: public function getRenderer($renderer)
89: {
90: if(is_string($renderer) && $className = Mage::getConfig()->getBlockClassName($renderer)) {
91: return new $className();
92: } else {
93: return $renderer;
94: }
95: }
96:
97: 98: 99: 100: 101: 102: 103:
104: public function getConfig($key, $store = null)
105: {
106: $websiteId = Mage::app()->getStore($store)->getWebsiteId();
107:
108: if (!isset($this->_config[$websiteId])) {
109: $this->_config[$websiteId] = Mage::getStoreConfig('customer/address', $store);
110: }
111: return isset($this->_config[$websiteId][$key]) ? (string)$this->_config[$websiteId][$key] : null;
112: }
113:
114: 115: 116: 117: 118: 119:
120: public function getStreetLines($store = null)
121: {
122: $websiteId = Mage::app()->getStore($store)->getWebsiteId();
123: if (!isset($this->_streetLines[$websiteId])) {
124: $attribute = Mage::getSingleton('eav/config')->getAttribute('customer_address', 'street');
125: $lines = (int)$attribute->getMultilineCount();
126: if($lines <= 0) {
127: $lines = 2;
128: }
129: $this->_streetLines[$websiteId] = min(4, $lines);
130: }
131:
132: return $this->_streetLines[$websiteId];
133: }
134:
135: public function getFormat($code)
136: {
137: $format = Mage::getSingleton('customer/address_config')->getFormatByCode($code);
138: return $format->getRenderer() ? $format->getRenderer()->getFormat() : '';
139: }
140:
141: 142: 143: 144: 145: 146:
147: public function canShowConfig($key)
148: {
149: return (bool)$this->getConfig($key);
150: }
151:
152: 153: 154: 155: 156:
157: public function getAttributes()
158: {
159: if (is_null($this->_attributes)) {
160: $this->_attributes = array();
161:
162: $config = Mage::getSingleton('eav/config');
163: foreach ($config->getEntityAttributeCodes('customer_address') as $attributeCode) {
164: $this->_attributes[$attributeCode] = $config->getAttribute('customer_address', $attributeCode);
165: }
166: }
167: return $this->_attributes;
168: }
169:
170: 171: 172: 173: 174: 175:
176: public function getAttributeValidationClass($attributeCode)
177: {
178:
179: $attribute = isset($this->_attributes[$attributeCode]) ? $this->_attributes[$attributeCode]
180: : Mage::getSingleton('eav/config')->getAttribute('customer_address', $attributeCode);
181: $class = $attribute ? $attribute->getFrontend()->getClass() : '';
182:
183: if (in_array($attributeCode, array('firstname', 'middlename', 'lastname', 'prefix', 'suffix', 'taxvat'))) {
184: if ($class && !$attribute->getIsVisible()) {
185: $class = '';
186: }
187:
188:
189: $customerAttribute = Mage::getSingleton('eav/config')->getAttribute('customer', $attributeCode);
190: $class .= $customerAttribute && $customerAttribute->getIsVisible()
191: ? $customerAttribute->getFrontend()->getClass() : '';
192: $class = implode(' ', array_unique(array_filter(explode(' ', $class))));
193: }
194:
195: return $class;
196: }
197:
198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212:
213: public function convertStreetLines($origStreets, $toCount)
214: {
215: $lines = array();
216: if (!empty($origStreets) && $toCount > 0) {
217: $countArgs = (int)floor(count($origStreets)/$toCount);
218: $modulo = count($origStreets) % $toCount;
219: $offset = 0;
220: $neededLinesCount = 0;
221: for ($i = 0; $i < $toCount; $i++) {
222: $offset += $neededLinesCount;
223: $neededLinesCount = $countArgs;
224: if ($modulo > 0) {
225: ++$neededLinesCount;
226: --$modulo;
227: }
228: $values = array_slice($origStreets, $offset, $neededLinesCount);
229: if (is_array($values)) {
230: $lines[] = implode(' ', $values);
231: }
232: }
233: }
234:
235: return $lines;
236: }
237:
238: 239: 240: 241: 242: 243:
244: public function isVatValidationEnabled($store = null)
245: {
246: return (bool)Mage::getStoreConfig(self::XML_PATH_VAT_VALIDATION_ENABLED, $store);
247: }
248:
249: 250: 251: 252: 253:
254: public function getDisableAutoGroupAssignDefaultValue()
255: {
256: return (bool)Mage::getStoreConfig(self::XML_PATH_VIV_DISABLE_AUTO_ASSIGN_DEFAULT);
257: }
258:
259: 260: 261: 262: 263: 264:
265: public function getValidateOnEachTransaction($store = null)
266: {
267: return (bool)Mage::getStoreConfig(self::XML_PATH_VIV_ON_EACH_TRANSACTION, $store);
268: }
269:
270: 271: 272: 273: 274: 275:
276: public function getTaxCalculationAddressType($store = null)
277: {
278: return (string)Mage::getStoreConfig(self::XML_PATH_VIV_TAX_CALCULATION_ADDRESS_TYPE, $store);
279: }
280:
281: 282: 283: 284: 285:
286: public function isVatAttributeVisible()
287: {
288: return (bool)Mage::getStoreConfig(self::XML_PATH_VAT_FRONTEND_VISIBILITY);
289: }
290: }
291: