-
-
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e87de2b
Initial plan
Copilot 9df7fe9
Fix guest order shipping address overwrite issue
Copilot 8db9588
Fix PHP CS Fixer errors in AddressTest.php
Copilot 41270a6
Fix additional PHP CS Fixer errors in AddressTest.php
Copilot 7156cfe
Fix Rector errors in AddressTest.php
Copilot a9e63a3
Update tests/unit/Mage/Sales/Model/Quote/AddressTest.php
sreichel 2896b35
Merge branch 'main' into copilot/fix-guest-order-address-overwrite
sreichel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,160 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * @copyright For copyright and license information, read the COPYING.txt file. | ||
| * @link /COPYING.txt | ||
| * @license Open Software License (OSL 3.0) | ||
| * @package OpenMage_Tests | ||
| */ | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace unit\Mage\Sales\Model\Quote; | ||
|
|
||
| use Mage; | ||
| use Mage_Customer_Model_Group; | ||
| use Mage_Sales_Model_Quote; | ||
| use Mage_Sales_Model_Quote_Address; | ||
| use OpenMage\Tests\Unit\OpenMageTest; | ||
|
|
||
| final class AddressTest extends OpenMageTest | ||
| { | ||
| /** | ||
| * Test that explicitly set same_as_billing flag is preserved for guest orders | ||
| * | ||
| * This test validates the fix for the issue where guest order shipping addresses | ||
| * were being overwritten by billing addresses during order edit. | ||
| * | ||
| * @covers Mage_Sales_Model_Quote_Address::_populateBeforeSaveData | ||
| * @group Model | ||
| */ | ||
| public function testPreservesExplicitlySetSameAsBillingForGuestOrders(): void | ||
| { | ||
| // Create a quote for a guest customer (no customer ID) | ||
| $quote = new Mage_Sales_Model_Quote(); | ||
| $quote->setCustomerId(null); | ||
| $quote->setCustomerGroupId(Mage_Customer_Model_Group::NOT_LOGGED_IN_ID); | ||
|
|
||
| // Create a shipping address with different data than billing | ||
| $address = new Mage_Sales_Model_Quote_Address(); | ||
| $address->setQuote($quote); | ||
| $address->setAddressType(Mage_Sales_Model_Quote_Address::TYPE_SHIPPING); | ||
|
|
||
| // Explicitly set same_as_billing to false (0) to indicate different addresses | ||
| // This simulates what happens during order edit when addresses differ | ||
| $address->setSameAsBilling(0); | ||
|
|
||
| // Trigger the _populateBeforeSaveData method via _beforeSave | ||
| // This is normally called when saving the address | ||
| $reflectionClass = new \ReflectionClass($address); | ||
| $method = $reflectionClass->getMethod('_populateBeforeSaveData'); | ||
| $method->invoke($address); | ||
|
|
||
| // Assert that the explicitly set value was preserved | ||
| self::assertSame( | ||
| 0, | ||
| $address->getSameAsBilling(), | ||
| 'Explicitly set same_as_billing=0 should be preserved for guest orders during order edit', | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Test that same_as_billing is set to default for new addresses without explicit value | ||
| * | ||
| * @covers Mage_Sales_Model_Quote_Address::_populateBeforeSaveData | ||
| * @group Model | ||
| */ | ||
| public function testSetsDefaultSameAsBillingForNewGuestAddressesWithoutExplicitValue(): void | ||
| { | ||
| // Create a quote for a guest customer (no customer ID) | ||
| $quote = new Mage_Sales_Model_Quote(); | ||
| $quote->setCustomerId(null); | ||
| $quote->setCustomerGroupId(Mage_Customer_Model_Group::NOT_LOGGED_IN_ID); | ||
|
|
||
| // Create a shipping address WITHOUT explicitly setting same_as_billing | ||
| $address = new Mage_Sales_Model_Quote_Address(); | ||
| $address->setQuote($quote); | ||
| $address->setAddressType(Mage_Sales_Model_Quote_Address::TYPE_SHIPPING); | ||
|
|
||
| // DO NOT set same_as_billing - let the default logic handle it | ||
|
|
||
| // Trigger the _populateBeforeSaveData method | ||
| $reflectionClass = new \ReflectionClass($address); | ||
| $method = $reflectionClass->getMethod('_populateBeforeSaveData'); | ||
| $method->invoke($address); | ||
|
|
||
| // For guest orders, default behavior should set same_as_billing to 1 | ||
| self::assertSame( | ||
| 1, | ||
| $address->getSameAsBilling(), | ||
| 'Default same_as_billing=1 should be set for new guest shipping addresses without explicit value', | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Test that explicitly set same_as_billing=1 is preserved | ||
| * | ||
| * @covers Mage_Sales_Model_Quote_Address::_populateBeforeSaveData | ||
| * @group Model | ||
| */ | ||
| public function testPreservesExplicitlySetSameAsBillingTrue(): void | ||
| { | ||
| // Create a quote for a guest customer | ||
| $quote = new Mage_Sales_Model_Quote(); | ||
| $quote->setCustomerId(null); | ||
| $quote->setCustomerGroupId(Mage_Customer_Model_Group::NOT_LOGGED_IN_ID); | ||
|
|
||
| // Create a shipping address | ||
| $address = new Mage_Sales_Model_Quote_Address(); | ||
| $address->setQuote($quote); | ||
| $address->setAddressType(Mage_Sales_Model_Quote_Address::TYPE_SHIPPING); | ||
|
|
||
| // Explicitly set same_as_billing to true (1) | ||
| $address->setSameAsBilling(1); | ||
|
|
||
| // Trigger the _populateBeforeSaveData method | ||
| $reflectionClass = new \ReflectionClass($address); | ||
| $method = $reflectionClass->getMethod('_populateBeforeSaveData'); | ||
| $method->invoke($address); | ||
|
|
||
| // Assert that the explicitly set value was preserved | ||
| self::assertSame( | ||
| 1, | ||
| $address->getSameAsBilling(), | ||
| 'Explicitly set same_as_billing=1 should be preserved', | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Test that the fix works for registered customers with different addresses | ||
| * | ||
| * @covers Mage_Sales_Model_Quote_Address::_populateBeforeSaveData | ||
| * @group Model | ||
| */ | ||
| public function testPreservesExplicitlySetSameAsBillingForRegisteredCustomers(): void | ||
| { | ||
| // Create a quote for a registered customer | ||
| $quote = new Mage_Sales_Model_Quote(); | ||
| $quote->setCustomerId(123); // Registered customer | ||
|
|
||
| // Create a shipping address | ||
| $address = new Mage_Sales_Model_Quote_Address(); | ||
| $address->setQuote($quote); | ||
| $address->setAddressType(Mage_Sales_Model_Quote_Address::TYPE_SHIPPING); | ||
|
|
||
| // Explicitly set same_as_billing to false | ||
| $address->setSameAsBilling(0); | ||
|
|
||
| // Trigger the _populateBeforeSaveData method | ||
| $reflectionClass = new \ReflectionClass($address); | ||
| $method = $reflectionClass->getMethod('_populateBeforeSaveData'); | ||
| $method->invoke($address); | ||
|
|
||
| // Assert that the explicitly set value was preserved | ||
| self::assertSame( | ||
| 0, | ||
| $address->getSameAsBilling(), | ||
| 'Explicitly set same_as_billing=0 should be preserved for registered customers', | ||
| ); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.