We have 3 shipping methods. UPS Fedex and USPS. UPS and Fedex are setup to use a custom packaging type and USPS is setup to use the default Custom Box (1x1x1mm). The ShippingRateWidget checks to see if there’s a package type set for the shipment. If not, it marks a flag $use_default_package_type. Then in the loop where the widget iterates over the shipping methods it sets the package type for the shipment based on the default package type of the shipping method. So the shipment entity ends up keeping the packaging type of the last shipping method. Later, the shipment is saved when you choose a rate and submit the form which saves it using the last shipping method’s packaging type. It isn't changed after that if you select a new rate/shipping method

Comments

ryross created an issue. See original summary.

mikelutz’s picture

This is a quick and dirty and untested patch to fix the problem short term. It resets the package type to empty after building the widget, and then sets it right before calling selectRates. It shouldn't break anything, but it's not the right permanent solution.

mikelutz’s picture

I added a PR which has the above patch and an updated test. Even if we find a better fix, I think the updated test is valid.

https://github.com/drupalcommerce/commerce_shipping/pull/3

mikelutz’s picture

Status: Active » Needs review
mikelutz’s picture

https://github.com/drupalcommerce/commerce_shipping/pull/4

Same code, rebased and squashed to a single commit

bojanz’s picture

Status: Needs review » Needs work

It doesn't make sense to keep the $use_default_package_type logic in the form element at all, since it doesn't work properly.

  • bojanz committed 9e499c5 on 8.x-2.x authored by mikelutz
    Issue #2920242 by mikelutz, bojanz: Shipment always using last shipping...
bojanz’s picture

Status: Needs work » Fixed

Committed an improved fix. Thanks!

Status: Fixed » Closed (fixed)

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