Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes
Customer Class Reference
Inheritance diagram for Customer:
AbstractModel DataObject Customer

Public Member Functions

 __construct (\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Eav\Model\Config $config, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Customer\Model\ResourceModel\Customer $resource, \Magento\Customer\Model\Config\Share $configShare, \Magento\Customer\Model\AddressFactory $addressFactory, \Magento\Customer\Model\ResourceModel\Address\CollectionFactory $addressesFactory, \Magento\Framework\Mail\Template\TransportBuilder $transportBuilder, GroupRepositoryInterface $groupRepository, \Magento\Framework\Encryption\EncryptorInterface $encryptor, \Magento\Framework\Stdlib\DateTime $dateTime, CustomerInterfaceFactory $customerDataFactory, DataObjectProcessor $dataObjectProcessor, \Magento\Framework\Api\DataObjectHelper $dataObjectHelper, \Magento\Customer\Api\CustomerMetadataInterface $metadataService, \Magento\Framework\Indexer\IndexerRegistry $indexerRegistry, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[], AccountConfirmation $accountConfirmation=null)
 
 _construct ()
 
 updateData ($customer)
 
 getSharingConfig ()
 
 authenticate ($login, $password)
 
 loadByEmail ($customerEmail)
 
 changePassword ($newPassword)
 
 getName ()
 
 addAddress (Address $address)
 
 getAddressById ($addressId)
 
 getAddressItemById ($addressId)
 
 getAddressCollection ()
 
 getAddressesCollection ()
 
 getAddresses ()
 
 getAttributes ()
 
 getAttribute ($attributeCode)
 
 setPassword ($password)
 
 hashPassword ($password, $salt=true)
 
 validatePassword ($password)
 
 encryptPassword ($password)
 
 decryptPassword ($password)
 
 getPrimaryAddress ($attributeCode)
 
 getPrimaryBillingAddress ()
 
 getDefaultBillingAddress ()
 
 getPrimaryShippingAddress ()
 
 getDefaultShippingAddress ()
 
 getPrimaryAddressIds ()
 
 getPrimaryAddresses ()
 
 getAdditionalAddresses ()
 
 isAddressPrimary (Address $address)
 
 sendNewAccountEmail ($type='registered', $backUrl='', $storeId='0')
 
 isConfirmationRequired ()
 
 getRandomConfirmationKey ()
 
 sendPasswordReminderEmail ()
 
 sendPasswordResetConfirmationEmail ()
 
 getGroupId ()
 
 getTaxClassId ()
 
 getStore ()
 
 getSharedStoreIds ()
 
 getSharedWebsiteIds ()
 
 setStore (\Magento\Store\Model\Store $store)
 
 validate ()
 
 unsetSubscription ()
 
 cleanAllAddresses ()
 
 addError ($error)
 
 getErrors ()
 
 resetErrors ()
 
 beforeDelete ()
 
 afterSave ()
 
 afterDeleteCommit ()
 
 getCreatedAtTimestamp ()
 
 reset ()
 
 isDeleteable ()
 
 setIsDeleteable ($value)
 
 isReadonly ()
 
 setIsReadonly ($value)
 
 __clone ()
 
 getEntityType ()
 
 changeResetPasswordLinkToken ($passwordLinkToken)
 
 isResetPasswordLinkTokenExpired ()
 
 getResetPasswordLinkExpirationPeriod ()
 
 isCustomerLocked ()
 
 getPasswordConfirm ()
 
 getPassword ()
 
- Public Member Functions inherited from AbstractModel
 __construct (\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[])
 
 __sleep ()
 
 __wakeup ()
 
 setIdFieldName ($name)
 
 getIdFieldName ()
 
 getId ()
 
 setId ($value)
 
 isDeleted ($isDeleted=null)
 
 hasDataChanges ()
 
 setData ($key, $value=null)
 
 unsetData ($key=null)
 
 setDataChanges ($value)
 
 getOrigData ($key=null)
 
 setOrigData ($key=null, $data=null)
 
 dataHasChangedFor ($field)
 
 getResourceName ()
 
 getResourceCollection ()
 
 getCollection ()
 
 load ($modelId, $field=null)
 
 beforeLoad ($identifier, $field=null)
 
 afterLoad ()
 
 isSaveAllowed ()
 
 setHasDataChanges ($flag)
 
 save ()
 
 afterCommitCallback ()
 
 isObjectNew ($flag=null)
 
 beforeSave ()
 
 validateBeforeSave ()
 
 getCacheTags ()
 
 cleanModelCache ()
 
 afterSave ()
 
 delete ()
 
 beforeDelete ()
 
 afterDelete ()
 
 afterDeleteCommit ()
 
 getResource ()
 
 getEntityId ()
 
 setEntityId ($entityId)
 
 clearInstance ()
 
 getStoredData ()
 
 getEventPrefix ()
 
- Public Member Functions inherited from DataObject
 __construct (array $data=[])
 
 addData (array $arr)
 
 setData ($key, $value=null)
 
 unsetData ($key=null)
 
 getData ($key='', $index=null)
 
 getDataByPath ($path)
 
 getDataByKey ($key)
 
 setDataUsingMethod ($key, $args=[])
 
 getDataUsingMethod ($key, $args=null)
 
 hasData ($key='')
 
 toArray (array $keys=[])
 
 convertToArray (array $keys=[])
 
 toXml (array $keys=[], $rootName='item', $addOpenTag=false, $addCdata=true)
 
 convertToXml (array $arrAttributes=[], $rootName='item', $addOpenTag=false, $addCdata=true)
 
 toJson (array $keys=[])
 
 convertToJson (array $keys=[])
 
 toString ($format='')
 
 __call ($method, $args)
 
 isEmpty ()
 
 serialize ($keys=[], $valueSeparator='=', $fieldSeparator=' ', $quote='"')
 
 debug ($data=null, &$objects=[])
 
 offsetSet ($offset, $value)
 
 offsetExists ($offset)
 
 offsetUnset ($offset)
 
 offsetGet ($offset)
 

Data Fields

const XML_PATH_REGISTER_EMAIL_TEMPLATE = 'customer/create_account/email_template'
 
const XML_PATH_REGISTER_EMAIL_IDENTITY = 'customer/create_account/email_identity'
 
const XML_PATH_REMIND_EMAIL_TEMPLATE = 'customer/password/remind_email_template'
 
const XML_PATH_FORGOT_EMAIL_TEMPLATE = 'customer/password/forgot_email_template'
 
const XML_PATH_FORGOT_EMAIL_IDENTITY = 'customer/password/forgot_email_identity'
 
const XML_PATH_RESET_PASSWORD_TEMPLATE = 'customer/password/reset_password_template'
 
const XML_PATH_IS_CONFIRM = 'customer/create_account/confirm'
 
const XML_PATH_CONFIRM_EMAIL_TEMPLATE = 'customer/create_account/email_confirmation_template'
 
const XML_PATH_CONFIRMED_EMAIL_TEMPLATE = 'customer/create_account/email_confirmed_template'
 
const XML_PATH_GENERATE_HUMAN_FRIENDLY_ID = 'customer/create_account/generate_human_friendly_id'
 
const SUBSCRIBED_YES = 'yes'
 
const SUBSCRIBED_NO = 'no'
 
const ENTITY = 'customer'
 
const CUSTOMER_GRID_INDEXER_ID = 'customer_grid'
 
const XML_PATH_CUSTOMER_RESET_PASSWORD_LINK_EXPIRATION_PERIOD = 'customer/password/reset_link_expiration_period'
 

Protected Member Functions

 canSkipConfirmation ()
 
 _getWebsiteStoreId ($defaultStoreId=null)
 
 _createAddressInstance ()
 
 _createAddressCollection ()
 
 getTemplateTypes ()
 
- Protected Member Functions inherited from AbstractModel
 _construct ()
 
 _init ($resourceModel)
 
 _setResourceModel ($resourceName, $collectionName=null)
 
 _getResource ()
 
 _getEventData ()
 
 _beforeLoad ($modelId, $field=null)
 
 _afterLoad ()
 
 _hasModelChanged ()
 
 _getValidatorBeforeSave ()
 
 _createValidatorBeforeSave ()
 
 _getValidationRulesBeforeSave ()
 
 _clearReferences ()
 
 _clearData ()
 
- Protected Member Functions inherited from DataObject
 _getData ($key)
 
 _underscore ($name)
 

Protected Attributes

 $_eventPrefix = 'customer'
 
 $_eventObject = 'customer'
 
 $_errors = []
 
 $_attributes
 
 $_addressesCollection
 
 $_isDeleteable = true
 
 $_isReadonly = false
 
 $_storeManager
 
 $_config
 
 $_scopeConfig
 
 $_configShare
 
 $_addressFactory
 
 $_addressesFactory
 
 $_transportBuilder
 
 $_groupRepository
 
 $_encryptor
 
 $mathRandom
 
 $dateTime
 
 $customerDataFactory
 
 $dataObjectProcessor
 
 $dataObjectHelper
 
 $metadataService
 
 $indexerRegistry
 
- Protected Attributes inherited from AbstractModel
 $_eventPrefix = 'core_abstract'
 
 $_eventObject = 'object'
 
 $_idFieldName = 'id'
 
 $_hasDataChanges = false
 
 $_origData
 
 $_isDeleted = false
 
 $_resource
 
 $_resourceCollection
 
 $_resourceName
 
 $_collectionName
 
 $_cacheTag = false
 
 $_dataSaveAllowed = true
 
 $_isObjectNew = null
 
 $_validatorBeforeSave = null
 
 $_eventManager
 
 $_cacheManager
 
 $_registry
 
 $_logger
 
 $_appState
 
 $_actionValidator
 
 $storedData = []
 
- Protected Attributes inherited from DataObject
 $_data = []
 

Additional Inherited Members

- Static Protected Attributes inherited from DataObject
static $_underscoreCache = []
 

Detailed Description

Customer model

@api @method int getWebsiteId() getWebsiteId() @method Customer setWebsiteId($value) @method int getStoreId() getStoreId() @method string getEmail() getEmail() @method mixed getDisableAutoGroupChange() @method Customer setDisableAutoGroupChange($value) @method Customer setGroupId($value) @method Customer setDefaultBilling($value) @method Customer setDefaultShipping($value) @method Customer setPasswordHash($string) @method string getPasswordHash() @method string getConfirmation() @SuppressWarnings(PHPMD.ExcessivePublicCount) @SuppressWarnings(PHPMD.TooManyFields) @SuppressWarnings(PHPMD.ExcessiveClassComplexity) @SuppressWarnings(PHPMD.CouplingBetweenObjects)

Since
100.0.2

Definition at line 46 of file Customer.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\Framework\Model\Context  $context,
\Magento\Framework\Registry  $registry,
\Magento\Store\Model\StoreManagerInterface  $storeManager,
\Magento\Eav\Model\Config  $config,
\Magento\Framework\App\Config\ScopeConfigInterface  $scopeConfig,
\Magento\Customer\Model\ResourceModel\Customer  $resource,
\Magento\Customer\Model\Config\Share  $configShare,
\Magento\Customer\Model\AddressFactory  $addressFactory,
\Magento\Customer\Model\ResourceModel\Address\CollectionFactory  $addressesFactory,
\Magento\Framework\Mail\Template\TransportBuilder  $transportBuilder,
GroupRepositoryInterface  $groupRepository,
\Magento\Framework\Encryption\EncryptorInterface  $encryptor,
\Magento\Framework\Stdlib\DateTime  $dateTime,
CustomerInterfaceFactory  $customerDataFactory,
DataObjectProcessor  $dataObjectProcessor,
\Magento\Framework\Api\DataObjectHelper  $dataObjectHelper,
\Magento\Customer\Api\CustomerMetadataInterface  $metadataService,
\Magento\Framework\Indexer\IndexerRegistry  $indexerRegistry,
\Magento\Framework\Data\Collection\AbstractDb  $resourceCollection = null,
array  $data = [],
AccountConfirmation  $accountConfirmation = null 
)
Parameters
\Magento\Framework\Model\Context$context
\Magento\Framework\Registry$registry
\Magento\Store\Model\StoreManagerInterface$storeManager
\Magento\Eav\Model\Config$config
ScopeConfigInterface$scopeConfig
ResourceCustomer$resource
Share$configShare
AddressFactory$addressFactory
CollectionFactory$addressesFactory
\Magento\Framework\Mail\Template\TransportBuilder$transportBuilder
GroupRepositoryInterface$groupRepository
\Magento\Framework\Encryption\EncryptorInterface$encryptor
\Magento\Framework\Stdlib\DateTime$dateTime
CustomerInterfaceFactory$customerDataFactory
DataObjectProcessor$dataObjectProcessor
\Magento\Framework\Api\DataObjectHelper$dataObjectHelper
CustomerMetadataInterface$metadataService
\Magento\Framework\Indexer\IndexerRegistry$indexerRegistry
\Magento\Framework\Data\Collection\AbstractDb | null$resourceCollection
array$data
AccountConfirmation | null$accountConfirmation@SuppressWarnings(PHPMD.ExcessiveParameterList)

Definition at line 247 of file Customer.php.

269  {
270  $this->metadataService = $metadataService;
271  $this->_scopeConfig = $scopeConfig;
272  $this->_storeManager = $storeManager;
273  $this->_config = $config;
274  $this->_configShare = $configShare;
275  $this->_addressFactory = $addressFactory;
276  $this->_addressesFactory = $addressesFactory;
277  $this->_transportBuilder = $transportBuilder;
278  $this->_groupRepository = $groupRepository;
279  $this->_encryptor = $encryptor;
280  $this->dateTime = $dateTime;
281  $this->customerDataFactory = $customerDataFactory;
282  $this->dataObjectProcessor = $dataObjectProcessor;
283  $this->dataObjectHelper = $dataObjectHelper;
284  $this->indexerRegistry = $indexerRegistry;
285  $this->accountConfirmation = $accountConfirmation ?: ObjectManager::getInstance()
286  ->get(AccountConfirmation::class);
287  parent::__construct(
288  $context,
289  $registry,
290  $resource,
291  $resourceCollection,
292  $data
293  );
294  }
$groupRepository
$config
Definition: fraud_order.php:17
$storeManager
$resource
Definition: bulk.php:12
$addressFactory
Definition: quote.php:20

Member Function Documentation

◆ __clone()

__clone ( )

Clone current object

Returns
void

Definition at line 1193 of file Customer.php.

1194  {
1195  $newAddressCollection = $this->getPrimaryAddresses();
1196  $newAddressCollection = array_merge($newAddressCollection, $this->getAdditionalAddresses());
1197  $this->setId(null);
1198  $this->cleanAllAddresses();
1199  foreach ($newAddressCollection as $address) {
1200  $this->addAddress(clone $address);
1201  }
1202  }
addAddress(Address $address)
Definition: Customer.php:465
$address
Definition: customer.php:38

◆ _construct()

_construct ( )

Initialize customer model

Returns
void

Definition at line 301 of file Customer.php.

302  {
303  $this->_init(\Magento\Customer\Model\ResourceModel\Customer::class);
304  }

◆ _createAddressCollection()

_createAddressCollection ( )
protected
Returns
\Magento\Customer\Model\ResourceModel\Address\Collection

Definition at line 1305 of file Customer.php.

1306  {
1307  return $this->_addressesFactory->create();
1308  }

◆ _createAddressInstance()

_createAddressInstance ( )
protected
Returns
Address

Definition at line 1297 of file Customer.php.

1298  {
1299  return $this->_addressFactory->create();
1300  }

◆ _getWebsiteStoreId()

_getWebsiteStoreId (   $defaultStoreId = null)
protected

Get either first store ID from a set website or the provided as default

Parameters
int | string | null$defaultStoreId
Returns
int

Definition at line 1221 of file Customer.php.

1222  {
1223  if ($this->getWebsiteId() != 0 && empty($defaultStoreId)) {
1224  $storeIds = $this->_storeManager->getWebsite($this->getWebsiteId())->getStoreIds();
1225  reset($storeIds);
1226  $defaultStoreId = current($storeIds);
1227  }
1228  return $defaultStoreId;
1229  }

◆ addAddress()

addAddress ( Address  $address)

Add address to address collection

Parameters
Address$address
Returns
$this

Definition at line 465 of file Customer.php.

466  {
467  $this->getAddressesCollection()->addItem($address);
468  return $this;
469  }
$address
Definition: customer.php:38

◆ addError()

addError (   $error)

Add error

Parameters
mixed$error
Returns
$this

Definition at line 1017 of file Customer.php.

1018  {
1019  $this->_errors[] = $error;
1020  return $this;
1021  }

◆ afterDeleteCommit()

afterDeleteCommit ( )

Init indexing process after customer delete

Returns
\Magento\Framework\Model\AbstractModel

Definition at line 1074 of file Customer.php.

1075  {
1076  $this->reindex();
1077  return parent::afterDeleteCommit();
1078  }

◆ afterSave()

afterSave ( )

Processing object after save data

Returns
$this

Definition at line 1060 of file Customer.php.

1061  {
1062  $indexer = $this->indexerRegistry->get(self::CUSTOMER_GRID_INDEXER_ID);
1063  if ($indexer->getState()->getStatus() == StateInterface::STATUS_VALID) {
1064  $this->_getResource()->addCommitCallback([$this, 'reindex']);
1065  }
1066  return parent::afterSave();
1067  }

◆ authenticate()

authenticate (   $login,
  $password 
)

Authenticate customer

Parameters
string$login
string$password
Returns
bool
Exceptions

Definition at line 391 of file Customer.php.

392  {
393  $this->loadByEmail($login);
394  if ($this->getConfirmation() && $this->isConfirmationRequired()) {
395  throw new EmailNotConfirmedException(
396  __("This account isn't confirmed. Verify and try again.")
397  );
398  }
399  if (!$this->validatePassword($password)) {
400  throw new InvalidEmailOrPasswordException(
401  __('Invalid login or password.')
402  );
403  }
404  $this->_eventManager->dispatch(
405  'customer_customer_authenticated',
406  ['model' => $this, 'password' => $password]
407  );
408 
409  return true;
410  }
__()
Definition: __.php:13

◆ beforeDelete()

beforeDelete ( )

Prepare customer for delete

Returns
$this

Definition at line 1049 of file Customer.php.

1050  {
1051  //TODO : Revisit and figure handling permissions in MAGETWO-11084 Implementation: Service Context Provider
1052  return parent::beforeDelete();
1053  }

◆ canSkipConfirmation()

canSkipConfirmation ( )
protected

Check whether confirmation may be skipped when registering using certain email address

Returns
bool
Deprecated:
101.0.4
See also
AccountConfirmation::isConfirmationRequired

Definition at line 1171 of file Customer.php.

1172  {
1173  if (!$this->getId()) {
1174  return false;
1175  }
1176 
1177  /* If an email was used to start the registration process and it is the same email as the one
1178  used to register, then this can skip confirmation.
1179  */
1180  $skipConfirmationIfEmail = $this->_registry->registry("skip_confirmation_if_email");
1181  if (!$skipConfirmationIfEmail) {
1182  return false;
1183  }
1184 
1185  return strtolower($skipConfirmationIfEmail) === strtolower($this->getEmail());
1186  }

◆ changePassword()

changePassword (   $newPassword)

Change customer password

Parameters
string$newPassword
Returns
$this

Definition at line 430 of file Customer.php.

431  {
432  $this->_getResource()->changePassword($this, $newPassword);
433  return $this;
434  }

◆ changeResetPasswordLinkToken()

changeResetPasswordLinkToken (   $passwordLinkToken)

Change reset password link token

Stores new reset password link token

Parameters
string$passwordLinkToken
Returns
$this
Exceptions

Definition at line 1240 of file Customer.php.

1241  {
1242  if (!is_string($passwordLinkToken) || empty($passwordLinkToken)) {
1243  throw new AuthenticationException(
1244  __('A valid password reset token is missing. Enter and try again.')
1245  );
1246  }
1247  $this->_getResource()->changeResetPasswordLinkToken($this, $passwordLinkToken);
1248  return $this;
1249  }
__()
Definition: __.php:13

◆ cleanAllAddresses()

cleanAllAddresses ( )

Clean all addresses

Returns
void

Definition at line 1006 of file Customer.php.

1007  {
1008  $this->_addressesCollection = null;
1009  }

◆ decryptPassword()

decryptPassword (   $password)

Decrypt password

Parameters
string$password
Returns
string

Definition at line 619 of file Customer.php.

620  {
621  return $this->_encryptor->decrypt($password);
622  }

◆ encryptPassword()

encryptPassword (   $password)

Encrypt password

Parameters
string$password
Returns
string

Definition at line 608 of file Customer.php.

609  {
610  return $this->_encryptor->encrypt($password);
611  }

◆ getAdditionalAddresses()

getAdditionalAddresses ( )

Retrieve not default addresses

Returns
Address[]

Definition at line 725 of file Customer.php.

726  {
727  $addresses = [];
728  $primatyIds = $this->getPrimaryAddressIds();
729  foreach ($this->getAddressesCollection() as $address) {
730  if (!in_array($address->getId(), $primatyIds)) {
731  $addresses[] = $address;
732  }
733  }
734  return $addresses;
735  }
$addresses
Definition: address_list.php:7
$address
Definition: customer.php:38

◆ getAddressById()

getAddressById (   $addressId)

Retrieve customer address by address id

Parameters
int$addressId
Returns
Address

Definition at line 477 of file Customer.php.

478  {
479  return $this->_createAddressInstance()->load($addressId);
480  }

◆ getAddressCollection()

getAddressCollection ( )

Retrieve not loaded address collection

Returns
\Magento\Customer\Model\ResourceModel\Address\Collection

Definition at line 498 of file Customer.php.

499  {
500  return $this->_createAddressCollection();
501  }

◆ getAddresses()

getAddresses ( )

Retrieve customer address array

Returns
\Magento\Framework\DataObject[]

Definition at line 529 of file Customer.php.

530  {
531  return $this->getAddressesCollection()->getItems();
532  }

◆ getAddressesCollection()

getAddressesCollection ( )

Customer addresses collection

Returns
\Magento\Customer\Model\ResourceModel\Address\Collection

Definition at line 508 of file Customer.php.

509  {
510  if ($this->_addressesCollection === null) {
511  $this->_addressesCollection = $this->getAddressCollection()->setCustomerFilter(
512  $this
513  )->addAttributeToSelect(
514  '*'
515  );
516  foreach ($this->_addressesCollection as $address) {
517  $address->setCustomer($this);
518  }
519  }
520 
522  }
$address
Definition: customer.php:38

◆ getAddressItemById()

getAddressItemById (   $addressId)

Getting customer address object from collection by identifier

Parameters
int$addressId
Returns
Address

Definition at line 488 of file Customer.php.

489  {
490  return $this->getAddressesCollection()->getItemById($addressId);
491  }

◆ getAttribute()

getAttribute (   $attributeCode)

Get customer attribute model object

Parameters
string$attributeCode
Returns
\Magento\Customer\Model\ResourceModel\Attribute | null

Definition at line 553 of file Customer.php.

554  {
555  $this->getAttributes();
556  if (isset($this->_attributes[$attributeCode])) {
557  return $this->_attributes[$attributeCode];
558  }
559  return null;
560  }
$attributeCode
Definition: extend.phtml:12

◆ getAttributes()

getAttributes ( )

Retrieve all customer attributes

Returns
Attribute[]

Definition at line 539 of file Customer.php.

540  {
541  if ($this->_attributes === null) {
542  $this->_attributes = $this->_getResource()->loadAllAttributes($this)->getSortedAttributes();
543  }
544  return $this->_attributes;
545  }

◆ getCreatedAtTimestamp()

getCreatedAtTimestamp ( )

Get customer created at date timestamp

Returns
int|null

Definition at line 1097 of file Customer.php.

1098  {
1099  $date = $this->getCreatedAt();
1100  if ($date) {
1101  return (new \DateTime($date))->getTimestamp();
1102  }
1103  return null;
1104  }

◆ getDefaultBillingAddress()

getDefaultBillingAddress ( )

Get customer default billing address

Returns
Address

Definition at line 652 of file Customer.php.

653  {
654  return $this->getPrimaryBillingAddress();
655  }

◆ getDefaultShippingAddress()

getDefaultShippingAddress ( )

Get default customer shipping address

Returns
Address

Definition at line 672 of file Customer.php.

673  {
674  return $this->getPrimaryShippingAddress();
675  }

◆ getEntityType()

getEntityType ( )

Return Entity Type instance

Returns
\Magento\Eav\Model\Entity\Type

Definition at line 1209 of file Customer.php.

1210  {
1211  return $this->_getResource()->getEntityType();
1212  }

◆ getErrors()

getErrors ( )

Retrieve errors

Returns
array

Definition at line 1028 of file Customer.php.

1029  {
1030  return $this->_errors;
1031  }

◆ getGroupId()

getGroupId ( )

Retrieve customer group identifier

Returns
int

Definition at line 881 of file Customer.php.

882  {
883  if (!$this->hasData('group_id')) {
884  $storeId = $this->getStoreId() ? $this->getStoreId() : $this->_storeManager->getStore()->getId();
885  $groupId = $this->_scopeConfig->getValue(
887  ScopeInterface::SCOPE_STORE,
888  $storeId
889  );
890  $this->setData('group_id', $groupId);
891  }
892  return $this->getData('group_id');
893  }
getData($key='', $index=null)
Definition: DataObject.php:119

◆ getName()

getName ( )

Get full customer name

Returns
string

Definition at line 441 of file Customer.php.

442  {
443  $name = '';
444 
445  if ($this->_config->getAttribute('customer', 'prefix')->getIsVisible() && $this->getPrefix()) {
446  $name .= $this->getPrefix() . ' ';
447  }
448  $name .= $this->getFirstname();
449  if ($this->_config->getAttribute('customer', 'middlename')->getIsVisible() && $this->getMiddlename()) {
450  $name .= ' ' . $this->getMiddlename();
451  }
452  $name .= ' ' . $this->getLastname();
453  if ($this->_config->getAttribute('customer', 'suffix')->getIsVisible() && $this->getSuffix()) {
454  $name .= ' ' . $this->getSuffix();
455  }
456  return $name;
457  }
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ getPassword()

getPassword ( )

Return Password

Returns
string
Since
100.1.0

Definition at line 1362 of file Customer.php.

1363  {
1364  return (string) $this->getData('password');
1365  }
getData($key='', $index=null)
Definition: DataObject.php:119

◆ getPasswordConfirm()

getPasswordConfirm ( )

Return Password Confirmation

Returns
string
Since
100.1.0

Definition at line 1351 of file Customer.php.

1352  {
1353  return (string) $this->getData('password_confirm');
1354  }
getData($key='', $index=null)
Definition: DataObject.php:119

◆ getPrimaryAddress()

getPrimaryAddress (   $attributeCode)

Retrieve default address by type(attribute)

Parameters
string$attributeCodeaddress type attribute code
Returns
Address|false

Definition at line 630 of file Customer.php.

631  {
632  $primaryAddress = $this->getAddressesCollection()->getItemById($this->getData($attributeCode));
633 
634  return $primaryAddress ? $primaryAddress : false;
635  }
getData($key='', $index=null)
Definition: DataObject.php:119
$attributeCode
Definition: extend.phtml:12

◆ getPrimaryAddresses()

getPrimaryAddresses ( )

Retrieve all customer default addresses

Returns
Address[]

Definition at line 699 of file Customer.php.

700  {
701  $addresses = [];
702  $primaryBilling = $this->getPrimaryBillingAddress();
703  if ($primaryBilling) {
704  $addresses[] = $primaryBilling;
705  $primaryBilling->setIsPrimaryBilling(true);
706  }
707 
708  $primaryShipping = $this->getPrimaryShippingAddress();
709  if ($primaryShipping) {
710  if ($primaryBilling && $primaryBilling->getId() == $primaryShipping->getId()) {
711  $primaryBilling->setIsPrimaryShipping(true);
712  } else {
713  $primaryShipping->setIsPrimaryShipping(true);
714  $addresses[] = $primaryShipping;
715  }
716  }
717  return $addresses;
718  }
$addresses
Definition: address_list.php:7

◆ getPrimaryAddressIds()

getPrimaryAddressIds ( )

Retrieve ids of default addresses

Returns
array

Definition at line 682 of file Customer.php.

683  {
684  $ids = [];
685  if ($this->getDefaultBilling()) {
686  $ids[] = $this->getDefaultBilling();
687  }
688  if ($this->getDefaultShipping()) {
689  $ids[] = $this->getDefaultShipping();
690  }
691  return $ids;
692  }

◆ getPrimaryBillingAddress()

getPrimaryBillingAddress ( )

Get customer default billing address

Returns
Address

Definition at line 642 of file Customer.php.

643  {
644  return $this->getPrimaryAddress('default_billing');
645  }
getPrimaryAddress($attributeCode)
Definition: Customer.php:630

◆ getPrimaryShippingAddress()

getPrimaryShippingAddress ( )

Get default customer shipping address

Returns
Address

Definition at line 662 of file Customer.php.

663  {
664  return $this->getPrimaryAddress('default_shipping');
665  }
getPrimaryAddress($attributeCode)
Definition: Customer.php:630

◆ getRandomConfirmationKey()

getRandomConfirmationKey ( )

Generate random confirmation key

Returns
string

Definition at line 803 of file Customer.php.

804  {
805  return md5(uniqid());
806  }

◆ getResetPasswordLinkExpirationPeriod()

getResetPasswordLinkExpirationPeriod ( )

Retrieve customer reset password link expiration period in days

Returns
int

Definition at line 1286 of file Customer.php.

1287  {
1288  return (int)$this->_scopeConfig->getValue(
1289  self::XML_PATH_CUSTOMER_RESET_PASSWORD_LINK_EXPIRATION_PERIOD,
1291  );
1292  }

◆ getSharedStoreIds()

getSharedStoreIds ( )

Retrieve shared store ids

Returns
array

Definition at line 924 of file Customer.php.

925  {
926  $ids = $this->_getData('shared_store_ids');
927  if ($ids === null) {
928  $ids = [];
929  if ((bool)$this->getSharingConfig()->isWebsiteScope()) {
930  $ids = $this->_storeManager->getWebsite($this->getWebsiteId())->getStoreIds();
931  } else {
932  foreach ($this->_storeManager->getStores() as $store) {
933  $ids[] = $store->getId();
934  }
935  }
936  $this->setData('shared_store_ids', $ids);
937  }
938 
939  return $ids;
940  }

◆ getSharedWebsiteIds()

getSharedWebsiteIds ( )

Retrieve shared website ids

Returns
int[]

Definition at line 947 of file Customer.php.

948  {
949  $ids = $this->_getData('shared_website_ids');
950  if ($ids === null) {
951  $ids = [];
952  if ((bool)$this->getSharingConfig()->isWebsiteScope()) {
953  $ids[] = $this->getWebsiteId();
954  } else {
955  foreach ($this->_storeManager->getWebsites() as $website) {
956  $ids[] = $website->getId();
957  }
958  }
959  $this->setData('shared_website_ids', $ids);
960  }
961  return $ids;
962  }

◆ getSharingConfig()

getSharingConfig ( )

Retrieve customer sharing configuration model

Returns
Share

Definition at line 377 of file Customer.php.

378  {
379  return $this->_configShare;
380  }

◆ getStore()

getStore ( )

Retrieve store where customer was created

Returns
\Magento\Store\Model\Store

Definition at line 914 of file Customer.php.

915  {
916  return $this->_storeManager->getStore($this->getStoreId());
917  }

◆ getTaxClassId()

getTaxClassId ( )

Retrieve customer tax class identifier

Returns
int

Definition at line 900 of file Customer.php.

901  {
902  if (!$this->getData('tax_class_id')) {
903  $groupTaxClassId = $this->_groupRepository->getById($this->getGroupId())->getTaxClassId();
904  $this->setData('tax_class_id', $groupTaxClassId);
905  }
906  return $this->getData('tax_class_id');
907  }
getData($key='', $index=null)
Definition: DataObject.php:119

◆ getTemplateTypes()

getTemplateTypes ( )
protected
Returns
array

'registered' welcome email, when confirmation is disabled 'confirmed' welcome email, when confirmation is enabled 'confirmation' email with confirmation link

Definition at line 1313 of file Customer.php.

1314  {
1320  $types = [
1323  'confirmation' => self::XML_PATH_CONFIRM_EMAIL_TEMPLATE,
1324  ];
1325  return $types;
1326  }

◆ hashPassword()

hashPassword (   $password,
  $salt = true 
)

Hash customer password

Parameters
string$password
bool | int | string$salt
Returns
string

Definition at line 582 of file Customer.php.

583  {
584  return $this->_encryptor->getHash($password, $salt);
585  }

◆ isAddressPrimary()

isAddressPrimary ( Address  $address)

Check if address is primary

Parameters
Address$address
Returns
boolean

Definition at line 743 of file Customer.php.

744  {
745  if (!$address->getId()) {
746  return false;
747  }
748  return $address->getId() == $this->getDefaultBilling() || $address->getId() == $this->getDefaultShipping();
749  }
$address
Definition: customer.php:38

◆ isConfirmationRequired()

isConfirmationRequired ( )

Check if accounts confirmation is required in config

Returns
bool
Deprecated:
101.0.4
See also
AccountConfirmation::isConfirmationRequired

Definition at line 791 of file Customer.php.

792  {
793  $websiteId = $this->getWebsiteId() ? $this->getWebsiteId() : null;
794 
795  return $this->accountConfirmation->isConfirmationRequired($websiteId, $this->getId(), $this->getEmail());
796  }

◆ isCustomerLocked()

isCustomerLocked ( )

Check if customer is locked

Returns
boolean
Since
100.1.0

Definition at line 1334 of file Customer.php.

1335  {
1336  if ($this->getLockExpires()) {
1337  $lockExpires = new \DateTime($this->getLockExpires());
1338  if ($lockExpires > new \DateTime()) {
1339  return true;
1340  }
1341  }
1342  return false;
1343  }

◆ isDeleteable()

isDeleteable ( )

Checks model is deletable

Returns
boolean

Definition at line 1125 of file Customer.php.

1126  {
1127  return $this->_isDeleteable;
1128  }

◆ isReadonly()

isReadonly ( )

Checks model is readonly

Returns
boolean

Definition at line 1147 of file Customer.php.

1148  {
1149  return $this->_isReadonly;
1150  }

◆ isResetPasswordLinkTokenExpired()

isResetPasswordLinkTokenExpired ( )

Check if current reset password link token is expired

Returns
boolean

Definition at line 1256 of file Customer.php.

1257  {
1258  $linkToken = $this->getRpToken();
1259  $linkTokenCreatedAt = $this->getRpTokenCreatedAt();
1260 
1261  if (empty($linkToken) || empty($linkTokenCreatedAt)) {
1262  return true;
1263  }
1264 
1265  $expirationPeriod = $this->getResetPasswordLinkExpirationPeriod();
1266 
1267  $currentTimestamp = (new \DateTime())->getTimestamp();
1268  $tokenTimestamp = (new \DateTime($linkTokenCreatedAt))->getTimestamp();
1269  if ($tokenTimestamp > $currentTimestamp) {
1270  return true;
1271  }
1272 
1273  $dayDifference = floor(($currentTimestamp - $tokenTimestamp) / (24 * 60 * 60));
1274  if ($dayDifference >= $expirationPeriod) {
1275  return true;
1276  }
1277 
1278  return false;
1279  }

◆ loadByEmail()

loadByEmail (   $customerEmail)

Load customer by email

Parameters
string$customerEmail
Returns
$this

Definition at line 418 of file Customer.php.

419  {
420  $this->_getResource()->loadByEmail($this, $customerEmail);
421  return $this;
422  }

◆ reset()

reset ( )

Reset all model data

Returns
$this

Definition at line 1111 of file Customer.php.

1112  {
1113  $this->setData([]);
1114  $this->setOrigData();
1115  $this->_attributes = null;
1116 
1117  return $this;
1118  }

◆ resetErrors()

resetErrors ( )

Reset errors array

Returns
$this

Definition at line 1038 of file Customer.php.

1039  {
1040  $this->_errors = [];
1041  return $this;
1042  }

◆ sendNewAccountEmail()

sendNewAccountEmail (   $type = 'registered',
  $backUrl = '',
  $storeId = '0' 
)

Send email with new account related information

Parameters
string$type
string$backUrl
string$storeId
Returns
$this
Exceptions

Definition at line 760 of file Customer.php.

761  {
762  $types = $this->getTemplateTypes();
763 
764  if (!isset($types[$type])) {
765  throw new \Magento\Framework\Exception\LocalizedException(
766  __('The transactional account email type is incorrect. Verify and try again.')
767  );
768  }
769 
770  if (!$storeId) {
771  $storeId = $this->_getWebsiteStoreId($this->getSendemailStoreId());
772  }
773 
774  $this->_sendEmailTemplate(
775  $types[$type],
776  self::XML_PATH_REGISTER_EMAIL_IDENTITY,
777  ['customer' => $this, 'back_url' => $backUrl, 'store' => $this->getStore()],
778  $storeId
779  );
780 
781  return $this;
782  }
_getWebsiteStoreId($defaultStoreId=null)
Definition: Customer.php:1221
__()
Definition: __.php:13
$type
Definition: item.phtml:13

◆ sendPasswordReminderEmail()

sendPasswordReminderEmail ( )

Send email with new customer password

Returns
$this

Definition at line 813 of file Customer.php.

814  {
815  $this->_sendEmailTemplate(
816  self::XML_PATH_REMIND_EMAIL_TEMPLATE,
817  self::XML_PATH_FORGOT_EMAIL_IDENTITY,
818  ['customer' => $this, 'store' => $this->getStore()],
819  $this->getStoreId()
820  );
821 
822  return $this;
823  }

◆ sendPasswordResetConfirmationEmail()

sendPasswordResetConfirmationEmail ( )

Send email with reset password confirmation link

Returns
$this

Definition at line 859 of file Customer.php.

860  {
861  $storeId = $this->getStoreId();
862  if (!$storeId) {
863  $storeId = $this->_getWebsiteStoreId();
864  }
865 
866  $this->_sendEmailTemplate(
867  self::XML_PATH_FORGOT_EMAIL_TEMPLATE,
868  self::XML_PATH_FORGOT_EMAIL_IDENTITY,
869  ['customer' => $this, 'store' => $this->getStore()],
870  $storeId
871  );
872 
873  return $this;
874  }
_getWebsiteStoreId($defaultStoreId=null)
Definition: Customer.php:1221

◆ setIsDeleteable()

setIsDeleteable (   $value)

Set is deletable flag

Parameters
boolean$value
Returns
$this

Definition at line 1136 of file Customer.php.

1137  {
1138  $this->_isDeleteable = (bool)$value;
1139  return $this;
1140  }
$value
Definition: gender.phtml:16

◆ setIsReadonly()

setIsReadonly (   $value)

Set is readonly flag

Parameters
boolean$value
Returns
$this

Definition at line 1158 of file Customer.php.

1159  {
1160  $this->_isReadonly = (bool)$value;
1161  return $this;
1162  }
$value
Definition: gender.phtml:16

◆ setPassword()

setPassword (   $password)

Set plain and hashed password

Parameters
string$password
Returns
$this

Definition at line 568 of file Customer.php.

569  {
570  $this->setData('password', $password);
571  $this->setPasswordHash($this->hashPassword($password));
572  return $this;
573  }
hashPassword($password, $salt=true)
Definition: Customer.php:582

◆ setStore()

setStore ( \Magento\Store\Model\Store  $store)

Set store to customer

Parameters
\Magento\Store\Model\Store$store
Returns
$this

Definition at line 970 of file Customer.php.

971  {
972  $this->setStoreId($store->getId());
973  $this->setWebsiteId($store->getWebsite()->getId());
974  return $this;
975  }

◆ unsetSubscription()

unsetSubscription ( )

Unset subscription

Returns
$this

Definition at line 993 of file Customer.php.

994  {
995  if (isset($this->_isSubscribed)) {
996  unset($this->_isSubscribed);
997  }
998  return $this;
999  }

◆ updateData()

updateData (   $customer)

Update customer data

Parameters
\Magento\Customer\Api\Data\CustomerInterface$customer
Returns
$this

Definition at line 336 of file Customer.php.

337  {
338  $customerDataAttributes = $this->dataObjectProcessor->buildOutputDataArray(
339  $customer,
340  \Magento\Customer\Api\Data\CustomerInterface::class
341  );
342 
343  foreach ($customerDataAttributes as $attributeCode => $attributeData) {
344  if ($attributeCode == 'password') {
345  continue;
346  }
348  }
349 
350  $customAttributes = $customer->getCustomAttributes();
351  if ($customAttributes !== null) {
352  foreach ($customAttributes as $attribute) {
353  $this->setData($attribute->getAttributeCode(), $attribute->getValue());
354  }
355  }
356 
357  $customerId = $customer->getId();
358  if ($customerId) {
359  $this->setId($customerId);
360  }
361 
362  // Need to use attribute set or future updates can cause data loss
363  if (!$this->getAttributeSetId()) {
364  $this->setAttributeSetId(
366  );
367  }
368 
369  return $this;
370  }
$customer
Definition: customers.php:11
$attributeCode
Definition: extend.phtml:12
setDataUsingMethod($key, $args=[])
Definition: DataObject.php:204

◆ validate()

validate ( )

Validate customer attribute values.

Deprecated:
100.1.0
Returns
bool

Definition at line 983 of file Customer.php.

984  {
985  return true;
986  }

◆ validatePassword()

validatePassword (   $password)

Validate password with salted hash

Parameters
string$password
Returns
boolean

Definition at line 593 of file Customer.php.

594  {
595  $hash = $this->getPasswordHash();
596  if (!$hash) {
597  return false;
598  }
599  return $this->_encryptor->validateHash($password, $hash);
600  }

Field Documentation

◆ $_addressesCollection

$_addressesCollection
protected

Definition at line 121 of file Customer.php.

◆ $_addressesFactory

$_addressesFactory
protected

Definition at line 165 of file Customer.php.

◆ $_addressFactory

$_addressFactory
protected

Definition at line 160 of file Customer.php.

◆ $_attributes

$_attributes
protected

Definition at line 114 of file Customer.php.

◆ $_config

$_config
protected

Definition at line 145 of file Customer.php.

◆ $_configShare

$_configShare
protected

Definition at line 155 of file Customer.php.

◆ $_encryptor

$_encryptor
protected

Definition at line 180 of file Customer.php.

◆ $_errors

$_errors = []
protected

Definition at line 107 of file Customer.php.

◆ $_eventObject

$_eventObject = 'customer'
protected

Definition at line 100 of file Customer.php.

◆ $_eventPrefix

$_eventPrefix = 'customer'
protected

Definition at line 93 of file Customer.php.

◆ $_groupRepository

$_groupRepository
protected

Definition at line 175 of file Customer.php.

◆ $_isDeleteable

$_isDeleteable = true
protected

Definition at line 128 of file Customer.php.

◆ $_isReadonly

$_isReadonly = false
protected

Definition at line 135 of file Customer.php.

◆ $_scopeConfig

$_scopeConfig
protected

Definition at line 150 of file Customer.php.

◆ $_storeManager

$_storeManager
protected

Definition at line 140 of file Customer.php.

◆ $_transportBuilder

$_transportBuilder
protected

Definition at line 170 of file Customer.php.

◆ $customerDataFactory

$customerDataFactory
protected

Definition at line 195 of file Customer.php.

◆ $dataObjectHelper

$dataObjectHelper
protected

Definition at line 205 of file Customer.php.

◆ $dataObjectProcessor

$dataObjectProcessor
protected

Definition at line 200 of file Customer.php.

◆ $dateTime

$dateTime
protected

Definition at line 190 of file Customer.php.

◆ $indexerRegistry

$indexerRegistry
protected

Definition at line 215 of file Customer.php.

◆ $mathRandom

$mathRandom
protected

Definition at line 185 of file Customer.php.

◆ $metadataService

$metadataService
protected

Definition at line 210 of file Customer.php.

◆ CUSTOMER_GRID_INDEXER_ID

const CUSTOMER_GRID_INDEXER_ID = 'customer_grid'

Definition at line 81 of file Customer.php.

◆ ENTITY

const ENTITY = 'customer'

Definition at line 79 of file Customer.php.

◆ SUBSCRIBED_NO

const SUBSCRIBED_NO = 'no'

Definition at line 77 of file Customer.php.

◆ SUBSCRIBED_YES

const SUBSCRIBED_YES = 'yes'

Definition at line 75 of file Customer.php.

◆ XML_PATH_CONFIRM_EMAIL_TEMPLATE

const XML_PATH_CONFIRM_EMAIL_TEMPLATE = 'customer/create_account/email_confirmation_template'

Definition at line 69 of file Customer.php.

◆ XML_PATH_CONFIRMED_EMAIL_TEMPLATE

const XML_PATH_CONFIRMED_EMAIL_TEMPLATE = 'customer/create_account/email_confirmed_template'

Definition at line 71 of file Customer.php.

◆ XML_PATH_CUSTOMER_RESET_PASSWORD_LINK_EXPIRATION_PERIOD

const XML_PATH_CUSTOMER_RESET_PASSWORD_LINK_EXPIRATION_PERIOD = 'customer/password/reset_link_expiration_period'

Configuration path to expiration period of reset password link

Definition at line 86 of file Customer.php.

◆ XML_PATH_FORGOT_EMAIL_IDENTITY

const XML_PATH_FORGOT_EMAIL_IDENTITY = 'customer/password/forgot_email_identity'

Definition at line 59 of file Customer.php.

◆ XML_PATH_FORGOT_EMAIL_TEMPLATE

const XML_PATH_FORGOT_EMAIL_TEMPLATE = 'customer/password/forgot_email_template'

Definition at line 57 of file Customer.php.

◆ XML_PATH_GENERATE_HUMAN_FRIENDLY_ID

const XML_PATH_GENERATE_HUMAN_FRIENDLY_ID = 'customer/create_account/generate_human_friendly_id'

Definition at line 73 of file Customer.php.

◆ XML_PATH_IS_CONFIRM

const XML_PATH_IS_CONFIRM = 'customer/create_account/confirm'

◆ XML_PATH_REGISTER_EMAIL_IDENTITY

const XML_PATH_REGISTER_EMAIL_IDENTITY = 'customer/create_account/email_identity'

Definition at line 53 of file Customer.php.

◆ XML_PATH_REGISTER_EMAIL_TEMPLATE

const XML_PATH_REGISTER_EMAIL_TEMPLATE = 'customer/create_account/email_template'

Configuration paths for email templates and identities

Definition at line 51 of file Customer.php.

◆ XML_PATH_REMIND_EMAIL_TEMPLATE

const XML_PATH_REMIND_EMAIL_TEMPLATE = 'customer/password/remind_email_template'

Definition at line 55 of file Customer.php.

◆ XML_PATH_RESET_PASSWORD_TEMPLATE

const XML_PATH_RESET_PASSWORD_TEMPLATE = 'customer/password/reset_password_template'

Definition at line 61 of file Customer.php.


The documentation for this class was generated from the following file: