Skip to content

Potential error on order edit page when address has extension attributes #10438

@dankocherga

Description

@dankocherga

Potential error on order edit page when address has extension attributes

Preconditions

  1. Magento 2.1.7
  2. PHP 7.0.18

Steps to reproduce

  1. Suppose you init extension attributes of the order address on the sales_order_address_load_after event (any other way is also ok):
        $address = $observer->getEvent()->getAddress();
        $extensionAttributes = $address->getExtensionAttributes();
        if (!$extensionAttributes) {
            $extensionAttributes = $this->extensionAttributesFactory->create();
            $address->setExtensionAttributes($extensionAttributes);
        }
  1. Go to order's admin panel and click "Edit"

Expected result

  1. Order edit page opens

Actual result

  1. 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.

Metadata

Metadata

Assignees

Labels

Fixed in 2.2.xThe issue has been fixed in 2.2 release lineFixed in 2.3.xThe issue has been fixed in 2.3 release lineIssue: Cannot ReproduceCannot reproduce the issue on the latest `2.4-develop` branchIssue: Clear DescriptionGate 2 Passed. Manual verification of the issue description passedIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedIssue: Format is validGate 1 Passed. Automatic verification of issue format passedIssue: Ready for WorkGate 4. Acknowledged. Issue is added to backlog and ready for developmentReproduced on 2.1.xThe issue has been reproduced on latest 2.1 releaseReproduced on 2.2.xThe issue has been reproduced on latest 2.2 releaseReproduced on 2.3.xThe issue has been reproduced on latest 2.3 releasebug report

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions