Skip to content
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

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

Closed
dankocherga opened this issue Aug 4, 2017 · 6 comments
Closed
Assignees
Labels
bug report Fixed in 2.2.x The issue has been fixed in 2.2 release line Fixed in 2.3.x The issue has been fixed in 2.3 release line Issue: Cannot Reproduce Cannot reproduce the issue on the latest `2.4-develop` branch Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Reproduced on 2.1.x The issue has been reproduced on latest 2.1 release Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release

Comments

@dankocherga
Copy link

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.

@magento-engcom-team magento-engcom-team added G1 Passed bug report Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed and removed G1 Passed labels Sep 5, 2017
@magento-engcom-team magento-engcom-team added the Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed label Sep 18, 2017
@magento-engcom-team
Copy link
Contributor

@dankocherga From github code I can only get error that missing argument in $this->extensionAttributesFactory->create() function. When I tried to customize code I would not receive any error. Pls show all your module code.

@magento-engcom-team magento-engcom-team added Progress: needs update Issue: Cannot Reproduce Cannot reproduce the issue on the latest `2.4-develop` branch labels Sep 18, 2017
@dankocherga
Copy link
Author

@magento-engcom-team
Please look at this sample module: https://github.com/dankocherga/m2-issue-10438
It adds extension attributes to order's shipping and billing address.
Try creating an order and editing it via admin panel.

@magento-engcom-team magento-engcom-team self-assigned this Sep 21, 2017
@magento-engcom-team
Copy link
Contributor

@dankocherga, thank you for your report.
We've created internal ticket(s) MAGETWO-75789 to track progress on the issue.

@magento-engcom-team magento-engcom-team added 2.1.x Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Reproduced on 2.1.x The issue has been reproduced on latest 2.1 release Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release labels Sep 22, 2017
@YevSent
Copy link
Contributor

YevSent commented Oct 20, 2017

I'm working on it #SQUASHTOBERFEST

okorshenko pushed a commit that referenced this issue Nov 21, 2017
@okorshenko okorshenko added the Fixed in 2.2.x The issue has been fixed in 2.2 release line label Nov 21, 2017
@okorshenko
Copy link
Contributor

thank you for your report. The issue has been fixed and delivered to 2.2-develop branch. Will be available with upcoming patch release

@magento-engcom-team
Copy link
Contributor

Hi @dankocherga. Thank you for your report.
The issue has been fixed in magento-engcom/magento2ce#1362 by @magento-engcom-team in 2.3-develop branch
Related commit(s):

The fix will be available with the upcoming 2.3.0 release.

@magento-engcom-team magento-engcom-team added the Fixed in 2.3.x The issue has been fixed in 2.3 release line label Feb 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug report Fixed in 2.2.x The issue has been fixed in 2.2 release line Fixed in 2.3.x The issue has been fixed in 2.3 release line Issue: Cannot Reproduce Cannot reproduce the issue on the latest `2.4-develop` branch Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Reproduced on 2.1.x The issue has been reproduced on latest 2.1 release Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release
Projects
None yet
Development

No branches or pull requests

5 participants