Custom module refreshing order total on change of payment method

Hi all,

I'm coding a custom module that i'm sure more of us will enjoy. It's goal is to refresh an order's total as soon as the payment method option of the order is changed, so that additional fees depending on payment methods can be studied live before confirming the order.

I've configured the payment method fieldset to display on the review order page on the checkout process (as shown in the attachment).

I've got 90% of the functionality covered, like so: http://pastebin.com/uAHviRMx

There's one last hurdle to take though.

When selecting a new payment method, this new selection is saved to the order OK. The ajax commands refreshes the two targetted fieldsets, but there's a delay in the refresh of the order's cart. I have to do another select of a different payment method in order to display the result of the previously selected radio button.

What am i missing? Thanks for any help :)

Image icon custom_order_total_refresh.jpg203.5 KB
Posted: Oct 27, 2013


Ryan Ryan Szrama on November 12, 2013

Hmm, I know I've dealt with this before, but I can't remember why / how I fixed it. : )

That isn't very helpful, but one thought is have you changed the #ajax refresh callback on that payment methods radio button to return an array of AJAX commands instead of the form element to render / replace? If you do that, you can still make the first command be the form element replacement but target the order total with a separate follow-up command.

Or maybe that's already what you're doing and the delay is caused by something else?

elsteff1385 on November 15, 2013

Found it!

Issue was that the line items in the order had to be updated, because changing the payment method introduces a new line item called "fee".

Fully working and commented solution can be found here: http://pastebin.com/b25iqnPh