Basically what is happening is that we fill in an address, hit recalculate, and send it off to ajax land. We get the freshly allocated shipping profile entity from $form_state, and send it to the packer, which sends it to proposed shipments who tries to save the profile id. The problem is the profile is never saved to the database at this point so it doesn't get an id. Then we try to create a real shipment from the proposed shipment, but it doesn't have a profile id to load, so it doesn't get saved to the shipment, and the shipping method plugins don't have a shipping address to use to calculate rates. If you go to checkout review and then back, the profile has an id, and everything gets passed through just fine. So we can either:

Save the profile in the checkout pane build form, right before we send it to the packer manager

Save it in the packer manager before calling the packers if we have a profile entity with no id.

Manually set the shipping profile in the shipment in the PackerManager::packToShipments() function after we create the shipment from the proposed shipment.

All easy fixes, but I wasn't sure which one would be best or most appropriate.

Comments

mikeNCM created an issue. See original summary.

bojanz’s picture

We need to start with a failing test, because CheckoutPaneTest is green right now, even though it shouldn't be.

mikelutz’s picture

Looking at it further, I don't think it's the checkout panes job, I think it belongs to the packer manager to make sure that if it's calling for proposed shipments that it sends a saved profile to the packers. Of course, we may not need a profile to call for the proposed shipment, so we are saying if the manager gets a profile with data but no id, then it needs to be saved. If we have a blank profile, then the proposed shipment has no profile ID, and it's up to the shipping method to decide if it can't calculate a rate without a profile. If that sounds good, I'll write up a patch for the packer manager test, and the fix tomorrow.

bojanz’s picture

Thank you for your great research of this problem, it allowed me to understand it quickly.

We can't start saving the shipping method because it would create orphaned data (profiles) in the database. Our flow is:
1) Provide shipping method data 2) Recalculate (creates shipments) 3) Complete shipments (choose shipping method etc)
Then the page is submitted and the relevant entities are created.

Instead, we should change ProposedShipment::getShippingMethodId() to getShippingMethod(), pass around the whole entity.

I have a patch passing tests, incoming.

  • bojanz committed 6c1b02d on 8.x-2.x
    Issue #2855464: Shipping Profile doesn't make it through to shipping...
bojanz’s picture

Status: Active » Fixed

My computer decided to crash right after that post. Here's the commit.

Status: Fixed » Closed (fixed)

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