On edit shipment (e.g. /admin/commerce/orders/X/shipments/XX/edit) there is an infinite loop caused by CurrencyHelper::isAdminOrder().

What happened:

1. CurrencyOrderRefresh::checkCurrency event subscriber ORDER_LOAD is leading to CurrencyHelper::isAdminOrder() check
2. CurrencyHelper::isAdminOrder() loads order again from route param triggering CommerceContentEntityStorage::postLoad() that dispatches ORDER_LOAD event again in loop

as a result You get 'Error: Maximum function nesting level of '256' reached, aborting! in is_array()'.

Comments

agolubic created an issue. See original summary.

agolubic’s picture

StatusFileSize
new3.85 KB
valic’s picture

Status: Needs review » Needs work
Related issues: +#3099944: Unable to create admin order.

This is introduced in 3099944 because the order object is not available, but order id in some cases.

I see that commerce_shipment is extending admin route providers now, and therefor shipment edit form is admin route.
Think it was not before when have chosen to go with the current approach.

This needs to be completely removed, and for any check on admin we should take into consideration only the admin path defined by routes, it is most cleanest way to do it.

There is no point in adding more specific checks for each case


  /**
   * Check admin route.
   */
  public function checkAdminRoute() {
    // Get current route. Skip admin path.
    return \Drupal::service('router.admin_context')->isAdminRoute($this->routeMatch->getRouteObject());
  }
sorabh.v6’s picture

StatusFileSize
new4.52 KB

Hi,

I used the $order we get in the CurrencyOrderRefresh event subscriber class. Its working on my local, and it doesn't use the database query directly.

Please check and give feedback, if any.

Thanks

sorabh.v6’s picture

Status: Needs work » Needs review
sorabh.v6’s picture

StatusFileSize
new4.54 KB

Hi,

Previous patch is missing one check, added that in this new patch.

Thanks

valic’s picture

Assigned: Unassigned » valic
Status: Needs review » Needs work

There is a simpler way it seems to fix this

valic’s picture

Title: Infinite loop on shipment edit > CurrencyHelper::isAdminOrder() » Resolve any admin create order and shipments problem - Infinite loop on shipment edit > CurrencyHelper::isAdminOrder()

Adjusting the title to more reflect upcoming patch

valic’s picture

Title: Resolve any admin create order and shipments problem - Infinite loop on shipment edit > CurrencyHelper::isAdminOrder() » Resolve any admin CRUD tasks in relation with order and shipments - Infinite loop on shipment edit > CurrencyHelper::isAdminOrder()
valic’s picture

Title: Resolve any admin CRUD tasks in relation with order and shipments - Infinite loop on shipment edit > CurrencyHelper::isAdminOrder() » Resolve any admin CRUD problem in relation with order and shipments - Infinite loop on shipment edit > CurrencyHelper::isAdminOrder()
valic’s picture

Priority: Normal » Critical
Status: Needs work » Needs review
StatusFileSize
new30 KB

Initial patch attached.

There were a few more changes, but added test coverage for commerce admin orders and shipment admin handling.

We in fact are running core tests, wrapped with injected different currentCurrency than core tests.
That should confirm that we are not influencing any admin CRUD action.

\Drupal\Tests\commerce_order\FunctionalJavascript\OrderAdminTest
\Drupal\Tests\commerce_shipping\FunctionalJavascript\ShipmentAdminTest

So three tests cases are still going to fail

Status: Needs review » Needs work

The last submitted patch, 11: 3150116-11.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

valic’s picture

Status: Needs work » Needs review
StatusFileSize
new29.31 KB
new456 bytes

Removing some debug lines from shipping. (that is the reason for failing those)

Now we are down to two failing tests from core

testCreateOrder
testAdminOrderView

Status: Needs review » Needs work

The last submitted patch, 13: 3150116-13.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

valic’s picture

Status: Needs work » Needs review
StatusFileSize
new36.77 KB
new9.22 KB

Needed to rework path changes, it seems for now it is easiest just ignore /admin completely.
Until 2.x overall rewrite, this ought to be enough.

With core commerce/shipping tests passing with injected different current currency value.

valic’s picture

Status: Needs review » Reviewed & tested by the community

Nice!

All tests are passing, ours for cart/checkout, and core commerce/shipping for creating orders/shipments through admin UI with injected different currentCurrency.

Most definitely committing this today 🥳 .

  • valic committed 7395e25 on 8.x-1.x
    Issue #3150116 by valic, sorabh.v6, agolubic: Resolve any admin CRUD...
valic’s picture

Assigned: valic » Unassigned
Status: Reviewed & tested by the community » Fixed

Committed.

This is the last big change before moving to 2.x version of the module
2.x plan

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.