10 use Magento\Customer\Api\Data\CustomerInterfaceFactory;
13 use Magento\Customer\Model\ResourceModel\Address\CollectionFactory;
220 private $accountConfirmation;
266 \
Magento\Framework\Data\Collection\AbstractDb $resourceCollection =
null,
271 $this->_scopeConfig = $scopeConfig;
274 $this->_configShare = $configShare;
276 $this->_addressesFactory = $addressesFactory;
277 $this->_transportBuilder = $transportBuilder;
286 ->get(AccountConfirmation::class);
311 public function getDataModel()
317 $addressesData[] =
$address->getDataModel();
319 $customerDataObject = $this->customerDataFactory->create();
320 $this->dataObjectHelper->populateWithArray(
323 \
Magento\Customer\Api\Data\CustomerInterface::class
325 $customerDataObject->setAddresses($addressesData)
326 ->setId($this->
getId());
327 return $customerDataObject;
338 $customerDataAttributes = $this->dataObjectProcessor->buildOutputDataArray(
350 $customAttributes =
$customer->getCustomAttributes();
351 if ($customAttributes !==
null) {
363 if (!$this->getAttributeSetId()) {
364 $this->setAttributeSetId(
396 __(
"This account isn't confirmed. Verify and try again.")
401 __(
'Invalid login or password.')
404 $this->_eventManager->dispatch(
405 'customer_customer_authenticated',
406 [
'model' => $this,
'password' => $password]
432 $this->
_getResource()->changePassword($this, $newPassword);
445 if ($this->_config->getAttribute(
'customer',
'prefix')->getIsVisible() && $this->getPrefix()) {
446 $name .= $this->getPrefix() .
' ';
448 $name .= $this->getFirstname();
449 if ($this->_config->getAttribute(
'customer',
'middlename')->getIsVisible() && $this->getMiddlename()) {
450 $name .=
' ' . $this->getMiddlename();
452 $name .=
' ' . $this->getLastname();
453 if ($this->_config->getAttribute(
'customer',
'suffix')->getIsVisible() && $this->getSuffix()) {
454 $name .=
' ' . $this->getSuffix();
510 if ($this->_addressesCollection ===
null) {
513 )->addAttributeToSelect(
516 foreach ($this->_addressesCollection as
$address) {
541 if ($this->_attributes ===
null) {
542 $this->_attributes = $this->
_getResource()->loadAllAttributes($this)->getSortedAttributes();
570 $this->
setData(
'password', $password);
584 return $this->_encryptor->getHash($password, $salt);
595 $hash = $this->getPasswordHash();
599 return $this->_encryptor->validateHash($password, $hash);
610 return $this->_encryptor->encrypt($password);
621 return $this->_encryptor->decrypt($password);
634 return $primaryAddress ? $primaryAddress :
false;
685 if ($this->getDefaultBilling()) {
686 $ids[] = $this->getDefaultBilling();
688 if ($this->getDefaultShipping()) {
689 $ids[] = $this->getDefaultShipping();
703 if ($primaryBilling) {
705 $primaryBilling->setIsPrimaryBilling(
true);
709 if ($primaryShipping) {
710 if ($primaryBilling && $primaryBilling->getId() == $primaryShipping->getId()) {
711 $primaryBilling->setIsPrimaryShipping(
true);
713 $primaryShipping->setIsPrimaryShipping(
true);
730 if (!in_array(
$address->getId(), $primatyIds)) {
748 return $address->getId() == $this->getDefaultBilling() ||
$address->getId() == $this->getDefaultShipping();
764 if (!isset($types[
$type])) {
765 throw new \Magento\Framework\Exception\LocalizedException(
766 __(
'The transactional account email type is incorrect. Verify and try again.')
774 $this->_sendEmailTemplate(
776 self::XML_PATH_REGISTER_EMAIL_IDENTITY,
777 [
'customer' => $this,
'back_url' => $backUrl,
'store' => $this->
getStore()],
793 $websiteId = $this->getWebsiteId() ? $this->getWebsiteId() :
null;
795 return $this->accountConfirmation->isConfirmationRequired(
$websiteId, $this->
getId(), $this->getEmail());
805 return md5(uniqid());
815 $this->_sendEmailTemplate(
816 self::XML_PATH_REMIND_EMAIL_TEMPLATE,
817 self::XML_PATH_FORGOT_EMAIL_IDENTITY,
818 [
'customer' => $this,
'store' => $this->
getStore()],
834 protected function _sendEmailTemplate(
$template, $sender, $templateParams = [],
$storeId =
null)
837 $transport = $this->_transportBuilder->setTemplateIdentifier(
839 )->setTemplateOptions(
844 $this->_scopeConfig->getValue($sender, ScopeInterface::SCOPE_STORE,
$storeId)
849 $transport->sendMessage();
866 $this->_sendEmailTemplate(
867 self::XML_PATH_FORGOT_EMAIL_TEMPLATE,
868 self::XML_PATH_FORGOT_EMAIL_IDENTITY,
869 [
'customer' => $this,
'store' => $this->
getStore()],
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,
892 return $this->
getData(
'group_id');
902 if (!$this->
getData(
'tax_class_id')) {
903 $groupTaxClassId = $this->_groupRepository->getById($this->
getGroupId())->getTaxClassId();
904 $this->
setData(
'tax_class_id', $groupTaxClassId);
906 return $this->
getData(
'tax_class_id');
916 return $this->_storeManager->getStore($this->getStoreId());
926 $ids = $this->
_getData(
'shared_store_ids');
930 $ids = $this->_storeManager->getWebsite($this->getWebsiteId())->getStoreIds();
932 foreach ($this->_storeManager->getStores() as
$store) {
936 $this->
setData(
'shared_store_ids', $ids);
949 $ids = $this->
_getData(
'shared_website_ids');
953 $ids[] = $this->getWebsiteId();
955 foreach ($this->_storeManager->getWebsites() as
$website) {
959 $this->
setData(
'shared_website_ids', $ids);
972 $this->setStoreId(
$store->getId());
973 $this->setWebsiteId(
$store->getWebsite()->getId());
995 if (isset($this->_isSubscribed)) {
996 unset($this->_isSubscribed);
1008 $this->_addressesCollection =
null;
1019 $this->_errors[] = $error;
1040 $this->_errors = [];
1052 return parent::beforeDelete();
1062 $indexer = $this->indexerRegistry->get(self::CUSTOMER_GRID_INDEXER_ID);
1064 $this->
_getResource()->addCommitCallback([$this,
'reindex']);
1066 return parent::afterSave();
1077 return parent::afterDeleteCommit();
1085 public function reindex()
1088 $indexer = $this->indexerRegistry->get(self::CUSTOMER_GRID_INDEXER_ID);
1099 $date = $this->getCreatedAt();
1101 return (
new \
DateTime($date))->getTimestamp();
1115 $this->_attributes =
null;
1138 $this->_isDeleteable = (bool)
$value;
1160 $this->_isReadonly = (bool)
$value;
1173 if (!$this->
getId()) {
1180 $skipConfirmationIfEmail = $this->_registry->registry(
"skip_confirmation_if_email");
1181 if (!$skipConfirmationIfEmail) {
1185 return strtolower($skipConfirmationIfEmail) === strtolower($this->getEmail());
1199 foreach ($newAddressCollection as
$address) {
1223 if ($this->getWebsiteId() != 0 && empty($defaultStoreId)) {
1224 $storeIds = $this->_storeManager->getWebsite($this->getWebsiteId())->getStoreIds();
1226 $defaultStoreId = current($storeIds);
1228 return $defaultStoreId;
1242 if (!is_string($passwordLinkToken) || empty($passwordLinkToken)) {
1244 __(
'A valid password reset token is missing. Enter and try again.')
1247 $this->
_getResource()->changeResetPasswordLinkToken($this, $passwordLinkToken);
1258 $linkToken = $this->getRpToken();
1259 $linkTokenCreatedAt = $this->getRpTokenCreatedAt();
1261 if (empty($linkToken) || empty($linkTokenCreatedAt)) {
1267 $currentTimestamp = (new \DateTime())->getTimestamp();
1268 $tokenTimestamp = (new \DateTime($linkTokenCreatedAt))->getTimestamp();
1269 if ($tokenTimestamp > $currentTimestamp) {
1273 $dayDifference = floor(($currentTimestamp - $tokenTimestamp) / (24 * 60 * 60));
1274 if ($dayDifference >= $expirationPeriod) {
1288 return (
int)$this->_scopeConfig->getValue(
1289 self::XML_PATH_CUSTOMER_RESET_PASSWORD_LINK_EXPIRATION_PERIOD,
1299 return $this->_addressFactory->create();
1307 return $this->_addressesFactory->create();
1336 if ($this->getLockExpires()) {
1337 $lockExpires = new \DateTime($this->getLockExpires());
1338 if ($lockExpires >
new \
DateTime()) {
1353 return (
string) $this->
getData(
'password_confirm');
1364 return (
string) $this->
getData(
'password');
const XML_PATH_REGISTER_EMAIL_IDENTITY
const XML_PATH_CUSTOMER_RESET_PASSWORD_LINK_EXPIRATION_PERIOD
setData($key, $value=null)
_createAddressCollection()
getData($key='', $index=null)
setStore(\Magento\Store\Model\Store $store)
sendNewAccountEmail($type='registered', $backUrl='', $storeId='0')
getDefaultBillingAddress()
getPrimaryShippingAddress()
validatePassword($password)
const XML_PATH_FORGOT_EMAIL_TEMPLATE
const XML_PATH_DEFAULT_ID
_getWebsiteStoreId($defaultStoreId=null)
const XML_PATH_GENERATE_HUMAN_FRIENDLY_ID
encryptPassword($password)
addAddress(Address $address)
const XML_PATH_IS_CONFIRM
authenticate($login, $password)
getResetPasswordLinkExpirationPeriod()
isAddressPrimary(Address $address)
const XML_PATH_REMIND_EMAIL_TEMPLATE
getRandomConfirmationKey()
getDefaultShippingAddress()
hashPassword($password, $salt=true)
setOrigData($key=null, $data=null)
isResetPasswordLinkTokenExpired()
changePassword($newPassword)
getPrimaryAddress($attributeCode)
const XML_PATH_CONFIRMED_EMAIL_TEMPLATE
getAddressById($addressId)
getPrimaryBillingAddress()
decryptPassword($password)
loadByEmail($customerEmail)
const XML_PATH_CONFIRM_EMAIL_TEMPLATE
const XML_PATH_FORGOT_EMAIL_IDENTITY
const CUSTOMER_GRID_INDEXER_ID
getAttribute($attributeCode)
const XML_PATH_RESET_PASSWORD_TEMPLATE
sendPasswordReminderEmail()
const XML_PATH_REGISTER_EMAIL_TEMPLATE
changeResetPasswordLinkToken($passwordLinkToken)
sendPasswordResetConfirmationEmail()
setDataUsingMethod($key, $args=[])
__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)
getAddressItemById($addressId)
if(!isset($_GET['name'])) $name