Overview

Namespaces

  • None
  • PHP

Classes

  • Eabi_DpdEE_Block_Adminhtml_Config_Form_Field_Country
  • Eabi_DpdEE_Block_Info_Payment
  • Eabi_DpdEE_Block_Invoice
  • Eabi_DpdEE_Block_Order_Courier
  • Eabi_DpdEE_Helper_Data
  • Eabi_DpdEE_Model_Api
  • Eabi_DpdEE_Model_Button_Courier
  • Eabi_DpdEE_Model_Config
  • Eabi_DpdEE_Model_Flat
  • Eabi_DpdEE_Model_Observer
  • Eabi_DpdEE_Model_Payment_Processor
  • Eabi_DpdEE_Model_Post
  • Eabi_DpdEE_Model_Source_Label_Position
  • Eabi_DpdEE_Model_Source_Service
  • Eabi_Livehandler_Adminhtml_LivehandlerController
  • Eabi_Livehandler_Adminhtml_RemoveController
  • Eabi_Livehandler_Block_Adminhtml_Config_Form_Field_Button
  • Eabi_Livehandler_Block_Adminhtml_Config_Form_Field_Remove
  • Eabi_Livehandler_Block_Email
  • Eabi_LiveHandler_Block_Footer
  • Eabi_Livehandler_Helper_Data
  • Eabi_Livehandler_Helper_Keypair
  • Eabi_Livehandler_IndexController
  • Eabi_Livehandler_Model_Abstract
  • Eabi_Livehandler_Model_Action_Abstract
  • Eabi_Livehandler_Model_Action_Postoffice_Print
  • Eabi_Livehandler_Model_Action_Postoffice_Send
  • Eabi_Livehandler_Model_Adminhtml_Gridmanager
  • Eabi_Livehandler_Model_Directory_Collection
  • Eabi_Livehandler_Model_Entry
  • Eabi_Livehandler_Model_File_Object
  • Eabi_Livehandler_Model_Mysql4_Entry
  • Eabi_Livehandler_Model_Mysql4_Entry_Collection
  • Eabi_Livehandler_Model_Ordergrid
  • Eabi_Livehandler_Model_System_Config_Backend_Button
  • Eabi_Postoffice_Adminhtml_PostofficeController
  • Eabi_Postoffice_Block_Adminhtml_Config_Form_Field_License
  • Eabi_Postoffice_Block_Adminhtml_Config_Form_Field_Remove
  • Eabi_Postoffice_Block_Config_Rebuildbutton
  • Eabi_Postoffice_Helper_Countrycode
  • Eabi_Postoffice_Helper_Data
  • Eabi_Postoffice_IndexController
  • Eabi_Postoffice_Model_Carrier_Abstract
  • Eabi_Postoffice_Model_Carrier_Result
  • Eabi_Postoffice_Model_Carriermodule
  • Eabi_Postoffice_Model_Mysql4_Carriermodule
  • Eabi_Postoffice_Model_Mysql4_Carriermodule_Collection
  • Eabi_Postoffice_Model_Mysql4_Office
  • Eabi_Postoffice_Model_Mysql4_Office_Collection
  • Eabi_Postoffice_Model_Observer
  • Eabi_Postoffice_Model_Office
  • Eabi_Postoffice_Model_Orderview
  • Eabi_Postoffice_Model_Source_Sendevent
  • Eabi_Postoffice_Model_Updater
  • Overview
  • Namespace
  • Class
  • Tree
  1: <?php
  2: /*
  3:   
  4:  *
  5:  * NOTICE OF LICENSE
  6:  *
  7:  * This source file is subject to the Open Software License (OSL 3.0)
  8:  * or OpenGPL v3 license (GNU Public License V3.0)
  9:  * that is bundled with this package in the file LICENSE.txt.
 10:  * It is also available through the world-wide-web at this URL:
 11:  * http://opensource.org/licenses/osl-3.0.php
 12:  * or
 13:  * http://www.gnu.org/licenses/gpl-3.0.txt
 14:  * If you did not receive a copy of the license and are unable to
 15:  * obtain it through the world-wide-web, please send an email
 16:  * to info@e-abi.ee so we can send you a copy immediately.
 17:  *
 18:  * DISCLAIMER
 19:  *
 20:  * Do not edit or add to this file if you wish to upgrade this module to newer
 21:  * versions in the future.
 22:  *
 23:  * @category   Eabi
 24:  * @package    Eabi_Dpd
 25:  * @copyright  Copyright (c) 2014 Aktsiamaailm LLC (http://en.e-abi.ee/)
 26:  * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 27:  * @license    http://www.gnu.org/licenses/gpl-3.0.txt  GNU Public License V3.0
 28:  * @author     Matis Halmann
 29:  * 
 30: 
 31:  */
 32: 
 33: /**
 34:  * Helper class of getting Country Phone dial codes.
 35:  *
 36:  * @author Matis
 37:  */
 38: class Eabi_Postoffice_Helper_Countrycode {
 39: 
 40:     protected $_countryCodes = array(
 41:         'IL' => '972',
 42:         'AF' => '93',
 43:         'AL' => '355',
 44:         'DZ' => '213',
 45:         'AS' => '1684',
 46:         'AD' => '376',
 47:         'AO' => '244',
 48:         'AI' => '1264',
 49:         'AG' => '1268',
 50:         'AR' => '54',
 51:         'AM' => '374',
 52:         'AW' => '297',
 53:         'AU' => '61',
 54:         'AT' => '43',
 55:         'AZ' => '994',
 56:         'BS' => '1242',
 57:         'BH' => '973',
 58:         'BD' => '880',
 59:         'BB' => '1246',
 60:         'BY' => '375',
 61:         'BE' => '32',
 62:         'BZ' => '501',
 63:         'BJ' => '229',
 64:         'BM' => '1441',
 65:         'BT' => '975',
 66:         'BA' => '387',
 67:         'BW' => '267',
 68:         'BR' => '55',
 69:         'IO' => '246',
 70:         'BG' => '359',
 71:         'BF' => '226',
 72:         'BI' => '257',
 73:         'KH' => '855',
 74:         'CM' => '237',
 75:         'CA' => '1',
 76:         'CV' => '238',
 77:         'KY' => '345',
 78:         'CF' => '236',
 79:         'TD' => '235',
 80:         'CL' => '56',
 81:         'CN' => '86',
 82:         'CX' => '61',
 83:         'CO' => '57',
 84:         'KM' => '269',
 85:         'CG' => '242',
 86:         'CK' => '682',
 87:         'CR' => '506',
 88:         'HR' => '385',
 89:         'CU' => '53',
 90:         'CY' => '537',
 91:         'CZ' => '420',
 92:         'DK' => '45',
 93:         'DJ' => '253',
 94:         'DM' => '1767',
 95:         'DO' => '1849',
 96:         'EC' => '593',
 97:         'EG' => '20',
 98:         'SV' => '503',
 99:         'GQ' => '240',
100:         'ER' => '291',
101:         'EE' => '372',
102:         'ET' => '251',
103:         'FO' => '298',
104:         'FJ' => '679',
105:         'FI' => '358',
106:         'FR' => '33',
107:         'GF' => '594',
108:         'PF' => '689',
109:         'GA' => '241',
110:         'GM' => '220',
111:         'GE' => '995',
112:         'DE' => '49',
113:         'GH' => '233',
114:         'GI' => '350',
115:         'GR' => '30',
116:         'GL' => '299',
117:         'GD' => '1473',
118:         'GP' => '590',
119:         'GU' => '1671',
120:         'GT' => '502',
121:         'GN' => '224',
122:         'GW' => '245',
123:         'GY' => '595',
124:         'HT' => '509',
125:         'HN' => '504',
126:         'HU' => '36',
127:         'IS' => '354',
128:         'IN' => '91',
129:         'ID' => '62',
130:         'IQ' => '964',
131:         'IE' => '353',
132:         'IT' => '39',
133:         'JM' => '1876',
134:         'JP' => '81',
135:         'JO' => '962',
136:         'KZ' => '77',
137:         'KE' => '254',
138:         'KI' => '686',
139:         'KW' => '965',
140:         'KG' => '996',
141:         'LV' => '371',
142:         'LB' => '961',
143:         'LS' => '266',
144:         'LR' => '231',
145:         'LI' => '423',
146:         'LT' => '370',
147:         'LU' => '352',
148:         'MG' => '261',
149:         'MW' => '265',
150:         'MY' => '60',
151:         'MV' => '960',
152:         'ML' => '223',
153:         'MT' => '356',
154:         'MH' => '692',
155:         'MQ' => '596',
156:         'MR' => '222',
157:         'MU' => '230',
158:         'YT' => '262',
159:         'MX' => '52',
160:         'MC' => '377',
161:         'MN' => '976',
162:         'ME' => '382',
163:         'MS' => '1664',
164:         'MA' => '212',
165:         'MM' => '95',
166:         'NA' => '264',
167:         'NR' => '674',
168:         'NP' => '977',
169:         'NL' => '31',
170:         'AN' => '599',
171:         'NC' => '687',
172:         'NZ' => '64',
173:         'NI' => '505',
174:         'NE' => '227',
175:         'NG' => '234',
176:         'NU' => '683',
177:         'NF' => '672',
178:         'MP' => '1670',
179:         'NO' => '47',
180:         'OM' => '968',
181:         'PK' => '92',
182:         'PW' => '680',
183:         'PA' => '507',
184:         'PG' => '675',
185:         'PY' => '595',
186:         'PE' => '51',
187:         'PH' => '63',
188:         'PL' => '48',
189:         'PT' => '351',
190:         'PR' => '1939',
191:         'QA' => '974',
192:         'RO' => '40',
193:         'RW' => '250',
194:         'WS' => '685',
195:         'SM' => '378',
196:         'SA' => '966',
197:         'SN' => '221',
198:         'RS' => '381',
199:         'SC' => '248',
200:         'SL' => '232',
201:         'SG' => '65',
202:         'SK' => '421',
203:         'SI' => '386',
204:         'SB' => '677',
205:         'ZA' => '27',
206:         'GS' => '500',
207:         'ES' => '34',
208:         'LK' => '94',
209:         'SD' => '249',
210:         'SR' => '597',
211:         'SZ' => '268',
212:         'SE' => '46',
213:         'CH' => '41',
214:         'TJ' => '992',
215:         'TH' => '66',
216:         'TG' => '228',
217:         'TK' => '690',
218:         'TO' => '676',
219:         'TT' => '1868',
220:         'TN' => '216',
221:         'TR' => '90',
222:         'TM' => '993',
223:         'TC' => '1649',
224:         'TV' => '688',
225:         'UG' => '256',
226:         'UA' => '380',
227:         'AE' => '971',
228:         'GB' => '44',
229:         'US' => '1',
230:         'UY' => '598',
231:         'UZ' => '998',
232:         'VU' => '678',
233:         'WF' => '681',
234:         'YE' => '967',
235:         'ZM' => '260',
236:         'ZW' => '263',
237:         'BO' => '591',
238:         'BN' => '673',
239:         'CC' => '61',
240:         'CD' => '243',
241:         'CI' => '225',
242:         'FK' => '500',
243:         'GG' => '44',
244:         'VA' => '379',
245:         'HK' => '852',
246:         'IR' => '98',
247:         'IM' => '44',
248:         'JE' => '44',
249:         'KP' => '850',
250:         'KR' => '82',
251:         'LA' => '856',
252:         'LY' => '218',
253:         'MO' => '853',
254:         'MK' => '389',
255:         'FM' => '691',
256:         'MD' => '373',
257:         'MZ' => '258',
258:         'PS' => '970',
259:         'PN' => '872',
260:         'RE' => '262',
261:         'RU' => '7',
262:         'BL' => '590',
263:         'SH' => '290',
264:         'KN' => '1869',
265:         'LC' => '1758',
266:         'MF' => '590',
267:         'PM' => '508',
268:         'VC' => '1784',
269:         'ST' => '239',
270:         'SO' => '252',
271:         'SJ' => '47',
272:         'SY' => '963',
273:         'TW' => '886',
274:         'TZ' => '255',
275:         'TL' => '670',
276:         'VE' => '58',
277:         'VN' => '84',
278:         'VG' => '1284',
279:         'VI' => '1340',
280:     );
281: 
282:     /**
283:      * Gets array of all phone country codes, where array key is country ISO-3166 code and value is numeric dial code without '+'
284:      * @return array
285:      */
286:     public function getCountryCodes() {
287:         return $this->_countryCodes;
288:     }
289: 
290: 
291:     /**
292:      * Gets numeric dialcode without '+' sign for specified country code
293:      * @param string $countryId ISO-3166 country code
294:      * @return string
295:      */
296:     public function getCountryCode($countryId) {
297:         if (isset($this->_countryCodes[$countryId])) {
298:             return $this->_countryCodes[$countryId];
299:         }
300:         return null;
301:     }
302:     
303:     
304:     
305:     /**
306:      * <p>Attempts to separate country code from phone number by supplied default country.</p>
307:      * <p>If Phone number is missing country code, then it is applied by supplied country ISO-3166 code</p>
308:      * <p>Returns array with following format</p>
309:      * <pre>
310:      *  array(
311:      *      'dial_code' => country dial code with + prefix
312:      *      'phone_number' => phone number without country code
313:      *  );
314:      * </pre>
315:      * 
316:      * @param string $phonenumber phone number that may contain country code
317:      * @param string $countryId ISO-3166 country code
318:      * @return array
319:      */
320:     public function separatePhoneNumberFromCountryCode($phonenumber, $countryId) {
321:         $result = array(
322:             'dial_code' => '',
323:             'phone_number' => '',
324:         );
325:         $defaultDialCode = $this->getCountryCode($countryId);
326:         
327:         //remove all whitespace
328:         $phonenumber = str_replace(' ', '', $phonenumber);
329:         
330:         //when country code is supplied, then it can:
331:         //start with country code
332:         //start with + sign
333:         //start with 00 (double zero)
334:         //be longer than 10 digits
335:         $containsCountryCode = strpos($phonenumber, $defaultDialCode) === 0
336:                 || strpos($phonenumber, '+') === 0
337:                 || strpos($phonenumber, '00') === 0
338:                 || strlen($phonenumber) > 10;
339:         
340:         //when country code is not supplied, then it can
341:         //start with single zero
342:         //start with any number
343:         if (!$containsCountryCode) {
344:             $result['dial_code'] = '+'.$defaultDialCode;
345:             if (strpos($phonenumber, '0') === 0) {
346:                 $result['phone_number'] = substr($phonenumber, 1);
347:             } else {
348:                 $result['phone_number'] = $phonenumber;
349:             }
350:         } else {
351:             //phone number contains country code
352:             //we need to know what country code phone number contains
353:             //remove 00 or + sign
354:             $phonenumber = ltrim($phonenumber, '+0');
355:             $dialCode = $this->_getCountryCodeFromPhonenumber($phonenumber, $defaultDialCode);
356:             $result['dial_code'] = '+'.$dialCode;
357:             $result['phone_number'] = substr($phonenumber, strlen($dialCode));
358:         }
359:         
360:         
361:         return $result;
362:     }
363:     
364: 
365:     /**
366:      * <p>Attempts to find country code from phone number, when it is known that phone number most certainly contains country code.</p>
367:      * <p>Method assumes that longest found dial code is matcing dial code for this phone number.</p>
368:      * <p>If now match is found then default code is used.</p>
369:      * @param string $phonenumber phone number that is known to contain country code
370:      * @param string $defaultCode dial code to be used if no country code is found
371:      * @return string resulting dial code without + sign
372:      */
373:     protected function _getCountryCodeFromPhonenumber($phonenumber, $defaultCode) {
374:         $matchingCountryCode = '';
375:         foreach ($this->getCountryCodes() as $countryIso => $dialCode) {
376:             if (strpos($phonenumber, $dialCode) === 0) {
377:                 if (strlen($dialCode) > $matchingCountryCode) {
378:                     $matchingCountryCode = $dialCode;
379:                 }
380:             }
381:         }
382:         //as last resort apply default dial code
383:         if ($matchingCountryCode === '') {
384:             return $defaultCode;
385:         }
386:         return $matchingCountryCode;
387:     }
388: 
389: }
390: 
DPD Eesti - Pakivedu.ee Shipping module for Magento API documentation generated by ApiGen 2.8.0