If an order entity contains payment_gateway, and we have some shipping method with "Limit by payment gateway" restriction, the method \Drupal\commerce_payment\Plugin\Commerce\Condition\OrderPaymentGateway::evaluate is trying to get its ID and fails with

Error: InvalidArgumentException: Unable to get a value with a non-numeric delta in a list.

We need to get payment gateway ID in correct way

$payment_gateway_id = $order->get('payment_gateway')->target_id;
instead of
$payment_gateway_id = $order->get('payment_gateway')->get('target_id');

Comments

martin_klima created an issue. See original summary.

martin_klima’s picture

Version: 8.x-2.6 » 8.x-2.x-dev
Status: Active » Needs review
StatusFileSize
new1.07 KB

Patch attached

Status: Needs review » Needs work

The last submitted patch, 2: commerce_get-payment-gw-id_2969613_2.patch, failed testing. View results

bojanz’s picture

We actually need $order->get('payment_gateway')->first()->get('target_id');
And we need to update the unit test that is failing.

martin_klima’s picture

Status: Needs work » Needs review
StatusFileSize
new4.38 KB

I updated the failing test. I'm not experienced in such kind of tests, and I didn't know how to test first(), then get(), so I used getValue() and tested it locally.

If you think, the $order->get('payment_gateway')->first()->get('target_id') is better approach than getValue(), let me know and I will rewrite it.

Status: Needs review » Needs work

The last submitted patch, 5: commerce_get-payment-gw-id_2969613_5.patch, failed testing. View results

martin_klima’s picture

Status: Needs work » Needs review
StatusFileSize
new3.99 KB
bojanz’s picture

Title: Getting payment gateway entity ID fails » The OrderPaymentGateway condition is broken

Retitling.

  • bojanz committed 34a9659 on 8.x-2.x authored by martin_klima
    Issue #2969613 by martin_klima: The OrderPaymentGateway condition is...
bojanz’s picture

Status: Needs review » Fixed

Tweaked and committed, thanks!

Status: Fixed » Closed (fixed)

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