-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Closed
Labels
Fixed in 2.2.xThe issue has been fixed in 2.2 release lineThe issue has been fixed in 2.2 release lineFixed in 2.3.xThe issue has been fixed in 2.3 release lineThe issue has been fixed in 2.3 release lineIssue: Cannot ReproduceCannot reproduce the issue on the latest `2.4-develop` branchCannot reproduce the issue on the latest `2.4-develop` branchIssue: Clear DescriptionGate 2 Passed. Manual verification of the issue description passedGate 2 Passed. Manual verification of the issue description passedIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedIssue: Format is validGate 1 Passed. Automatic verification of issue format passedGate 1 Passed. Automatic verification of issue format passedIssue: Ready for WorkGate 4. Acknowledged. Issue is added to backlog and ready for developmentGate 4. Acknowledged. Issue is added to backlog and ready for developmentReproduced on 2.1.xThe issue has been reproduced on latest 2.1 releaseThe issue has been reproduced on latest 2.1 releaseReproduced on 2.2.xThe issue has been reproduced on latest 2.2 releaseThe issue has been reproduced on latest 2.2 releaseReproduced on 2.3.xThe issue has been reproduced on latest 2.3 releaseThe issue has been reproduced on latest 2.3 releasebug report
Description
Potential error on order edit page when address has extension attributes
Preconditions
- Magento 2.1.7
- PHP 7.0.18
Steps to reproduce
- Suppose you init extension attributes of the order address on the
sales_order_address_load_afterevent (any other way is also ok):
$address = $observer->getEvent()->getAddress();
$extensionAttributes = $address->getExtensionAttributes();
if (!$extensionAttributes) {
$extensionAttributes = $this->extensionAttributesFactory->create();
$address->setExtensionAttributes($extensionAttributes);
}- Go to order's admin panel and click "Edit"
Expected result
- Order edit page opens
Actual result
- Order edit page fails with the following error:
Recoverable Error: Object of class Magento\Sales\Api\Data\OrderAddressExtension could not be converted to string in .../module-sales/Model/AdminOrder/Create.php on line 503
The code on this line does the following:
$shippingAddress = $order->getShippingAddress();
if ($shippingAddress) {
$addressDiff = array_diff_assoc($shippingAddress->getData(), $order->getBillingAddress()->getData());
unset($addressDiff['address_type'], $addressDiff['entity_id']);
$shippingAddress->setSameAsBilling(empty($addressDiff));
}The problem is that $shippingAddress object could potentially have extension_attributes field in the data and that field is an object (which is correct).
When you diff arrays with object in a field you get the error:
php > var_dump(array_diff_assoc(['foo' => new stdClass], ['foo' => new stdClass]));
PHP Catchable fatal error: Object of class stdClass could not be converted to string in php shell code on line 1
array_diff_assoc converts values to strings according to the documentation:
Two values from key => value pairs are considered equal only if (string) $elem1 === (string) $elem2 . In other words a strict check takes place so the string representations must be the same.
loggres, yourTatianka, obukhow, semsemyonoff, pavdan and 3 more
Metadata
Metadata
Assignees
Labels
Fixed in 2.2.xThe issue has been fixed in 2.2 release lineThe issue has been fixed in 2.2 release lineFixed in 2.3.xThe issue has been fixed in 2.3 release lineThe issue has been fixed in 2.3 release lineIssue: Cannot ReproduceCannot reproduce the issue on the latest `2.4-develop` branchCannot reproduce the issue on the latest `2.4-develop` branchIssue: Clear DescriptionGate 2 Passed. Manual verification of the issue description passedGate 2 Passed. Manual verification of the issue description passedIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedIssue: Format is validGate 1 Passed. Automatic verification of issue format passedGate 1 Passed. Automatic verification of issue format passedIssue: Ready for WorkGate 4. Acknowledged. Issue is added to backlog and ready for developmentGate 4. Acknowledged. Issue is added to backlog and ready for developmentReproduced on 2.1.xThe issue has been reproduced on latest 2.1 releaseThe issue has been reproduced on latest 2.1 releaseReproduced on 2.2.xThe issue has been reproduced on latest 2.2 releaseThe issue has been reproduced on latest 2.2 releaseReproduced on 2.3.xThe issue has been reproduced on latest 2.3 releaseThe issue has been reproduced on latest 2.3 releasebug report