-
-
Notifications
You must be signed in to change notification settings - Fork 450
Description
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
- Create a guest order with different billing and shipping addresses.
- In the Admin Panel, go to Sales > Orders and open the order.
- Click the Edit button.
- 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.3Anything 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.