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:  * Customer model
  29:  *
  30:  * @category    Mage
  31:  * @package     Mage_Customer
  32:  * @author      Magento Core Team <core@magentocommerce.com>
  33:  */
  34: class Mage_Customer_Model_Customer extends Mage_Core_Model_Abstract
  35: {
  36:     /**
  37:      * Configuration pathes for email templates and identities
  38:      */
  39:     const XML_PATH_REGISTER_EMAIL_TEMPLATE = 'customer/create_account/email_template';
  40:     const XML_PATH_REGISTER_EMAIL_IDENTITY = 'customer/create_account/email_identity';
  41:     const XML_PATH_REMIND_EMAIL_TEMPLATE = 'customer/password/remind_email_template';
  42:     const XML_PATH_FORGOT_EMAIL_TEMPLATE = 'customer/password/forgot_email_template';
  43:     const XML_PATH_FORGOT_EMAIL_IDENTITY = 'customer/password/forgot_email_identity';
  44: 
  45:     const XML_PATH_DEFAULT_EMAIL_DOMAIN         = 'customer/create_account/email_domain';
  46:     const XML_PATH_IS_CONFIRM                   = 'customer/create_account/confirm';
  47:     const XML_PATH_CONFIRM_EMAIL_TEMPLATE       = 'customer/create_account/email_confirmation_template';
  48:     const XML_PATH_CONFIRMED_EMAIL_TEMPLATE     = 'customer/create_account/email_confirmed_template';
  49:     const XML_PATH_GENERATE_HUMAN_FRIENDLY_ID   = 'customer/create_account/generate_human_friendly_id';
  50: 
  51:     /**
  52:      * Codes of exceptions related to customer model
  53:      */
  54:     const EXCEPTION_EMAIL_NOT_CONFIRMED       = 1;
  55:     const EXCEPTION_INVALID_EMAIL_OR_PASSWORD = 2;
  56:     const EXCEPTION_EMAIL_EXISTS              = 3;
  57:     const EXCEPTION_INVALID_RESET_PASSWORD_LINK_TOKEN = 4;
  58: 
  59:     const SUBSCRIBED_YES = 'yes';
  60:     const SUBSCRIBED_NO  = 'no';
  61: 
  62:     /**
  63:      * Model event prefix
  64:      *
  65:      * @var string
  66:      */
  67:     protected $_eventPrefix = 'customer';
  68: 
  69:     /**
  70:      * Name of the event object
  71:      *
  72:      * @var string
  73:      */
  74:     protected $_eventObject = 'customer';
  75: 
  76:     /**
  77:      * List of errors
  78:      *
  79:      * @var array
  80:      */
  81:     protected $_errors = array();
  82: 
  83:     /**
  84:      * Assoc array of customer attributes
  85:      *
  86:      * @var array
  87:      */
  88:     protected $_attributes;
  89: 
  90:     /**
  91:      * Customer addresses array
  92:      *
  93:      * @var array
  94:      * @deprecated after 1.4.0.0-rc1
  95:      */
  96:     protected $_addresses = null;
  97: 
  98:     /**
  99:      * Customer addresses collection
 100:      *
 101:      * @var Mage_Customer_Model_Entity_Address_Collection
 102:      */
 103:     protected $_addressesCollection;
 104: 
 105:     /**
 106:      * Is model deleteable
 107:      *
 108:      * @var boolean
 109:      */
 110:     protected $_isDeleteable = true;
 111: 
 112:     /**
 113:      * Is model readonly
 114:      *
 115:      * @var boolean
 116:      */
 117:     protected $_isReadonly = false;
 118: 
 119:     /**
 120:      * Confirmation requirement flag
 121:      *
 122:      * @var boolean
 123:      */
 124:     private static $_isConfirmationRequired;
 125: 
 126:     /**
 127:      * Initialize customer model
 128:      */
 129:     function _construct()
 130:     {
 131:         $this->_init('customer/customer');
 132:     }
 133: 
 134:     /**
 135:      * Retrieve customer sharing configuration model
 136:      *
 137:      * @return Mage_Customer_Model_Config_Share
 138:      */
 139:     public function getSharingConfig()
 140:     {
 141:         return Mage::getSingleton('customer/config_share');
 142:     }
 143: 
 144:     /**
 145:      * Authenticate customer
 146:      *
 147:      * @param  string $login
 148:      * @param  string $password
 149:      * @throws Mage_Core_Exception
 150:      * @return true
 151:      *
 152:      */
 153:     public function authenticate($login, $password)
 154:     {
 155:         $this->loadByEmail($login);
 156:         if ($this->getConfirmation() && $this->isConfirmationRequired()) {
 157:             throw Mage::exception('Mage_Core', Mage::helper('customer')->__('This account is not confirmed.'),
 158:                 self::EXCEPTION_EMAIL_NOT_CONFIRMED
 159:             );
 160:         }
 161:         if (!$this->validatePassword($password)) {
 162:             throw Mage::exception('Mage_Core', Mage::helper('customer')->__('Invalid login or password.'),
 163:                 self::EXCEPTION_INVALID_EMAIL_OR_PASSWORD
 164:             );
 165:         }
 166:         Mage::dispatchEvent('customer_customer_authenticated', array(
 167:            'model'    => $this,
 168:            'password' => $password,
 169:         ));
 170: 
 171:         return true;
 172:     }
 173: 
 174:     /**
 175:      * Load customer by email
 176:      *
 177:      * @param   string $customerEmail
 178:      * @return  Mage_Customer_Model_Customer
 179:      */
 180:     public function loadByEmail($customerEmail)
 181:     {
 182:         $this->_getResource()->loadByEmail($this, $customerEmail);
 183:         return $this;
 184:     }
 185: 
 186: 
 187:     /**
 188:      * Processing object before save data
 189:      *
 190:      * @return Mage_Customer_Model_Customer
 191:      */
 192:     protected function _beforeSave()
 193:     {
 194:         parent::_beforeSave();
 195: 
 196:         $storeId = $this->getStoreId();
 197:         if ($storeId === null) {
 198:             $this->setStoreId(Mage::app()->getStore()->getId());
 199:         }
 200: 
 201:         $this->getGroupId();
 202:         return $this;
 203:     }
 204: 
 205:     /**
 206:      * Change customer password
 207:      *
 208:      * @param   string $newPassword
 209:      * @return  Mage_Customer_Model_Customer
 210:      */
 211:     public function changePassword($newPassword)
 212:     {
 213:         $this->_getResource()->changePassword($this, $newPassword);
 214:         return $this;
 215:     }
 216: 
 217:     /**
 218:      * Get full customer name
 219:      *
 220:      * @return string
 221:      */
 222:     public function getName()
 223:     {
 224:         $name = '';
 225:         $config = Mage::getSingleton('eav/config');
 226:         if ($config->getAttribute('customer', 'prefix')->getIsVisible() && $this->getPrefix()) {
 227:             $name .= $this->getPrefix() . ' ';
 228:         }
 229:         $name .= $this->getFirstname();
 230:         if ($config->getAttribute('customer', 'middlename')->getIsVisible() && $this->getMiddlename()) {
 231:             $name .= ' ' . $this->getMiddlename();
 232:         }
 233:         $name .=  ' ' . $this->getLastname();
 234:         if ($config->getAttribute('customer', 'suffix')->getIsVisible() && $this->getSuffix()) {
 235:             $name .= ' ' . $this->getSuffix();
 236:         }
 237:         return $name;
 238:     }
 239: 
 240:     /**
 241:      * Add address to address collection
 242:      *
 243:      * @param   Mage_Customer_Model_Address $address
 244:      * @return  Mage_Customer_Model_Customer
 245:      */
 246:     public function addAddress(Mage_Customer_Model_Address $address)
 247:     {
 248:         $this->getAddressesCollection()->addItem($address);
 249:         $this->getAddresses();
 250:         $this->_addresses[] = $address;
 251:         return $this;
 252:     }
 253: 
 254:     /**
 255:      * Retrieve customer address by address id
 256:      *
 257:      * @param   int $addressId
 258:      * @return  Mage_Customer_Model_Address
 259:      */
 260:     public function getAddressById($addressId)
 261:     {
 262:         return Mage::getModel('customer/address')
 263:             ->load($addressId);
 264:     }
 265: 
 266:     /**
 267:      * Getting customer address object from collection by identifier
 268:      *
 269:      * @param int $addressId
 270:      * @return Mage_Customer_Model_Address
 271:      */
 272:     public function getAddressItemById($addressId)
 273:     {
 274:         return $this->getAddressesCollection()->getItemById($addressId);
 275:     }
 276: 
 277:     /**
 278:      * Retrieve not loaded address collection
 279:      *
 280:      * @return Mage_Customer_Model_Entity_Address_Collection
 281:      */
 282:     public function getAddressCollection()
 283:     {
 284:         return Mage::getResourceModel('customer/address_collection');
 285:     }
 286: 
 287:     /**
 288:      * Customer addresses collection
 289:      *
 290:      * @return Mage_Customer_Model_Entity_Address_Collection
 291:      */
 292:     public function getAddressesCollection()
 293:     {
 294:         if ($this->_addressesCollection === null) {
 295:             $this->_addressesCollection = $this->getAddressCollection()
 296:                 ->setCustomerFilter($this)
 297:                 ->addAttributeToSelect('*');
 298:             foreach ($this->_addressesCollection as $address) {
 299:                 $address->setCustomer($this);
 300:             }
 301:         }
 302: 
 303:         return $this->_addressesCollection;
 304:     }
 305: 
 306:     /**
 307:      * Retrieve customer address array
 308:      *
 309:      * @return array
 310:      */
 311:     public function getAddresses()
 312:     {
 313:         $this->_addresses = $this->getAddressesCollection()->getItems();
 314:         return $this->_addresses;
 315:     }
 316: 
 317:     /**
 318:      * Retrieve all customer attributes
 319:      *
 320:      * @return array
 321:      */
 322:     public function getAttributes()
 323:     {
 324:         if ($this->_attributes === null) {
 325:             $this->_attributes = $this->_getResource()
 326:             ->loadAllAttributes($this)
 327:             ->getSortedAttributes();
 328:         }
 329:         return $this->_attributes;
 330:     }
 331: 
 332:     /**
 333:      * Get customer attribute model object
 334:      *
 335:      * @param   string $attributeCode
 336:      * @return  Mage_Customer_Model_Entity_Attribute | null
 337:      */
 338:     public function getAttribute($attributeCode)
 339:     {
 340:         $this->getAttributes();
 341:         if (isset($this->_attributes[$attributeCode])) {
 342:             return $this->_attributes[$attributeCode];
 343:         }
 344:         return null;
 345:     }
 346: 
 347:     /**
 348:      * Set plain and hashed password
 349:      *
 350:      * @param string $password
 351:      * @return Mage_Customer_Model_Customer
 352:      */
 353:     public function setPassword($password)
 354:     {
 355:         $this->setData('password', $password);
 356:         $this->setPasswordHash($this->hashPassword($password));
 357:         return $this;
 358:     }
 359: 
 360:     /**
 361:      * Hash customer password
 362:      *
 363:      * @param   string $password
 364:      * @param   int    $salt
 365:      * @return  string
 366:      */
 367:     public function hashPassword($password, $salt = null)
 368:     {
 369:         return Mage::helper('core')->getHash($password, !is_null($salt) ? $salt : 2);
 370:     }
 371: 
 372:     /**
 373:      * Retrieve random password
 374:      *
 375:      * @param   int $length
 376:      * @return  string
 377:      */
 378:     public function generatePassword($length = 8)
 379:     {
 380:         $chars = Mage_Core_Helper_Data::CHARS_PASSWORD_LOWERS
 381:             . Mage_Core_Helper_Data::CHARS_PASSWORD_UPPERS
 382:             . Mage_Core_Helper_Data::CHARS_PASSWORD_DIGITS
 383:             . Mage_Core_Helper_Data::CHARS_PASSWORD_SPECIALS;
 384:         return Mage::helper('core')->getRandomString($length, $chars);
 385:     }
 386: 
 387:     /**
 388:      * Validate password with salted hash
 389:      *
 390:      * @param string $password
 391:      * @return boolean
 392:      */
 393:     public function validatePassword($password)
 394:     {
 395:         $hash = $this->getPasswordHash();
 396:         if (!$hash) {
 397:             return false;
 398:         }
 399:         return Mage::helper('core')->validateHash($password, $hash);
 400:     }
 401: 
 402: 
 403:     /**
 404:      * Encrypt password
 405:      *
 406:      * @param   string $password
 407:      * @return  string
 408:      */
 409:     public function encryptPassword($password)
 410:     {
 411:         return Mage::helper('core')->encrypt($password);
 412:     }
 413: 
 414:     /**
 415:      * Decrypt password
 416:      *
 417:      * @param   string $password
 418:      * @return  string
 419:      */
 420:     public function decryptPassword($password)
 421:     {
 422:         return Mage::helper('core')->decrypt($password);
 423:     }
 424: 
 425:     /**
 426:      * Retrieve default address by type(attribute)
 427:      *
 428:      * @param   string $attributeCode address type attribute code
 429:      * @return  Mage_Customer_Model_Address
 430:      */
 431:     public function getPrimaryAddress($attributeCode)
 432:     {
 433:         $primaryAddress = $this->getAddressesCollection()->getItemById($this->getData($attributeCode));
 434: 
 435:         return $primaryAddress ? $primaryAddress : false;
 436:     }
 437: 
 438:     /**
 439:      * Get customer default billing address
 440:      *
 441:      * @return Mage_Customer_Model_Address
 442:      */
 443:     public function getPrimaryBillingAddress()
 444:     {
 445:         return $this->getPrimaryAddress('default_billing');
 446:     }
 447: 
 448:     /**
 449:      * Get customer default billing address
 450:      *
 451:      * @return Mage_Customer_Model_Address
 452:      */
 453:     public function getDefaultBillingAddress()
 454:     {
 455:         return $this->getPrimaryBillingAddress();
 456:     }
 457: 
 458:     /**
 459:      * Get default customer shipping address
 460:      *
 461:      * @return Mage_Customer_Model_Address
 462:      */
 463:     public function getPrimaryShippingAddress()
 464:     {
 465:         return $this->getPrimaryAddress('default_shipping');
 466:     }
 467: 
 468:     /**
 469:      * Get default customer shipping address
 470:      *
 471:      * @return Mage_Customer_Model_Address
 472:      */
 473:     public function getDefaultShippingAddress()
 474:     {
 475:         return $this->getPrimaryShippingAddress();
 476:     }
 477: 
 478:     /**
 479:      * Retrieve ids of default addresses
 480:      *
 481:      * @return array
 482:      */
 483:     public function getPrimaryAddressIds()
 484:     {
 485:         $ids = array();
 486:         if ($this->getDefaultBilling()) {
 487:             $ids[] = $this->getDefaultBilling();
 488:         }
 489:         if ($this->getDefaultShipping()) {
 490:             $ids[] = $this->getDefaultShipping();
 491:         }
 492:         return $ids;
 493:     }
 494: 
 495:     /**
 496:      * Retrieve all customer default addresses
 497:      *
 498:      * @return array
 499:      */
 500:     public function getPrimaryAddresses()
 501:     {
 502:         $addresses = array();
 503:         $primaryBilling = $this->getPrimaryBillingAddress();
 504:         if ($primaryBilling) {
 505:             $addresses[] = $primaryBilling;
 506:             $primaryBilling->setIsPrimaryBilling(true);
 507:         }
 508: 
 509:         $primaryShipping = $this->getPrimaryShippingAddress();
 510:         if ($primaryShipping) {
 511:             if ($primaryBilling->getId() == $primaryShipping->getId()) {
 512:                 $primaryBilling->setIsPrimaryShipping(true);
 513:             } else {
 514:                 $primaryShipping->setIsPrimaryShipping(true);
 515:                 $addresses[] = $primaryShipping;
 516:             }
 517:         }
 518:         return $addresses;
 519:     }
 520: 
 521:     /**
 522:      * Retrieve not default addresses
 523:      *
 524:      * @return array
 525:      */
 526:     public function getAdditionalAddresses()
 527:     {
 528:         $addresses = array();
 529:         $primatyIds = $this->getPrimaryAddressIds();
 530:         foreach ($this->getAddressesCollection() as $address) {
 531:             if (!in_array($address->getId(), $primatyIds)) {
 532:                 $addresses[] = $address;
 533:             }
 534:         }
 535:         return $addresses;
 536:     }
 537: 
 538:     /**
 539:      * Check if address is primary
 540:      *
 541:      * @param Mage_Customer_Model_Address $address
 542:      * @return boolean
 543:      */
 544:     public function isAddressPrimary(Mage_Customer_Model_Address $address)
 545:     {
 546:         if (!$address->getId()) {
 547:             return false;
 548:         }
 549:         return ($address->getId() == $this->getDefaultBilling()) || ($address->getId() == $this->getDefaultShipping());
 550:     }
 551: 
 552:     /**
 553:      * Send email with new account related information
 554:      *
 555:      * @param string $type
 556:      * @param string $backUrl
 557:      * @param string $storeId
 558:      * @throws Mage_Core_Exception
 559:      * @return Mage_Customer_Model_Customer
 560:      */
 561:     public function sendNewAccountEmail($type = 'registered', $backUrl = '', $storeId = '0')
 562:     {
 563:         $types = array(
 564:             'registered'   => self::XML_PATH_REGISTER_EMAIL_TEMPLATE,  // welcome email, when confirmation is disabled
 565:             'confirmed'    => self::XML_PATH_CONFIRMED_EMAIL_TEMPLATE, // welcome email, when confirmation is enabled
 566:             'confirmation' => self::XML_PATH_CONFIRM_EMAIL_TEMPLATE,   // email with confirmation link
 567:         );
 568:         if (!isset($types[$type])) {
 569:             Mage::throwException(Mage::helper('customer')->__('Wrong transactional account email type'));
 570:         }
 571: 
 572:         if (!$storeId) {
 573:             $storeId = $this->_getWebsiteStoreId($this->getSendemailStoreId());
 574:         }
 575: 
 576:         $this->_sendEmailTemplate($types[$type], self::XML_PATH_REGISTER_EMAIL_IDENTITY,
 577:             array('customer' => $this, 'back_url' => $backUrl), $storeId);
 578: 
 579:         return $this;
 580:     }
 581: 
 582:     /**
 583:      * Check if accounts confirmation is required in config
 584:      *
 585:      * @return bool
 586:      */
 587:     public function isConfirmationRequired()
 588:     {
 589:         if ($this->canSkipConfirmation()) {
 590:             return false;
 591:         }
 592:         if (self::$_isConfirmationRequired === null) {
 593:             $storeId = $this->getStoreId() ? $this->getStoreId() : null;
 594:             self::$_isConfirmationRequired = (bool)Mage::getStoreConfig(self::XML_PATH_IS_CONFIRM, $storeId);
 595:         }
 596: 
 597:         return self::$_isConfirmationRequired;
 598:     }
 599: 
 600:     /**
 601:      * Generate random confirmation key
 602:      *
 603:      * @return string
 604:      */
 605:     public function getRandomConfirmationKey()
 606:     {
 607:         return md5(uniqid());
 608:     }
 609: 
 610:     /**
 611:      * Send email with new customer password
 612:      *
 613:      * @return Mage_Customer_Model_Customer
 614:      */
 615:     public function sendPasswordReminderEmail()
 616:     {
 617:         $storeId = $this->getStoreId();
 618:         if (!$storeId) {
 619:             $storeId = $this->_getWebsiteStoreId();
 620:         }
 621: 
 622:         $this->_sendEmailTemplate(self::XML_PATH_REMIND_EMAIL_TEMPLATE, self::XML_PATH_FORGOT_EMAIL_IDENTITY,
 623:             array('customer' => $this), $storeId);
 624: 
 625:         return $this;
 626:     }
 627: 
 628:     /**
 629:      * Send corresponding email template
 630:      *
 631:      * @param string $emailTemplate configuration path of email template
 632:      * @param string $emailSender configuration path of email identity
 633:      * @param array $templateParams
 634:      * @param int|null $storeId
 635:      * @return Mage_Customer_Model_Customer
 636:      */
 637:     protected function _sendEmailTemplate($template, $sender, $templateParams = array(), $storeId = null)
 638:     {
 639:         /** @var $mailer Mage_Core_Model_Email_Template_Mailer */
 640:         $mailer = Mage::getModel('core/email_template_mailer');
 641:         $emailInfo = Mage::getModel('core/email_info');
 642:         $emailInfo->addTo($this->getEmail(), $this->getName());
 643:         $mailer->addEmailInfo($emailInfo);
 644: 
 645:         // Set all required params and send emails
 646:         $mailer->setSender(Mage::getStoreConfig($sender, $storeId));
 647:         $mailer->setStoreId($storeId);
 648:         $mailer->setTemplateId(Mage::getStoreConfig($template, $storeId));
 649:         $mailer->setTemplateParams($templateParams);
 650:         $mailer->send();
 651:         return $this;
 652:     }
 653: 
 654:     /**
 655:      * Send email with reset password confirmation link
 656:      *
 657:      * @return Mage_Customer_Model_Customer
 658:      */
 659:     public function sendPasswordResetConfirmationEmail()
 660:     {
 661:         $storeId = $this->getStoreId();
 662:         if (!$storeId) {
 663:             $storeId = $this->_getWebsiteStoreId();
 664:         }
 665: 
 666:         $this->_sendEmailTemplate(self::XML_PATH_FORGOT_EMAIL_TEMPLATE, self::XML_PATH_FORGOT_EMAIL_IDENTITY,
 667:             array('customer' => $this), $storeId);
 668: 
 669:         return $this;
 670:     }
 671: 
 672:     /**
 673:      * Retrieve customer group identifier
 674:      *
 675:      * @return int
 676:      */
 677:     public function getGroupId()
 678:     {
 679:         if (!$this->hasData('group_id')) {
 680:             $storeId = $this->getStoreId() ? $this->getStoreId() : Mage::app()->getStore()->getId();
 681:             $groupId = Mage::getStoreConfig(Mage_Customer_Model_Group::XML_PATH_DEFAULT_ID, $storeId);
 682:             $this->setData('group_id', $groupId);
 683:         }
 684:         return $this->getData('group_id');
 685:     }
 686: 
 687:     /**
 688:      * Retrieve customer tax class identifier
 689:      *
 690:      * @return int
 691:      */
 692:     public function getTaxClassId()
 693:     {
 694:         if (!$this->getData('tax_class_id')) {
 695:             $this->setTaxClassId(Mage::getModel('customer/group')->getTaxClassId($this->getGroupId()));
 696:         }
 697:         return $this->getData('tax_class_id');
 698:     }
 699: 
 700:     /**
 701:      * Check store availability for customer
 702:      *
 703:      * @param   Mage_Core_Model_Store | int $store
 704:      * @return  bool
 705:      */
 706:     public function isInStore($store)
 707:     {
 708:         if ($store instanceof Mage_Core_Model_Store) {
 709:             $storeId = $store->getId();
 710:         } else {
 711:             $storeId = $store;
 712:         }
 713: 
 714:         $availableStores = $this->getSharedStoreIds();
 715:         return in_array($storeId, $availableStores);
 716:     }
 717: 
 718:     /**
 719:      * Retrieve store where customer was created
 720:      *
 721:      * @return Mage_Core_Model_Store
 722:      */
 723:     public function getStore()
 724:     {
 725:         return Mage::app()->getStore($this->getStoreId());
 726:     }
 727: 
 728:     /**
 729:      * Retrieve shared store ids
 730:      *
 731:      * @return array
 732:      */
 733:     public function getSharedStoreIds()
 734:     {
 735:         $ids = $this->_getData('shared_store_ids');
 736:         if ($ids === null) {
 737:             $ids = array();
 738:             if ((bool)$this->getSharingConfig()->isWebsiteScope()) {
 739:                 $ids = Mage::app()->getWebsite($this->getWebsiteId())->getStoreIds();
 740:             } else {
 741:                 foreach (Mage::app()->getStores() as $store) {
 742:                     $ids[] = $store->getId();
 743:                 }
 744:             }
 745:             $this->setData('shared_store_ids', $ids);
 746:         }
 747: 
 748:         return $ids;
 749:     }
 750: 
 751:     /**
 752:      * Retrive shared website ids
 753:      *
 754:      * @return array
 755:      */
 756:     public function getSharedWebsiteIds()
 757:     {
 758:         $ids = $this->_getData('shared_website_ids');
 759:         if ($ids === null) {
 760:             $ids = array();
 761:             if ((bool)$this->getSharingConfig()->isWebsiteScope()) {
 762:                 $ids[] = $this->getWebsiteId();
 763:             } else {
 764:                 foreach (Mage::app()->getWebsites() as $website) {
 765:                     $ids[] = $website->getId();
 766:                 }
 767:             }
 768:             $this->setData('shared_website_ids', $ids);
 769:         }
 770:         return $ids;
 771:     }
 772: 
 773:     /**
 774:      * Set store to customer
 775:      *
 776:      * @param Mage_Core_Model_Store $store
 777:      * @return Mage_Customer_Model_Customer
 778:      */
 779:     public function setStore(Mage_Core_Model_Store $store)
 780:     {
 781:         $this->setStoreId($store->getId());
 782:         $this->setWebsiteId($store->getWebsite()->getId());
 783:         return $this;
 784:     }
 785: 
 786:     /**
 787:      * Validate customer attribute values.
 788:      * For existing customer password + confirmation will be validated only when password is set (i.e. its change is requested)
 789:      *
 790:      * @return bool
 791:      */
 792:     public function validate()
 793:     {
 794:         $errors = array();
 795:         if (!Zend_Validate::is( trim($this->getFirstname()) , 'NotEmpty')) {
 796:             $errors[] = Mage::helper('customer')->__('The first name cannot be empty.');
 797:         }
 798: 
 799:         if (!Zend_Validate::is( trim($this->getLastname()) , 'NotEmpty')) {
 800:             $errors[] = Mage::helper('customer')->__('The last name cannot be empty.');
 801:         }
 802: 
 803:         if (!Zend_Validate::is($this->getEmail(), 'EmailAddress')) {
 804:             $errors[] = Mage::helper('customer')->__('Invalid email address "%s".', $this->getEmail());
 805:         }
 806: 
 807:         $password = $this->getPassword();
 808:         if (!$this->getId() && !Zend_Validate::is($password , 'NotEmpty')) {
 809:             $errors[] = Mage::helper('customer')->__('The password cannot be empty.');
 810:         }
 811:         if (strlen($password) && !Zend_Validate::is($password, 'StringLength', array(6))) {
 812:             $errors[] = Mage::helper('customer')->__('The minimum password length is %s', 6);
 813:         }
 814:         $confirmation = $this->getConfirmation();
 815:         if ($password != $confirmation) {
 816:             $errors[] = Mage::helper('customer')->__('Please make sure your passwords match.');
 817:         }
 818: 
 819:         $entityType = Mage::getSingleton('eav/config')->getEntityType('customer');
 820:         $attribute = Mage::getModel('customer/attribute')->loadByCode($entityType, 'dob');
 821:         if ($attribute->getIsRequired() && '' == trim($this->getDob())) {
 822:             $errors[] = Mage::helper('customer')->__('The Date of Birth is required.');
 823:         }
 824:         $attribute = Mage::getModel('customer/attribute')->loadByCode($entityType, 'taxvat');
 825:         if ($attribute->getIsRequired() && '' == trim($this->getTaxvat())) {
 826:             $errors[] = Mage::helper('customer')->__('The TAX/VAT number is required.');
 827:         }
 828:         $attribute = Mage::getModel('customer/attribute')->loadByCode($entityType, 'gender');
 829:         if ($attribute->getIsRequired() && '' == trim($this->getGender())) {
 830:             $errors[] = Mage::helper('customer')->__('Gender is required.');
 831:         }
 832: 
 833:         if (empty($errors)) {
 834:             return true;
 835:         }
 836:         return $errors;
 837:     }
 838: 
 839:     /**
 840:      * Import customer data from text array
 841:      *
 842:      * @param array $row
 843:      * @return Mage_Customer_Model_Customer
 844:      */
 845:     public function importFromTextArray(array $row)
 846:     {
 847:         $this->resetErrors();
 848:         $line = $row['i'];
 849:         $row = $row['row'];
 850: 
 851:         $regions = Mage::getResourceModel('directory/region_collection');
 852: 
 853:         $website = Mage::getModel('core/website')->load($row['website_code'], 'code');
 854: 
 855:         if (!$website->getId()) {
 856:             $this->addError(Mage::helper('customer')->__('Invalid website, skipping the record, line: %s', $line));
 857: 
 858:         } else {
 859:             $row['website_id'] = $website->getWebsiteId();
 860:             $this->setWebsiteId($row['website_id']);
 861:         }
 862: 
 863:         // Validate Email
 864:         if (empty($row['email'])) {
 865:             $this->addError(Mage::helper('customer')->__('Missing email, skipping the record, line: %s', $line));
 866:         } else {
 867:             $this->loadByEmail($row['email']);
 868:         }
 869: 
 870:         if (empty($row['entity_id'])) {
 871:             if ($this->getData('entity_id')) {
 872:                 $this->addError(Mage::helper('customer')->__('The customer email (%s) already exists, skipping the record, line: %s', $row['email'], $line));
 873:             }
 874:         } else {
 875:             if ($row['entity_id'] != $this->getData('entity_id')) {
 876:                 $this->addError(Mage::helper('customer')->__('The customer ID and email did not match, skipping the record, line: %s', $line));
 877:             } else {
 878:                 $this->unsetData();
 879:                 $this->load($row['entity_id']);
 880:                 if (isset($row['store_view'])) {
 881:                     $storeId = Mage::app()->getStore($row['store_view'])->getId();
 882:                     if ($storeId) $this->setStoreId($storeId);
 883:                 }
 884:             }
 885:         }
 886: 
 887:         if (empty($row['website_code'])) {
 888:             $this->addError(Mage::helper('customer')->__('Missing website, skipping the record, line: %s', $line));
 889:         }
 890: 
 891:         if (empty($row['group'])) {
 892:             $row['group'] = 'General';
 893:         }
 894: 
 895:         if (empty($row['firstname'])) {
 896:             $this->addError(Mage::helper('customer')->__('Missing first name, skipping the record, line: %s', $line));
 897:         }
 898:         if (empty($row['lastname'])) {
 899:             $this->addError(Mage::helper('customer')->__('Missing last name, skipping the record, line: %s', $line));
 900:         }
 901: 
 902:         if (!empty($row['password_new'])) {
 903:             $this->setPassword($row['password_new']);
 904:             unset($row['password_new']);
 905:             if (!empty($row['password_hash'])) unset($row['password_hash']);
 906:         }
 907: 
 908:         $errors = $this->getErrors();
 909:         if ($errors) {
 910:             $this->unsetData();
 911:             $this->printError(implode('<br />', $errors));
 912:             return;
 913:         }
 914: 
 915:         foreach ($row as $field => $value) {
 916:             $this->setData($field, $value);
 917:         }
 918: 
 919:         if (!$this->validateAddress($row, 'billing')) {
 920:             $this->printError(Mage::helper('customer')->__('Invalid billing address for (%s)', $row['email']), $line);
 921:         } else {
 922:             // Handling billing address
 923:             $billingAddress = $this->getPrimaryBillingAddress();
 924:             if (!$billingAddress  instanceof Mage_Customer_Model_Address) {
 925:                 $billingAddress = Mage::getModel('customer/address');
 926:             }
 927: 
 928:             $regions->addRegionNameFilter($row['billing_region'])->load();
 929:             if ($regions) foreach($regions as $region) {
 930:                 $regionId = intval($region->getId());
 931:             }
 932: 
 933:             $billingAddress->setFirstname($row['firstname']);
 934:             $billingAddress->setLastname($row['lastname']);
 935:             $billingAddress->setCity($row['billing_city']);
 936:             $billingAddress->setRegion($row['billing_region']);
 937:             if (isset($regionId)) {
 938:                 $billingAddress->setRegionId($regionId);
 939:             }
 940:             $billingAddress->setCountryId($row['billing_country']);
 941:             $billingAddress->setPostcode($row['billing_postcode']);
 942:             if (isset($row['billing_street2'])) {
 943:                 $billingAddress->setStreet(array($row['billing_street1'], $row['billing_street2']));
 944:             } else {
 945:                 $billingAddress->setStreet(array($row['billing_street1']));
 946:             }
 947:             if (isset($row['billing_telephone'])) {
 948:                 $billingAddress->setTelephone($row['billing_telephone']);
 949:             }
 950: 
 951:             if (!$billingAddress->getId()) {
 952:                 $billingAddress->setIsDefaultBilling(true);
 953:                 if ($this->getDefaultBilling()) {
 954:                     $this->setData('default_billing', '');
 955:                 }
 956:                 $this->addAddress($billingAddress);
 957:             } // End handling billing address
 958:         }
 959: 
 960:         if (!$this->validateAddress($row, 'shipping')) {
 961:             $this->printError(Mage::helper('customer')->__('Invalid shipping address for (%s)', $row['email']), $line);
 962:         } else {
 963:             // Handling shipping address
 964:             $shippingAddress = $this->getPrimaryShippingAddress();
 965:             if (!$shippingAddress instanceof Mage_Customer_Model_Address) {
 966:                 $shippingAddress = Mage::getModel('customer/address');
 967:             }
 968: 
 969:             $regions->addRegionNameFilter($row['shipping_region'])->load();
 970: 
 971:             if ($regions) foreach($regions as $region) {
 972:                $regionId = intval($region->getId());
 973:             }
 974: 
 975:             $shippingAddress->setFirstname($row['firstname']);
 976:             $shippingAddress->setLastname($row['lastname']);
 977:             $shippingAddress->setCity($row['shipping_city']);
 978:             $shippingAddress->setRegion($row['shipping_region']);
 979:             if (isset($regionId)) {
 980:                 $shippingAddress->setRegionId($regionId);
 981:             }
 982:             $shippingAddress->setCountryId($row['shipping_country']);
 983:             $shippingAddress->setPostcode($row['shipping_postcode']);
 984:             if (isset($row['shipping_street2'])) {
 985:                 $shippingAddress->setStreet(array($row['shipping_street1'], $row['shipping_street2']));
 986:             } else {
 987:                 $shippingAddress->setStreet(array($row['shipping_street1']));
 988:             }
 989:             if (!empty($row['shipping_telephone'])) {
 990:                 $shippingAddress->setTelephone($row['shipping_telephone']);
 991:             }
 992: 
 993:             if (!$shippingAddress->getId()) {
 994:                $shippingAddress->setIsDefaultShipping(true);
 995:                $this->addAddress($shippingAddress);
 996:             }
 997:             // End handling shipping address
 998:         }
 999:         if (!empty($row['is_subscribed'])) {
1000:             $isSubscribed = (bool)strtolower($row['is_subscribed']) == self::SUBSCRIBED_YES;
1001:             $this->setIsSubscribed($isSubscribed);
1002:         }
1003:         unset($row);
1004:         return $this;
1005:     }
1006: 
1007:     /**
1008:      * Unset subscription
1009:      *
1010:      * @return Mage_Customer_Model_Customer
1011:      */
1012:     function unsetSubscription()
1013:     {
1014:         if (isset($this->_isSubscribed)) {
1015:             unset($this->_isSubscribed);
1016:         }
1017:         return $this;
1018:     }
1019: 
1020:     /**
1021:      * Clean all addresses
1022:      *
1023:      * @return Mage_Customer_Model_Customer
1024:      */
1025:     function cleanAllAddresses() {
1026:         $this->_addressesCollection = null;
1027:         $this->_addresses           = null;
1028:     }
1029: 
1030:     /**
1031:      * Add error
1032:      *
1033:      * @return Mage_Customer_Model_Customer
1034:      */
1035:     function addError($error)
1036:     {
1037:         $this->_errors[] = $error;
1038:         return $this;
1039:     }
1040: 
1041:     /**
1042:      * Retreive errors
1043:      *
1044:      * @return array
1045:      */
1046:     function getErrors()
1047:     {
1048:         return $this->_errors;
1049:     }
1050: 
1051:     /**
1052:      * Reset errors array
1053:      *
1054:      * @return Mage_Customer_Model_Customer
1055:      */
1056:     function resetErrors()
1057:     {
1058:         $this->_errors = array();
1059:         return $this;
1060:     }
1061: 
1062:     /**
1063:      * Print error
1064:      *
1065:      * @param $error
1066:      * @param $line
1067:      * @return boolean
1068:      */
1069:     function printError($error, $line = null)
1070:     {
1071:         if ($error == null) {
1072:             return false;
1073:         }
1074: 
1075:         $liStyle = 'background-color: #FDD; ';
1076:         echo '<li style="' . $liStyle . '">';
1077:         echo '<img src="' . Mage::getDesign()->getSkinUrl('images/error_msg_icon.gif') . '" class="v-middle"/>';
1078:         echo $error;
1079:         if ($line) {
1080:             echo '<small>, Line: <b>' . $line . '</b></small>';
1081:         }
1082:         echo '</li>';
1083:     }
1084: 
1085:     /**
1086:      * Validate address
1087:      *
1088:      * @param array $data
1089:      * @param string $type
1090:      * @return bool
1091:      */
1092:     function validateAddress(array $data, $type = 'billing')
1093:     {
1094:         $fields = array('city', 'country', 'postcode', 'telephone', 'street1');
1095:         $usca   = array('US', 'CA');
1096:         $prefix = $type ? $type . '_' : '';
1097: 
1098:         if ($data) {
1099:             foreach($fields as $field) {
1100:                 if (!isset($data[$prefix . $field])) {
1101:                     return false;
1102:                 }
1103:                 if ($field == 'country'
1104:                     && in_array(strtolower($data[$prefix . $field]), array('US', 'CA'))) {
1105: 
1106:                     if (!isset($data[$prefix . 'region'])) {
1107:                         return false;
1108:                     }
1109: 
1110:                     $region = Mage::getModel('directory/region')
1111:                         ->loadByName($data[$prefix . 'region']);
1112:                     if (!$region->getId()) {
1113:                         return false;
1114:                     }
1115:                     unset($region);
1116:                 }
1117:             }
1118:             unset($data);
1119:             return true;
1120:         }
1121:         return false;
1122:     }
1123: 
1124:     /**
1125:      * Prepare customer for delete
1126:      */
1127:     protected function _beforeDelete()
1128:     {
1129:         $this->_protectFromNonAdmin();
1130:         return parent::_beforeDelete();
1131:     }
1132: 
1133:     /**
1134:      * Get customer created at date timestamp
1135:      *
1136:      * @return int|null
1137:      */
1138:     public function getCreatedAtTimestamp()
1139:     {
1140:         $date = $this->getCreatedAt();
1141:         if ($date) {
1142:             return Varien_Date::toTimestamp($date);
1143:         }
1144:         return null;
1145:     }
1146: 
1147:     /**
1148:      * Reset all model data
1149:      *
1150:      * @return Mage_Customer_Model_Customer
1151:      */
1152:     public function reset()
1153:     {
1154:         $this->setData(array());
1155:         $this->setOrigData();
1156:         $this->_attributes = null;
1157: 
1158:         return $this;
1159:     }
1160: 
1161:     /**
1162:      * Checks model is deleteable
1163:      *
1164:      * @return boolean
1165:      */
1166:     public function isDeleteable()
1167:     {
1168:         return $this->_isDeleteable;
1169:     }
1170: 
1171:     /**
1172:      * Set is deleteable flag
1173:      *
1174:      * @param boolean $value
1175:      * @return Mage_Customer_Model_Customer
1176:      */
1177:     public function setIsDeleteable($value)
1178:     {
1179:         $this->_isDeleteable = (bool)$value;
1180:         return $this;
1181:     }
1182: 
1183:     /**
1184:      * Checks model is readonly
1185:      *
1186:      * @return boolean
1187:      */
1188:     public function isReadonly()
1189:     {
1190:         return $this->_isReadonly;
1191:     }
1192: 
1193:     /**
1194:      * Set is readonly flag
1195:      *
1196:      * @param boolean $value
1197:      * @return Mage_Customer_Model_Customer
1198:      */
1199:     public function setIsReadonly($value)
1200:     {
1201:         $this->_isReadonly = (bool)$value;
1202:         return $this;
1203:     }
1204: 
1205:     /**
1206:      * Check whether confirmation may be skipped when registering using certain email address
1207:      *
1208:      * @return bool
1209:      */
1210:     public function canSkipConfirmation()
1211:     {
1212:         return $this->getId() && $this->hasSkipConfirmationIfEmail()
1213:             && strtolower($this->getSkipConfirmationIfEmail()) === strtolower($this->getEmail());
1214:     }
1215: 
1216:     /**
1217:      * Clone current object
1218:      */
1219:     public function __clone()
1220:     {
1221:         $newAddressCollection = $this->getPrimaryAddresses();
1222:         $newAddressCollection = array_merge($newAddressCollection, $this->getAdditionalAddresses());
1223:         $this->setId(null);
1224:         $this->cleanAllAddresses();
1225:         foreach ($newAddressCollection as $address) {
1226:             $this->addAddress(clone $address);
1227:         }
1228:     }
1229: 
1230:     /**
1231:      * Return Entity Type instance
1232:      *
1233:      * @return Mage_Eav_Model_Entity_Type
1234:      */
1235:     public function getEntityType()
1236:     {
1237:         return $this->_getResource()->getEntityType();
1238:     }
1239: 
1240:     /**
1241:      * Return Entity Type ID
1242:      *
1243:      * @return int
1244:      */
1245:     public function getEntityTypeId()
1246:     {
1247:         $entityTypeId = $this->getData('entity_type_id');
1248:         if (!$entityTypeId) {
1249:             $entityTypeId = $this->getEntityType()->getId();
1250:             $this->setData('entity_type_id', $entityTypeId);
1251:         }
1252:         return $entityTypeId;
1253:     }
1254: 
1255:     /**
1256:      * Get either first store ID from a set website or the provided as default
1257:      *
1258:      * @param int|string|null $storeId
1259:      *
1260:      * @return int
1261:      */
1262:     protected function _getWebsiteStoreId($defaultStoreId = null)
1263:     {
1264:         if ($this->getWebsiteId() != 0 && empty($defaultStoreId)) {
1265:             $storeIds = Mage::app()->getWebsite($this->getWebsiteId())->getStoreIds();
1266:             reset($storeIds);
1267:             $defaultStoreId = current($storeIds);
1268:         }
1269:         return $defaultStoreId;
1270:     }
1271: 
1272:     /**
1273:      * Change reset password link token
1274:      *
1275:      * Stores new reset password link token
1276:      *
1277:      * @param string $newResetPasswordLinkToken
1278:      * @return Mage_Customer_Model_Customer
1279:      */
1280:     public function changeResetPasswordLinkToken($newResetPasswordLinkToken) {
1281:         if (!is_string($newResetPasswordLinkToken) || empty($newResetPasswordLinkToken)) {
1282:             throw Mage::exception('Mage_Core', Mage::helper('customer')->__('Invalid password reset token.'),
1283:                 self::EXCEPTION_INVALID_RESET_PASSWORD_LINK_TOKEN);
1284:         }
1285:         $this->_getResource()->changeResetPasswordLinkToken($this, $newResetPasswordLinkToken);
1286:         return $this;
1287:     }
1288: 
1289:     /**
1290:      * Check if current reset password link token is expired
1291:      *
1292:      * @return boolean
1293:      */
1294:     public function isResetPasswordLinkTokenExpired()
1295:     {
1296:         $resetPasswordLinkToken = $this->getRpToken();
1297:         $resetPasswordLinkTokenCreatedAt = $this->getRpTokenCreatedAt();
1298: 
1299:         if (empty($resetPasswordLinkToken) || empty($resetPasswordLinkTokenCreatedAt)) {
1300:             return true;
1301:         }
1302: 
1303:         $tokenExpirationPeriod = Mage::helper('customer')->getResetPasswordLinkExpirationPeriod();
1304: 
1305:         $currentDate = Varien_Date::now();
1306:         $currentTimestamp = Varien_Date::toTimestamp($currentDate);
1307:         $tokenTimestamp = Varien_Date::toTimestamp($resetPasswordLinkTokenCreatedAt);
1308:         if ($tokenTimestamp > $currentTimestamp) {
1309:             return true;
1310:         }
1311: 
1312:         $dayDifference = floor(($currentTimestamp - $tokenTimestamp) / (24 * 60 * 60));
1313:         if ($dayDifference >= $tokenExpirationPeriod) {
1314:             return true;
1315:         }
1316: 
1317:         return false;
1318:     }
1319: }
1320: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0