I am building a site that uses order level discounts. If there is a discount line item in the cart and I click the back button, it chokes on the order total calculate procedure because it is trying to get the total of a deceased line item. This is because the order object being used is coming from the form state.

Commerce discount is always rebasing line items at odd times so I believe we need to actually load the order object again. This shouldn't be too costly because it should be cached at this point anyway.

See patch.

CommentFileSizeAuthor
fix_stale_back_submit_order_object.patch744 bytesdpolant

Comments

dpolant’s picture

Status: Active » Needs review

Updating status.

rszrama’s picture

Status: Needs review » Fixed

Agreed. It's dangerous that we're using the order from the form state, because part of the back button submit handler entails updating the order status, resulting in an order save. That's why the order total is getting recalculated, and who knows what other opportunities this might create for us to accidentally resave stale order data. Not sure why I thought it was a good idea to just grab 'er from the form state, but I guess I just figured everything would go down sequentially in a way that doesn't happen in the wild. : )

Committed! Thanks, Dan.

Side note: this looks to be related to #1968712: Order entity in form_state/checkout pane forms is not the same as the one in checkout pane validate/submit callbacks.

Status: Fixed » Closed (fixed)

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

Anonymous’s picture

Issue summary: View changes

typo