Skip to content

Null order in Magento\Sales\Block\Order\PrintShipment.php #9830

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

Closed
dnadle opened this issue Jun 2, 2017 · 11 comments
Closed

Null order in Magento\Sales\Block\Order\PrintShipment.php #9830

dnadle opened this issue Jun 2, 2017 · 11 comments
Assignees
Labels
Component: Sales Fixed in 2.1.x The issue has been fixed in 2.1 release line 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: 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

Comments

@dnadle
Copy link

dnadle commented Jun 2, 2017

Viewing an order in the customer dashboard and clicking the print order link causes the following entry in httpd error_log:

PHP Fatal error: Call to a member function getRealOrderId() on null in /vendor/magento/module-sales/Block/Order/PrintShipment.php on line 58

Preconditions

Magento 2.1.6

Steps to reproduce

Log in as customer, go to Account Dashboard. Click My Orders, choose an order and click View Order, then click Print Order.

Expected result

No error in httpd error_log.

Actual result

The error described above is logged.

@YevSent
Copy link
Contributor

YevSent commented Jun 2, 2017

Hi, @dnadle, please, provide additional details to reproduce this issue, like products in the order, shipment, etc. I've checked on Magento 2.1.6 and there are no any errors in Magento and Apache logs.

@dnadle
Copy link
Author

dnadle commented Jun 4, 2017

I stepped through the code. The backend is trying to load the "current" order from a registry but the order is null, and this is not checked before the call to order->getRealOrderId() on line 58. The print version of the order is generated anyway and looks correct.

So, to reproduce the issue one must figure out why the order retrieved from the registry would be null. Regardless of any specific aspects of the order, calling a function on an object that could be null is bad code. It's a bug and should be fixed.

@bve-9384
Copy link

bve-9384 commented Jun 4, 2017

I experience the same issue, using Magento 2.1.7.
PHP Fatal error: Uncaught Error: Call to a member function getRealOrderId() on null in .../magento2/vendor/magento/module-sales/Block/Order/PrintShipment.php:58

Page URL: /sales/order/print/order_id/123/
Same issue for all orders, but page still looks fine

@veloraven
Copy link
Contributor

Internal ticket was created: MAGETWO-69787

@veloraven veloraven added the Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development label Jun 14, 2017
@dnadle
Copy link
Author

dnadle commented Jun 14, 2017

This has something to do with full page caching. PrintShipment::_prepareLayout() is called 4 times successfully by an execution chain renders the print version of the order correctly. But then it is called again, by a different chain for which the registry is not properly initialized and this _prepareLayout() call exits with the fatal error. I don't yet know what is triggering this second rendering, but if you disable full page caching it does not occur and there is no error message logged.

@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 Progress: needs update Component: Sales 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 Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed and removed Progress: needs update labels Sep 18, 2017
@magento-engcom-team magento-engcom-team added 2.2.x 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 labels Oct 11, 2017
@rogyar
Copy link
Contributor

rogyar commented Oct 22, 2017

This happens because of the incorrect block class definition. The #11631 contains fix for the order items list. Also, it fixes the error mentioned here

@okorshenko
Copy link
Contributor

The issue has been fixed in 2.1-develop branch and will be available with next patch release

@okorshenko okorshenko added the Fixed in 2.1.x The issue has been fixed in 2.1 release line label Nov 9, 2017
@ihor-sviziev ihor-sviziev reopened this Sep 4, 2018
@ihor-sviziev
Copy link
Contributor

ihor-sviziev commented Sep 4, 2018

@engcom-backlog-nickolas I have this issue on Magento 2.2.5 when built-in Full Page Cache enabled.

I re-opened this issue. Could you re-check if you can reproduce this issue?

This issue appears when Magento sends AJAX request to backend like this (the same steps to reproduce, but just cancel print dialog and wait few seconds):
https://magento2-example.com/page_cache/block/render/order_id/1/?blocks=%5B%22sales.order.print.info%22%5D&handles=%5B%22default%22%2C%22sales_order_print%22%2C%22print%22%5D&originalRequest=%7B%22route%22%3A%22sales%22%2C%22controller%22%3A%22order%22%2C%22action%22%3A%22print%22%2C%22uri%22%3A%22%2Fsales%2Forder%2Fprint%2Forder_id%2F1%2F%22%7D&version=version_id

@magento-engcom-team
Copy link
Contributor

@ihor-sviziev Internal ticket reopened. Thanks for investigation.

@sidolov
Copy link
Contributor

sidolov commented Sep 25, 2018

Hi @dnadle. Thank you for your report.
The issue has been fixed in #17998 by @MateuszChrapek in 2.2-develop branch
Related commit(s):

The fix will be available with the upcoming 2.2.8 release.

@slavvka
Copy link
Member

slavvka commented Oct 3, 2018

Hi @dnadle. Thank you for your report.
The issue has been fixed in #18272 by @mage2pratik in 2.3-develop branch
Related commit(s):

The fix will be available with the upcoming 2.3.1 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Sales Fixed in 2.1.x The issue has been fixed in 2.1 release line 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: 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
Projects
None yet
Development

No branches or pull requests