Skip to content

[BUG] Guest order shipping address overwritten by billing address during order edit #5212

@DegrizNet

Description

@DegrizNet

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

When editing a guest order in the admin panel, if the order originally had different billing and shipping addresses, the shipping address is incorrectly overwritten by the billing address during the initialization of the "Edit Order" process.

This happens because Mage_Sales_Model_Quote_Address::_populateBeforeSaveData contains logic that forces the same_as_billing flag to 1 for guest orders if the address is new (which it is during the initFromOrder process).

Expected Behavior

When editing order address should be different.

Steps To Reproduce

  1. Create a guest order with different billing and shipping addresses.
  2. In the Admin Panel, go to Sales > Orders and open the order.
  3. Click the Edit button.
  4. Observe that the Shipping Address section now contains the Billing Address data, and the "Same As Billing Address" checkbox is checked.

Environment

- OpenMage 20.15.0
- php: 8.3

Anything else?

Root Cause In app/code/core/Mage/Sales/Model/Quote/Address.php, the method _populateBeforeSaveData has the following logic:

if (!$this->getId()) {
    $this->setSameAsBilling((int) $this->_isSameAsBilling());
}

For guest orders, _isSameAsBilling() returns true if the customer is not registered. This logic overwrites any value explicitly set during the order conversion process (e.g., in Mage_Adminhtml_Model_Sales_Order_Create::initFromOrder).

Proposed Fix
Modify the condition to only apply the default guest logic if the same_as_billing flag has not been explicitly set yet.

--- app/code/core/Mage/Sales/Model/Quote/Address.php
+++ app/code/core/Mage/Sales/Model/Quote/Address.php
@@ -342,7 +342,7 @@
              * Set same_as_billing to "1" when default shipping address is set as default
              * and it is not equal billing address
              */
-            if (!$this->getId()) {
+            if (!$this->getId() && !$this->hasSameAsBilling()) {
                 $this->setSameAsBilling((int) $this->_isSameAsBilling());
             }
         }

Why this is correct
By checking !$this->hasSameAsBilling(), we ensure that if the conversion logic has already determined that the addresses are different (and thus called setSameAsBilling(0)), we don't revert that decision based on the generic guest rule. This preserves the data integrity during order editing and reordering.

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions