Skip to content

Conversation

luigifab
Copy link
Contributor

@luigifab luigifab commented Apr 30, 2021

Description

This PR do not save ALL customer addresses when the customer place an order.
I also change the sort order of customer addresses, last added address is displayed first.

OpenMage 20.0.13 / PHP 7.4.6, 8.0.11, 8.0.18

Manual testing scenarios

First, you need a customer with addresses.

  • Add in app/code/core/Mage/Customer/Model/Address.php:
    protected function _beforeSave()
    {
        Mage::log('! _beforeSave '.$this->getId());
        return parent::_beforeSave();
    }
  • Place an order, check logs.
  • Apply the PR and try again.

Contribution checklist

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All automated tests passed successfully (all builds are green)

@github-actions github-actions bot added the Component: Customer Relates to Mage_Customer label Apr 30, 2021
@kiatng kiatng added the performance Performance related label Apr 30, 2021
luigifab and others added 2 commits April 30, 2021 15:16
Co-authored-by: Ng Kiat Siong <kiatsiong.ng@gmail.com>
@luigifab luigifab marked this pull request as ready for review May 13, 2021 08:11
Copy link
Member

@colinmollenhour colinmollenhour left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work!

->setIsCustomerSaveTransaction(true);
}

if (($address->getIsPrimaryBilling() || $address->getIsDefaultBilling())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I tested this in backend:

            } else {
                if ($address->getParentId() != $customer->getId()) {
                    $address->setParentId($customer->getId());
                }
                Mage::getSingleton('adminhtml/session')->addNotice("is address #{$address->getId()} save?");
                if ($address->hasDataChanges()) {
                    $address->setStoreId($customer->getStoreId())
                        ->setIsCustomerSaveTransaction(true)
                        ->save();
                    Mage::getSingleton('adminhtml/session')->addSuccess("address #{$address->getId()} saved");
                } else {
                    $address->setStoreId($customer->getStoreId())
                        ->setIsCustomerSaveTransaction(true);
                }

I got this:
image

@luigifab Can you check?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this does not work on customer edit page.
Like this does not work when you save address on frontend.

@addison74
Copy link
Contributor

Before merging this I would like to discuss this feature:

"I also change the sort order of customer addresses, last added address is displayed first."

What benefits it brings? What happens in customer account and in Backend? What happens in ordering form?

@luigifab
Copy link
Contributor Author

I only changed the sort order of customer addresses collection, from asc to desc.
With that, you see last address first, like last order, last product, last comment...

@fballiano fballiano merged commit dfb6fe8 into OpenMage:1.9.4.x May 10, 2022
@github-actions
Copy link
Contributor

Unit Test Results

1 files  ±0  1 suites  ±0   0s ⏱️ ±0s
0 tests ±0  0 ✔️ ±0  0 💤 ±0  0 ❌ ±0 
7 runs  +1  5 ✔️ +1  2 💤 +2  0 ❌  - 2 

Results for commit dfb6fe8. ± Comparison against base commit cc3eff3.

@luigifab luigifab deleted the customer-addresses branch May 10, 2022 14:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Customer Relates to Mage_Customer performance Performance related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants