Rates alterations from ShippingEvents::SHIPPING_RATES event are not reflected on the order

Created on 29 February 2024, 6 months ago
Updated 23 August 2024, 15 days ago

Problem/Motivation

When using the ShippingEvents::SHIPPING_RATES event, rates are altered, but those alterations are not reflected in the order.

This means any discounts or markups are shown in the shipping pane, but are not included in the shipping price.
I set this to major, not to be dramatic, but because sites that use the event to mark up rates may have orders being placed with the wrong shipping costs.

Steps to reproduce

  • Add a ShippingEvents::SHIPPING_RATES event subscriber with a custom module.
  • Add two flat rate options through the UI.
  • Alter both rates with your event subscriber.

Result:
When the checkout pane is loaded, the default selected rate is correct, because calculateRates was called, and the rate was applied to the shipment. When you change to the second rate, the rates are correct in the shipping information pane, but the check for $should_refresh prevents the EarlyOrderProcessor from applying the altered rates to the order.

Proposed resolution

Not sure. commenting out:

      if (!$should_refresh) {
        continue;
      }

Allows the altered rates from the event subscriber to be applied, but also causes the rates to be collected, which causes needless requests and responses from carriers.

We should apply the rates upon every selection, but we certainly don't need to recalculate the rates every time a selection is made.

Remaining tasks

Verify the bug through testing, and find a way to reflect the new rates on the shipment.

🐛 Bug report
Status

Fixed

Version

2.0

Component

Code

Created by

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024