Payment Gateway conditions don't work properly for shipping methods in checkout

Created on 5 August 2021, over 3 years ago
Updated 29 August 2023, about 1 year ago

Problem/Motivation

In the Shipping checkout flow, on the Order information pane the available shipping methods are not presented based on the payment method choice.

Steps to reproduce

1. create "PaymentGateway1", "PaymentGateway2"
2. create "ShippingMethod1", "ShippingMethod2"
3. set the Selected payment gateway condition for "ShippingMethod2" to "PaymentGateway2"
4. set the Shipping checkout flow for the order type
5. create products, add them to cart, and start the checkout
6. if you select "PaymentGateway2", the "ShippingMethod2" doesn't appear.

Further problem that an incorrect combination can be set:
7. set in the checkout "PaymentGateway2" with "ShippingMethod1"
8. click to Continue to review
9. go back to Order information
10. you can set "ShippingMethod2" with "PaymentGateway1" (although we disabled that combination in step 3)
11. click to Continue to review
12. now an incorrect combination of shipping methods and payment gateways are set

Proposed resolution

In ShippingRateWidget $this->shipmentManager->calculateRates($shipment) is called but the Order that it checks doesn't contain the selected payment gateway on the checkout form. Find a way to use not just the saved field values but the selection, too.

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Needs work

Version

2.0

Component

Code

Created by

πŸ‡ΈπŸ‡°Slovakia kaszarobert

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡¬πŸ‡·Greece vensires

    I followed the idea from #4 (thank you lubwn) and modified it accordingly to keep any currently selected payment method:

    (function ($) {
      /**
       * Refresh the payment information about updating the shipping information.
       *
       * @see https://www.drupal.org/project/commerce_shipping/issues/3226851#comment-14761180
       */
      $(document).ajaxComplete(function(event, xhr, settings) {
        if (settings.extraData !== undefined && settings.extraData._triggering_element_name.indexOf( "shipping_information") !== -1) {
          let element = $('[id^="edit-payment-information-payment-method"]');
          element
            .find('input:checked').prop("checked", false)
            .click();
        }
      });
    })(jQuery)
    
  • Status changed to Needs work about 1 year ago
  • Here is a patch to update the selected payment gateway using #ajax callback.
    It modifies the ShippingInformation::buildPaneForm() to set the payment_gateway order field when possible. This must be done before building the form and calculating the available shipments.

    The patch should be further improved before committing to be more general on form IDs but fixed the issue for me.

  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 7.3 & MySQL 5.7
    last update about 1 year ago
    133 pass, 4 fail
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 8.0 & MySQL 5.7
    last update about 1 year ago
    133 pass, 4 fail
Production build 0.71.5 2024