Skip to content

Commit

Permalink
Do not save customer addresses when there are no changes (#1579)
Browse files Browse the repository at this point in the history
  • Loading branch information
luigifab authored May 10, 2022
1 parent 110e3d0 commit dfb6fe8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
4 changes: 3 additions & 1 deletion app/code/core/Mage/Customer/Model/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -421,9 +421,11 @@ public function getAddressesCollection()
if ($this->_addressesCollection === null) {
$this->_addressesCollection = $this->getAddressCollection()
->setCustomerFilter($this)
->addAttributeToSelect('*');
->addAttributeToSelect('*')
->setOrder('entity_id', 'desc');
foreach ($this->_addressesCollection as $address) {
$address->setCustomer($this);
$address->setDataChanges(false);
}
}

Expand Down
21 changes: 15 additions & 6 deletions app/code/core/Mage/Customer/Model/Resource/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ protected function _afterSave(Varien_Object $customer)
*/
protected function _saveAddresses(Mage_Customer_Model_Customer $customer)
{
$defaultBillingId = $customer->getData('default_billing');
$defaultShippingId = $customer->getData('default_shipping');
$defaultBillingId = $customer->getData('default_billing');
$defaultShippingId = $customer->getData('default_shipping');
foreach ($customer->getAddresses() as $address) {
if ($address->getData('_deleted')) {
if ($address->getId() == $defaultBillingId) {
Expand All @@ -146,10 +146,19 @@ protected function _saveAddresses(Mage_Customer_Model_Customer $customer)
}
$address->delete();
} else {
$address->setParentId($customer->getId())
->setStoreId($customer->getStoreId())
->setIsCustomerSaveTransaction(true)
->save();
if ($address->getParentId() != $customer->getId()) {
$address->setParentId($customer->getId());
}

if ($address->hasDataChanges()) {
$address->setStoreId($customer->getStoreId())
->setIsCustomerSaveTransaction(true)
->save();
} else {
$address->setStoreId($customer->getStoreId())
->setIsCustomerSaveTransaction(true);
}

if (($address->getIsPrimaryBilling() || $address->getIsDefaultBilling())
&& $address->getId() != $defaultBillingId
) {
Expand Down

0 comments on commit dfb6fe8

Please sign in to comment.