Skip to content

Commit d5b84d6

Browse files
Merge remote-tracking branch 'remotes/github/MAGETWO-91513' into EPAM-PR-23
2 parents d432abd + de8d0a9 commit d5b84d6

File tree

4 files changed

+63
-32
lines changed

4 files changed

+63
-32
lines changed

app/code/Magento/Customer/Model/AccountManagement.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1384,6 +1384,7 @@ public function changeResetPasswordLinkToken($customer, $passwordLinkToken)
13841384
$customerSecure->setRpTokenCreatedAt(
13851385
$this->dateTimeFactory->create()->format(DateTime::DATETIME_PHP_FORMAT)
13861386
);
1387+
$this->setIgnoreValidationFlag($customer);
13871388
$this->customerRepository->save($customer);
13881389
}
13891390
return true;
@@ -1537,4 +1538,15 @@ private function destroyCustomerSessions($customerId)
15371538
$this->saveHandler->destroy($sessionId);
15381539
}
15391540
}
1541+
1542+
/**
1543+
* Set ignore_validation_flag for reset password flow to skip unnecessary address and customer validation
1544+
*
1545+
* @param Customer $customer
1546+
* @return void
1547+
*/
1548+
private function setIgnoreValidationFlag($customer)
1549+
{
1550+
$customer->setData('ignore_validation_flag', true);
1551+
}
15401552
}

app/code/Magento/Customer/Model/ResourceModel/Customer.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,9 @@ protected function _beforeSave(\Magento\Framework\DataObject $customer)
151151
$customer->setConfirmation(null);
152152
}
153153

154-
$this->_validate($customer);
154+
if (!$customer->getData('ignore_validation_flag')) {
155+
$this->_validate($customer);
156+
}
155157

156158
return $this;
157159
}

app/code/Magento/Customer/Model/ResourceModel/Customer/Relation.php

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -23,41 +23,43 @@ public function processRelation(\Magento\Framework\Model\AbstractModel $customer
2323
$defaultBillingId = $customer->getData('default_billing');
2424
$defaultShippingId = $customer->getData('default_shipping');
2525

26-
/** @var \Magento\Customer\Model\Address $address */
27-
foreach ($customer->getAddresses() as $address) {
28-
if ($address->getData('_deleted')) {
29-
if ($address->getId() == $defaultBillingId) {
30-
$customer->setData('default_billing', null);
31-
}
26+
if (!$customer->getData('ignore_validation_flag')) {
27+
/** @var \Magento\Customer\Model\Address $address */
28+
foreach ($customer->getAddresses() as $address) {
29+
if ($address->getData('_deleted')) {
30+
if ($address->getId() == $defaultBillingId) {
31+
$customer->setData('default_billing', null);
32+
}
3233

33-
if ($address->getId() == $defaultShippingId) {
34-
$customer->setData('default_shipping', null);
35-
}
34+
if ($address->getId() == $defaultShippingId) {
35+
$customer->setData('default_shipping', null);
36+
}
3637

37-
$removedAddressId = $address->getId();
38-
$address->delete();
38+
$removedAddressId = $address->getId();
39+
$address->delete();
3940

40-
// Remove deleted address from customer address collection
41-
$customer->getAddressesCollection()->removeItemByKey($removedAddressId);
42-
} else {
43-
$address->setParentId(
44-
$customer->getId()
45-
)->setStoreId(
46-
$customer->getStoreId()
47-
)->setIsCustomerSaveTransaction(
48-
true
49-
)->save();
41+
// Remove deleted address from customer address collection
42+
$customer->getAddressesCollection()->removeItemByKey($removedAddressId);
43+
} else {
44+
$address->setParentId(
45+
$customer->getId()
46+
)->setStoreId(
47+
$customer->getStoreId()
48+
)->setIsCustomerSaveTransaction(
49+
true
50+
)->save();
5051

51-
if (($address->getIsPrimaryBilling() ||
52-
$address->getIsDefaultBilling()) && $address->getId() != $defaultBillingId
53-
) {
54-
$customer->setData('default_billing', $address->getId());
55-
}
52+
if (($address->getIsPrimaryBilling() ||
53+
$address->getIsDefaultBilling()) && $address->getId() != $defaultBillingId
54+
) {
55+
$customer->setData('default_billing', $address->getId());
56+
}
5657

57-
if (($address->getIsPrimaryShipping() ||
58-
$address->getIsDefaultShipping()) && $address->getId() != $defaultShippingId
59-
) {
60-
$customer->setData('default_shipping', $address->getId());
58+
if (($address->getIsPrimaryShipping() ||
59+
$address->getIsDefaultShipping()) && $address->getId() != $defaultShippingId
60+
) {
61+
$customer->setData('default_shipping', $address->getId());
62+
}
6163
}
6264
}
6365
}

app/code/Magento/Customer/Model/ResourceModel/CustomerRepository.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ public function save(CustomerInterface $customer, $passwordHash = null)
222222
) {
223223
$customerModel->setDefaultShipping($prevCustomerDataArr['default_shipping']);
224224
}
225+
$this->setValidationFlag($customerArr, $customerModel);
225226
$customerModel->save();
226227
$this->customerRegistry->push($customerModel);
227228
$customerId = $customerModel->getId();
@@ -231,7 +232,7 @@ public function save(CustomerInterface $customer, $passwordHash = null)
231232
) {
232233
$customer->setAddresses($delegatedNewOperation->getCustomer()->getAddresses());
233234
}
234-
if ($customer->getAddresses() !== null) {
235+
if ($customer->getAddresses() !== null && !$customerModel->getData('ignore_validation_flag')) {
235236
if ($customer->getId()) {
236237
$existingAddresses = $this->getById($customer->getId())->getAddresses();
237238
$getIdFunc = function ($address) {
@@ -396,4 +397,18 @@ protected function addFilterGroupToCollection(FilterGroup $filterGroup, Collecti
396397
$collection->addFieldToFilter($fields);
397398
}
398399
}
400+
401+
/**
402+
* Set ignore_validation_flag to skip model validation
403+
*
404+
* @param array $customerArray
405+
* @param Customer $customerModel
406+
* @return void
407+
*/
408+
private function setValidationFlag($customerArray, $customerModel)
409+
{
410+
if (isset($customerArray['ignore_validation_flag'])) {
411+
$customerModel->setData('ignore_validation_flag', true);
412+
}
413+
}
399414
}

0 commit comments

Comments
 (0)