Overview

Packages

  • currencysymbol
  • MAbout
  • Mage
    • Admin
    • Adminhtml
    • AdminNotification
    • Api
    • Api2
    • Authorizenet
    • Backup
    • Bundle
    • Captcha
    • Catalog
    • CatalogIndex
    • CatalogInventory
    • CatalogRule
    • CatalogSearch
    • Centinel
    • Checkout
    • Cms
    • Compiler
    • Connect
    • Contacts
    • Core
    • Cron
    • CurrencySymbol
    • Customer
    • Dataflow
    • Directory
    • DirtectPost
    • Downloadable
    • Eav
    • GiftMessage
    • GoogleAnalytics
    • GoogleBase
    • GoogleCheckout
    • ImportExport
    • Index
    • Install
    • Log
    • Media
    • Newsletter
    • Oauth
    • Page
    • PageCache
    • Paygate
    • Payment
    • Paypal
    • PaypalUk
    • Persistent
    • Poll
    • ProductAlert
    • Rating
    • Reports
    • Review
    • Rss
    • Rule
    • Sales
    • SalesRule
    • Sedfriend
    • Sendfriend
    • Shipping
    • Sitemap
    • Tag
    • Tax
    • Usa
    • Weee
    • Widget
    • Wishlist
    • XmlConnect
  • None
  • Phoenix
    • Moneybookers
  • PHP
  • Zend
    • Date
    • Mime
    • XmlRpc

Classes

  • Mage_Customer_AccountController
  • Mage_Customer_AddressController
  • Mage_Customer_Block_Account
  • Mage_Customer_Block_Account_Dashboard
  • Mage_Customer_Block_Account_Dashboard_Address
  • Mage_Customer_Block_Account_Dashboard_Block
  • Mage_Customer_Block_Account_Dashboard_Hello
  • Mage_Customer_Block_Account_Dashboard_Info
  • Mage_Customer_Block_Account_Dashboard_Newsletter
  • Mage_Customer_Block_Account_Dashboard_Sidebar
  • Mage_Customer_Block_Account_Forgotpassword
  • Mage_Customer_Block_Account_Navigation
  • Mage_Customer_Block_Account_Resetpassword
  • Mage_Customer_Block_Address_Book
  • Mage_Customer_Block_Address_Edit
  • Mage_Customer_Block_Address_Renderer_Default
  • Mage_Customer_Block_Form_Edit
  • Mage_Customer_Block_Form_Login
  • Mage_Customer_Block_Form_Register
  • Mage_Customer_Block_Newsletter
  • Mage_Customer_Block_Widget_Abstract
  • Mage_Customer_Block_Widget_Dob
  • Mage_Customer_Block_Widget_Gender
  • Mage_Customer_Block_Widget_Name
  • Mage_Customer_Block_Widget_Taxvat
  • Mage_Customer_Helper_Address
  • Mage_Customer_Helper_Data
  • Mage_Customer_Model_Address
  • Mage_Customer_Model_Address_Abstract
  • Mage_Customer_Model_Address_Api
  • Mage_Customer_Model_Address_Api_V2
  • Mage_Customer_Model_Address_Config
  • Mage_Customer_Model_Api2_Customer
  • Mage_Customer_Model_Api2_Customer_Address
  • Mage_Customer_Model_Api2_Customer_Address_Rest
  • Mage_Customer_Model_Api2_Customer_Address_Rest_Admin_V1
  • Mage_Customer_Model_Api2_Customer_Address_Rest_Customer_V1
  • Mage_Customer_Model_Api2_Customer_Address_Validator
  • Mage_Customer_Model_Api2_Customer_Rest
  • Mage_Customer_Model_Api2_Customer_Rest_Admin_V1
  • Mage_Customer_Model_Api2_Customer_Rest_Customer_V1
  • Mage_Customer_Model_Api_Resource
  • Mage_Customer_Model_Attribute
  • Mage_Customer_Model_Attribute_Backend_Data_Boolean
  • Mage_Customer_Model_Attribute_Data
  • Mage_Customer_Model_Attribute_Data_Abstract
  • Mage_Customer_Model_Attribute_Data_Boolean
  • Mage_Customer_Model_Attribute_Data_Date
  • Mage_Customer_Model_Attribute_Data_File
  • Mage_Customer_Model_Attribute_Data_Hidden
  • Mage_Customer_Model_Attribute_Data_Image
  • Mage_Customer_Model_Attribute_Data_Multiline
  • Mage_Customer_Model_Attribute_Data_Multiselect
  • Mage_Customer_Model_Attribute_Data_Postcode
  • Mage_Customer_Model_Attribute_Data_Select
  • Mage_Customer_Model_Attribute_Data_Text
  • Mage_Customer_Model_Attribute_Data_Textarea
  • Mage_Customer_Model_Config_Share
  • Mage_Customer_Model_Convert_Adapter_Customer
  • Mage_Customer_Model_Convert_Parser_Customer
  • Mage_Customer_Model_Customer
  • Mage_Customer_Model_Customer_Api
  • Mage_Customer_Model_Customer_Api_V2
  • Mage_Customer_Model_Customer_Attribute_Backend_Billing
  • Mage_Customer_Model_Customer_Attribute_Backend_Password
  • Mage_Customer_Model_Customer_Attribute_Backend_Shipping
  • Mage_Customer_Model_Customer_Attribute_Backend_Store
  • Mage_Customer_Model_Customer_Attribute_Backend_Website
  • Mage_Customer_Model_Customer_Attribute_Source_Group
  • Mage_Customer_Model_Customer_Attribute_Source_Store
  • Mage_Customer_Model_Customer_Attribute_Source_Website
  • Mage_Customer_Model_Entity_Address
  • Mage_Customer_Model_Entity_Address_Attribute_Backend_Region
  • Mage_Customer_Model_Entity_Address_Attribute_Backend_Street
  • Mage_Customer_Model_Entity_Address_Attribute_Collection
  • Mage_Customer_Model_Entity_Address_Attribute_Source_Country
  • Mage_Customer_Model_Entity_Address_Attribute_Source_Region
  • Mage_Customer_Model_Entity_Address_Collection
  • Mage_Customer_Model_Entity_Attribute
  • Mage_Customer_Model_Entity_Attribute_Collection
  • Mage_Customer_Model_Entity_Customer
  • Mage_Customer_Model_Entity_Customer_Collection
  • Mage_Customer_Model_Entity_Form_Attribute
  • Mage_Customer_Model_Entity_Form_Attribute_Collection
  • Mage_Customer_Model_Entity_Group
  • Mage_Customer_Model_Entity_Group_Collection
  • Mage_Customer_Model_Entity_Setup
  • Mage_Customer_Model_Entity_Wishlist_Collection
  • Mage_Customer_Model_Form
  • Mage_Customer_Model_Group
  • Mage_Customer_Model_Group_Api
  • Mage_Customer_Model_Group_Api_V2
  • Mage_Customer_Model_Observer
  • Mage_Customer_Model_Resource_Address
  • Mage_Customer_Model_Resource_Address_Attribute_Backend_Region
  • Mage_Customer_Model_Resource_Address_Attribute_Backend_Street
  • Mage_Customer_Model_Resource_Address_Attribute_Collection
  • Mage_Customer_Model_Resource_Address_Attribute_Source_Country
  • Mage_Customer_Model_Resource_Address_Attribute_Source_Region
  • Mage_Customer_Model_Resource_Address_Collection
  • Mage_Customer_Model_Resource_Attribute
  • Mage_Customer_Model_Resource_Attribute_Collection
  • Mage_Customer_Model_Resource_Customer
  • Mage_Customer_Model_Resource_Customer_Collection
  • Mage_Customer_Model_Resource_Form_Attribute
  • Mage_Customer_Model_Resource_Form_Attribute_Collection
  • Mage_Customer_Model_Resource_Group
  • Mage_Customer_Model_Resource_Group_Collection
  • Mage_Customer_Model_Resource_Setup
  • Mage_Customer_Model_Resource_Wishlist_Collection
  • Mage_Customer_Model_Session
  • Mage_Customer_ReviewController

Interfaces

  • Mage_Customer_Block_Address_Renderer_Interface

Exceptions

  • Mage_Customer_Exception
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Magento
  4:  *
  5:  * NOTICE OF LICENSE
  6:  *
  7:  * This source file is subject to the Open Software License (OSL 3.0)
  8:  * that is bundled with this package in the file LICENSE.txt.
  9:  * It is also available through the world-wide-web at this URL:
 10:  * http://opensource.org/licenses/osl-3.0.php
 11:  * If you did not receive a copy of the license and are unable to
 12:  * obtain it through the world-wide-web, please send an email
 13:  * to license@magentocommerce.com so we can send you a copy immediately.
 14:  *
 15:  * DISCLAIMER
 16:  *
 17:  * Do not edit or add to this file if you wish to upgrade Magento to newer
 18:  * versions in the future. If you wish to customize Magento for your
 19:  * needs please refer to http://www.magentocommerce.com for more information.
 20:  *
 21:  * @category    Mage
 22:  * @package     Mage_Customer
 23:  * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
 24:  * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 25:  */
 26: 
 27: 
 28: /**
 29:  * Customer Data Helper
 30:  *
 31:  * @category   Mage
 32:  * @package    Mage_Customer
 33:  * @author     Magento Core Team <core@magentocommerce.com>
 34:  */
 35: class Mage_Customer_Helper_Data extends Mage_Core_Helper_Abstract
 36: {
 37:     /**
 38:      * Query param name for last url visited
 39:      */
 40:     const REFERER_QUERY_PARAM_NAME = 'referer';
 41: 
 42:     /**
 43:      * Route for customer account login page
 44:      */
 45:     const ROUTE_ACCOUNT_LOGIN = 'customer/account/login';
 46: 
 47:     /**
 48:      * Config name for Redirect Customer to Account Dashboard after Logging in setting
 49:      */
 50:     const XML_PATH_CUSTOMER_STARTUP_REDIRECT_TO_DASHBOARD = 'customer/startup/redirect_dashboard';
 51: 
 52:     /**
 53:      * Config paths to VAT related customer groups
 54:      */
 55:     const XML_PATH_CUSTOMER_VIV_INTRA_UNION_GROUP = 'customer/create_account/viv_intra_union_group';
 56:     const XML_PATH_CUSTOMER_VIV_DOMESTIC_GROUP = 'customer/create_account/viv_domestic_group';
 57:     const XML_PATH_CUSTOMER_VIV_INVALID_GROUP = 'customer/create_account/viv_invalid_group';
 58:     const XML_PATH_CUSTOMER_VIV_ERROR_GROUP = 'customer/create_account/viv_error_group';
 59: 
 60:     /**
 61:      * Config path to option that enables/disables automatic group assignment based on VAT
 62:      */
 63:     const XML_PATH_CUSTOMER_VIV_GROUP_AUTO_ASSIGN = 'customer/create_account/viv_disable_auto_group_assign_default';
 64: 
 65:     /**
 66:      * Config path to support email
 67:      */
 68:     const XML_PATH_SUPPORT_EMAIL = 'trans_email/ident_support/email';
 69: 
 70:     /**
 71:      * WSDL of VAT validation service
 72:      *
 73:      */
 74:     const VAT_VALIDATION_WSDL_URL = 'http://ec.europa.eu/taxation_customs/vies/services/checkVatService?wsdl';
 75: 
 76:     /**
 77:      * Configuration path to expiration period of reset password link
 78:      */
 79:     const XML_PATH_CUSTOMER_RESET_PASSWORD_LINK_EXPIRATION_PERIOD
 80:         = 'default/customer/password/reset_link_expiration_period';
 81: 
 82:     /**
 83:      * VAT class constants
 84:      */
 85:     const VAT_CLASS_DOMESTIC    = 'domestic';
 86:     const VAT_CLASS_INTRA_UNION = 'intra_union';
 87:     const VAT_CLASS_INVALID     = 'invalid';
 88:     const VAT_CLASS_ERROR       = 'error';
 89: 
 90:     /**
 91:      * Customer groups collection
 92:      *
 93:      * @var Mage_Customer_Model_Entity_Group_Collection
 94:      */
 95:     protected $_groups;
 96: 
 97:     /**
 98:      * Check customer is logged in
 99:      *
100:      * @return bool
101:      */
102:     public function isLoggedIn()
103:     {
104:         return Mage::getSingleton('customer/session')->isLoggedIn();
105:     }
106: 
107:     /**
108:      * Retrieve logged in customer
109:      *
110:      * @return Mage_Customer_Model_Customer
111:      */
112:     public function getCustomer()
113:     {
114:         if (empty($this->_customer)) {
115:             $this->_customer = Mage::getSingleton('customer/session')->getCustomer();
116:         }
117:         return $this->_customer;
118:     }
119: 
120:     /**
121:      * Retrieve customer groups collection
122:      *
123:      * @return Mage_Customer_Model_Entity_Group_Collection
124:      */
125:     public function getGroups()
126:     {
127:         if (empty($this->_groups)) {
128:             $this->_groups = Mage::getModel('customer/group')->getResourceCollection()
129:                 ->setRealGroupsFilter()
130:                 ->load();
131:         }
132:         return $this->_groups;
133:     }
134: 
135:     /**
136:      * Retrieve current (logged in) customer object
137:      *
138:      * @return Mage_Customer_Model_Customer
139:      */
140:     public function getCurrentCustomer()
141:     {
142:         return $this->getCustomer();
143:     }
144: 
145:     /**
146:      * Retrieve current customer name
147:      *
148:      * @return string
149:      */
150:     public function getCustomerName()
151:     {
152:         return $this->getCustomer()->getName();
153:     }
154: 
155:     /**
156:      * Check customer has address
157:      *
158:      * @return bool
159:      */
160:     public function customerHasAddresses()
161:     {
162:         return count($this->getCustomer()->getAddresses()) > 0;
163:     }
164: 
165:     /**************************************************************************
166:      * Customer urls
167:      */
168: 
169:     /**
170:      * Retrieve customer login url
171:      *
172:      * @return string
173:      */
174:     public function getLoginUrl()
175:     {
176:         return $this->_getUrl(self::ROUTE_ACCOUNT_LOGIN, $this->getLoginUrlParams());
177:     }
178: 
179:     /**
180:      * Retrieve parameters of customer login url
181:      *
182:      * @return array
183:      */
184:     public function getLoginUrlParams()
185:     {
186:         $params = array();
187: 
188:         $referer = $this->_getRequest()->getParam(self::REFERER_QUERY_PARAM_NAME);
189: 
190:         if (!$referer && !Mage::getStoreConfigFlag(self::XML_PATH_CUSTOMER_STARTUP_REDIRECT_TO_DASHBOARD)
191:             && !Mage::getSingleton('customer/session')->getNoReferer()
192:         ) {
193:             $referer = Mage::getUrl('*/*/*', array('_current' => true, '_use_rewrite' => true));
194:             $referer = Mage::helper('core')->urlEncode($referer);
195:         }
196: 
197:         if ($referer) {
198:             $params = array(self::REFERER_QUERY_PARAM_NAME => $referer);
199:         }
200: 
201:         return $params;
202:     }
203: 
204:     /**
205:      * Retrieve customer login POST URL
206:      *
207:      * @return string
208:      */
209:     public function getLoginPostUrl()
210:     {
211:         $params = array();
212:         if ($this->_getRequest()->getParam(self::REFERER_QUERY_PARAM_NAME)) {
213:             $params = array(
214:                 self::REFERER_QUERY_PARAM_NAME => $this->_getRequest()->getParam(self::REFERER_QUERY_PARAM_NAME)
215:             );
216:         }
217:         return $this->_getUrl('customer/account/loginPost', $params);
218:     }
219: 
220:     /**
221:      * Retrieve customer logout url
222:      *
223:      * @return string
224:      */
225:     public function getLogoutUrl()
226:     {
227:         return $this->_getUrl('customer/account/logout');
228:     }
229: 
230:     /**
231:      * Retrieve customer dashboard url
232:      *
233:      * @return string
234:      */
235:     public function getDashboardUrl()
236:     {
237:         return $this->_getUrl('customer/account');
238:     }
239: 
240:     /**
241:      * Retrieve customer account page url
242:      *
243:      * @return string
244:      */
245:     public function getAccountUrl()
246:     {
247:         return $this->_getUrl('customer/account');
248:     }
249: 
250:     /**
251:      * Retrieve customer register form url
252:      *
253:      * @return string
254:      */
255:     public function getRegisterUrl()
256:     {
257:         return $this->_getUrl('customer/account/create');
258:     }
259: 
260:     /**
261:      * Retrieve customer register form post url
262:      *
263:      * @return string
264:      */
265:     public function getRegisterPostUrl()
266:     {
267:         return $this->_getUrl('customer/account/createpost');
268:     }
269: 
270:     /**
271:      * Retrieve customer account edit form url
272:      *
273:      * @return string
274:      */
275:     public function getEditUrl()
276:     {
277:         return $this->_getUrl('customer/account/edit');
278:     }
279: 
280:     /**
281:      * Retrieve customer edit POST URL
282:      *
283:      * @return string
284:      */
285:     public function getEditPostUrl()
286:     {
287:         return $this->_getUrl('customer/account/editpost');
288:     }
289: 
290:     /**
291:      * Retrieve url of forgot password page
292:      *
293:      * @return string
294:      */
295:     public function getForgotPasswordUrl()
296:     {
297:         return $this->_getUrl('customer/account/forgotpassword');
298:     }
299: 
300:     /**
301:      * Check is confirmation required
302:      *
303:      * @return bool
304:      */
305:     public function isConfirmationRequired()
306:     {
307:         return $this->getCustomer()->isConfirmationRequired();
308:     }
309: 
310:     /**
311:      * Retrieve confirmation URL for Email
312:      *
313:      * @param string $email
314:      * @return string
315:      */
316:     public function getEmailConfirmationUrl($email = null)
317:     {
318:         return $this->_getUrl('customer/account/confirmation', array('email' => $email));
319:     }
320: 
321:     /**
322:      * Check whether customers registration is allowed
323:      *
324:      * @return bool
325:      */
326:     public function isRegistrationAllowed()
327:     {
328:         $result = new Varien_Object(array('is_allowed' => true));
329:         Mage::dispatchEvent('customer_registration_is_allowed', array('result' => $result));
330:         return $result->getIsAllowed();
331:     }
332: 
333:     /**
334:      * Retrieve name prefix dropdown options
335:      *
336:      * @return array|bool
337:      */
338:     public function getNamePrefixOptions($store = null)
339:     {
340:         return $this->_prepareNamePrefixSuffixOptions(
341:             Mage::helper('customer/address')->getConfig('prefix_options', $store)
342:         );
343:     }
344: 
345:     /**
346:      * Retrieve name suffix dropdown options
347:      *
348:      * @return array|bool
349:      */
350:     public function getNameSuffixOptions($store = null)
351:     {
352:         return $this->_prepareNamePrefixSuffixOptions(
353:             Mage::helper('customer/address')->getConfig('suffix_options', $store)
354:         );
355:     }
356: 
357:     /**
358:      * Unserialize and clear name prefix or suffix options
359:      *
360:      * @param string $options
361:      * @return array|bool
362:      */
363:     protected function _prepareNamePrefixSuffixOptions($options)
364:     {
365:         $options = trim($options);
366:         if (empty($options)) {
367:             return false;
368:         }
369:         $result = array();
370:         $options = explode(';', $options);
371:         foreach ($options as $value) {
372:             $value = $this->escapeHtml(trim($value));
373:             $result[$value] = $value;
374:         }
375:         return $result;
376:     }
377: 
378:     /**
379:      * Generate unique token for reset password confirmation link
380:      *
381:      * @return string
382:      */
383:     public function generateResetPasswordLinkToken()
384:     {
385:         return Mage::helper('core')->uniqHash();
386:     }
387: 
388:     /**
389:      * Retrieve customer reset password link expiration period in days
390:      *
391:      * @return int
392:      */
393:     public function getResetPasswordLinkExpirationPeriod()
394:     {
395:         return (int) Mage::getConfig()->getNode(self::XML_PATH_CUSTOMER_RESET_PASSWORD_LINK_EXPIRATION_PERIOD);
396:     }
397: 
398:     /**
399:      * Get default customer group id
400:      *
401:      * @param Mage_Core_Model_Store|string|int $store
402:      * @return int
403:      */
404:     public function getDefaultCustomerGroupId($store = null)
405:     {
406:         return (int)Mage::getStoreConfig(Mage_Customer_Model_Group::XML_PATH_DEFAULT_ID, $store);
407:     }
408: 
409:     /**
410:      * Retrieve customer group ID based on his VAT number
411:      *
412:      * @param string $customerCountryCode
413:      * @param Varien_Object $vatValidationResult
414:      * @param Mage_Core_Model_Store|string|int $store
415:      * @return null|int
416:      */
417:     public function getCustomerGroupIdBasedOnVatNumber($customerCountryCode, $vatValidationResult, $store = null)
418:     {
419:         $groupId = null;
420: 
421:         $vatClass = $this->getCustomerVatClass($customerCountryCode, $vatValidationResult, $store);
422: 
423:         $vatClassToGroupXmlPathMap = array(
424:             self::VAT_CLASS_DOMESTIC => self::XML_PATH_CUSTOMER_VIV_DOMESTIC_GROUP,
425:             self::VAT_CLASS_INTRA_UNION => self::XML_PATH_CUSTOMER_VIV_INTRA_UNION_GROUP,
426:             self::VAT_CLASS_INVALID => self::XML_PATH_CUSTOMER_VIV_INVALID_GROUP,
427:             self::VAT_CLASS_ERROR => self::XML_PATH_CUSTOMER_VIV_ERROR_GROUP
428:         );
429: 
430:         if (isset($vatClassToGroupXmlPathMap[$vatClass])) {
431:             $groupId = (int)Mage::getStoreConfig($vatClassToGroupXmlPathMap[$vatClass], $store);
432:         }
433: 
434:         return $groupId;
435:     }
436: 
437:     /**
438:      * Send request to VAT validation service and return validation result
439:      *
440:      * @param string $countryCode
441:      * @param string $vatNumber
442:      * @param string $requesterCountryCode
443:      * @param string $requesterVatNumber
444:      *
445:      * @return Varien_Object
446:      */
447:     public function checkVatNumber($countryCode, $vatNumber, $requesterCountryCode = '', $requesterVatNumber = '')
448:     {
449:         // Default response
450:         $gatewayResponse = new Varien_Object(array(
451:             'is_valid' => false,
452:             'request_date' => '',
453:             'request_identifier' => '',
454:             'request_success' => false
455:         ));
456: 
457:         if (!extension_loaded('soap')) {
458:             Mage::logException(Mage::exception('Mage_Core',
459:                 Mage::helper('core')->__('PHP SOAP extension is required.')));
460:             return $gatewayResponse;
461:         }
462: 
463:         if (!$this->canCheckVatNumber($countryCode, $vatNumber, $requesterCountryCode, $requesterVatNumber)) {
464:             return $gatewayResponse;
465:         }
466: 
467:         try {
468:             $soapClient = $this->_createVatNumberValidationSoapClient();
469: 
470:             $requestParams = array();
471:             $requestParams['countryCode'] = $countryCode;
472:             $requestParams['vatNumber'] = str_replace(array(' ', '-'), array('', ''), $vatNumber);
473:             $requestParams['requesterCountryCode'] = $requesterCountryCode;
474:             $requestParams['requesterVatNumber'] = str_replace(array(' ', '-'), array('', ''), $requesterVatNumber);
475: 
476:             // Send request to service
477:             $result = $soapClient->checkVatApprox($requestParams);
478: 
479:             $gatewayResponse->setIsValid((boolean) $result->valid);
480:             $gatewayResponse->setRequestDate((string) $result->requestDate);
481:             $gatewayResponse->setRequestIdentifier((string) $result->requestIdentifier);
482:             $gatewayResponse->setRequestSuccess(true);
483:         } catch (Exception $exception) {
484:             $gatewayResponse->setIsValid(false);
485:             $gatewayResponse->setRequestDate('');
486:             $gatewayResponse->setRequestIdentifier('');
487:         }
488: 
489:         return $gatewayResponse;
490:     }
491: 
492:     /**
493:      * Check if parameters are valid to send to VAT validation service
494:      *
495:      * @param string $countryCode
496:      * @param string $vatNumber
497:      * @param string $requesterCountryCode
498:      * @param string $requesterVatNumber
499:      *
500:      * @return boolean
501:      */
502:     public function canCheckVatNumber($countryCode, $vatNumber, $requesterCountryCode, $requesterVatNumber)
503:     {
504:         $result = true;
505:         /** @var $coreHelper Mage_Core_Helper_Data */
506:         $coreHelper = Mage::helper('core');
507: 
508:         if (!is_string($countryCode)
509:             || !is_string($vatNumber)
510:             || !is_string($requesterCountryCode)
511:             || !is_string($requesterVatNumber)
512:             || empty($countryCode)
513:             || !$coreHelper->isCountryInEU($countryCode)
514:             || empty($vatNumber)
515:             || (empty($requesterCountryCode) && !empty($requesterVatNumber))
516:             || (!empty($requesterCountryCode) && empty($requesterVatNumber))
517:             || (!empty($requesterCountryCode) && !$coreHelper->isCountryInEU($requesterCountryCode))
518:         ) {
519:             $result = false;
520:         }
521: 
522:         return $result;
523:     }
524: 
525:     /**
526:      * Get VAT class
527:      *
528:      * @param string $customerCountryCode
529:      * @param Varien_Object $vatValidationResult
530:      * @param Mage_Core_Model_Store|string|int|null $store
531:      * @return null|string
532:      */
533:     public function getCustomerVatClass($customerCountryCode, $vatValidationResult, $store = null)
534:     {
535:         $vatClass = null;
536: 
537:         $isVatNumberValid = $vatValidationResult->getIsValid();
538: 
539:         if (is_string($customerCountryCode)
540:             && !empty($customerCountryCode)
541:             && $customerCountryCode === Mage::helper('core')->getMerchantCountryCode($store)
542:             && $isVatNumberValid
543:         ) {
544:             $vatClass = self::VAT_CLASS_DOMESTIC;
545:         } elseif ($isVatNumberValid) {
546:             $vatClass = self::VAT_CLASS_INTRA_UNION;
547:         } else {
548:             $vatClass = self::VAT_CLASS_INVALID;
549:         }
550: 
551:         if (!$vatValidationResult->getRequestSuccess()) {
552:             $vatClass = self::VAT_CLASS_ERROR;
553:         }
554: 
555:         return $vatClass;
556:     }
557: 
558:     /**
559:      * Get validation message that will be displayed to user by VAT validation result object
560:      *
561:      * @param Mage_Customer_Model_Address $customerAddress
562:      * @param bool $customerGroupAutoAssignDisabled
563:      * @param Varien_Object $validationResult
564:      * @return Varien_Object
565:      */
566:     public function getVatValidationUserMessage($customerAddress, $customerGroupAutoAssignDisabled, $validationResult)
567:     {
568:         $message = '';
569:         $isError = true;
570:         $customerVatClass = $this->getCustomerVatClass($customerAddress->getCountryId(), $validationResult);
571:         $groupAutoAssignDisabled = Mage::getStoreConfigFlag(self::XML_PATH_CUSTOMER_VIV_GROUP_AUTO_ASSIGN);
572: 
573:         $willChargeTaxMessage    = $this->__('You will be charged tax.');
574:         $willNotChargeTaxMessage = $this->__('You will not be charged tax.');
575: 
576:         if ($validationResult->getIsValid()) {
577:             $message = $this->__('Your VAT ID was successfully validated.');
578:             $isError = false;
579: 
580:             if (!$groupAutoAssignDisabled && !$customerGroupAutoAssignDisabled) {
581:                 $message .= ' ' . ($customerVatClass == self::VAT_CLASS_DOMESTIC
582:                     ? $willChargeTaxMessage
583:                     : $willNotChargeTaxMessage);
584:             }
585:         } else if ($validationResult->getRequestSuccess()) {
586:             $message = sprintf(
587:                 $this->__('The VAT ID entered (%s) is not a valid VAT ID.') . ' ',
588:                 $this->escapeHtml($customerAddress->getVatId())
589:             );
590:             if (!$groupAutoAssignDisabled && !$customerGroupAutoAssignDisabled) {
591:                 $message .= $willChargeTaxMessage;
592:             }
593:         }
594:         else {
595:             $contactUsMessage = sprintf($this->__('If you believe this is an error, please contact us at %s'),
596:                 Mage::getStoreConfig(self::XML_PATH_SUPPORT_EMAIL));
597: 
598:             $message = $this->__('Your Tax ID cannot be validated.') . ' '
599:                 . (!$groupAutoAssignDisabled && !$customerGroupAutoAssignDisabled
600:                     ? $willChargeTaxMessage . ' ' : '')
601:                 . $contactUsMessage;
602:         }
603: 
604:         $validationMessageEnvelope = new Varien_Object();
605:         $validationMessageEnvelope->setMessage($message);
606:         $validationMessageEnvelope->setIsError($isError);
607: 
608:         return $validationMessageEnvelope;
609:     }
610: 
611:     /**
612:      * Create SOAP client based on VAT validation service WSDL
613:      *
614:      * @param boolean $trace
615:      * @return SoapClient
616:      */
617:     protected function _createVatNumberValidationSoapClient($trace = false)
618:     {
619:         return new SoapClient(self::VAT_VALIDATION_WSDL_URL, array('trace' => $trace));
620:     }
621: }
622: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0