When updating the address, the default value for the shipping method is not updated.
If the user doesn't manually select an option, submitting the form (with the previous default value) crashes
the review page.

How to replicate the issue:

- On the checkout review page, click to edit the shipping information.
- Change the address and make sure it corresponds to a different shipping method than the selected one (eg: change the country)
- Click on 'Recalculate shipping'

The shipping methods are updated successfully but there is no value selected by default.

- Click 'Continue to review' WITHOUT selecting a shipping method

This will create an error and will crash the website.

After some investigation, I realised that when the shipping is recalculated the default value is not updated and keeps the previous value submitted. Hence, when submitting the form the widget tries to access a value that doesn't exist anymore.
The method extractFormValues() is looking for a non defined index.

On the patch below, I implemented an afterBuild method on ShippingRateWidget that updates the default value and added a condition when calculating the default value.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

andreastkdf created an issue. See original summary.

andreastkdf’s picture

Title: updating the shipping information crashes the review page if no shipping method selected » Updating the shipping information crashes the review page if no shipping method selected
andreastkdf’s picture

Issue summary: View changes
andreastkdf’s picture

andreastkdf’s picture

Version: 8.x-2.x-dev » 8.x-2.0-beta7
jsacksick’s picture

Status: Needs review » Needs work

The patch no longer applies.

I tried reproducing the problem with the latest dev code, a default value is indeed not selected, but submitting the page doesn't actually crash, and the current shipping rate is correctly shown on the review page.

I'm wondering if we couldn't come up with a simpler fix (I'm sure we could find a way to fix this without the after build). I'm pretty sure this is caused by the fact that a rate is present in $form_state['input'], during AJAX operations).

jsacksick’s picture

Status: Needs work » Closed (duplicate)