-
-
Notifications
You must be signed in to change notification settings - Fork 450
Fix guest order shipping address overwritten by billing address during order edit #5213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
- Modified _populateBeforeSaveData in Address.php to preserve explicitly set same_as_billing flag - Added unit tests to validate the fix for guest and registered customers - Tests verify that explicitly set values are preserved while defaults still apply when not set Co-authored-by: addison74 <[email protected]>
- Remove trailing whitespace from all lines - Add blank line between docblock description and @Covers annotation - Format multi-line assertSame calls to comply with coding standards Co-authored-by: addison74 <[email protected]>
- Change $this->assertSame to self::assertSame (static call) - Add trailing commas after last parameter in all assertSame calls - Remove trailing whitespace after closing braces Co-authored-by: addison74 <[email protected]>
... Fixed all additional PHP CS Fixer errors in commit 41270a6:
|
- Remove setAccessible(true) calls from ReflectionMethod invocations - Not needed in PHP 8.1+ for protected methods accessed via reflection Co-authored-by: addison74 <[email protected]>
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes a bug where guest order shipping addresses were incorrectly overwritten by billing addresses during order edit in the admin panel. The fix adds a conditional check to preserve explicitly set same_as_billing values while maintaining the default behavior for new orders.
Key Changes:
- Added
!$this->hasSameAsBilling()condition to prevent overwriting explicitly set address relationship flags - Comprehensive unit tests covering all scenarios: guest orders with different/same addresses, registered customers, and default behavior
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
app/code/core/Mage/Sales/Model/Quote/Address.php |
Modified line 325 to add !$this->hasSameAsBilling() check, preserving explicitly set same_as_billing values during order edit |
tests/unit/Mage/Sales/Model/Quote/AddressTest.php |
Added comprehensive unit tests covering guest orders, registered customers, explicit values, and default behavior scenarios |



Fix for guest order shipping address overwritten by billing address
Problem Statement
When editing a guest order in the admin panel with different billing and shipping addresses, the shipping address was incorrectly overwritten by the billing address during the initialization of the "Edit Order" process.
Root Cause
In
Mage_Sales_Model_Quote_Address::_populateBeforeSaveData()at line 325, the logic unconditionally setsame_as_billingfor new addresses (without an ID) based on whether the customer is registered. For guest orders,_isSameAsBilling()returns true, which overwrote the explicitly set value frominitFromOrder()that had correctly determined the addresses were different.Solution Implemented
Address.phpandCreate.php!$this->hasSameAsBilling()check to line 325 in Address.phpChanges Made
✅ Modified
/app/code/core/Mage/Sales/Model/Quote/Address.phpline 325if (!$this->getId())if (!$this->getId() && !$this->hasSameAsBilling())same_as_billingvalues are preserved during order editing✅ Created comprehensive unit tests in
/tests/unit/Mage/Sales/Model/Quote/AddressTest.phpHow It Works
The fix checks two conditions before applying default logic:
!$this->getId()- Address is new (no database ID yet)!$this->hasSameAsBilling()- No explicit value has been setThis means:
initFromOrder()setssame_as_billing=0(different addresses), it's preservedinitFromOrder()setssame_as_billing=1(same addresses), it's preservedImpact
This is a minimal, surgical fix that:
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.