Score:0

How to refresh and reload (with ajax?) order checkout panes and order calculation independent from commerce cart refresh (e.g. billing address change)

fr flag

I have following problem:

During checkout, my customer has to fill in his billing address (at least at the first time) to calculate VAT rate and gross price. Further calculation is done via an order processor after that. So far it works fine.

My problem is, that the cart order refresh doesn't refresh the checkout panes (like the order summary) via AJAX, when the billing country (and so perhaps the valid VAT rate, too) has changed. The user has to reload the page in the browser actively or has to submit the form to see an effect, even if the order has been refreshed (and recalculated) behind the scenes already.

  1. How can I force a cart refresh and a recalculation via my custom order processor, independent from the cart order refresh interval?
  2. How can I trigger a reload for my checkout panes (in best case via AJAX, because of better UX), so that the user sees the changes just in time?

I found out that there have been hooks for that in D7 but in D8/D9 the hooks and services seem to exist no more (e.g. commerce_cart_order_refresh() - see: How can I programmatically recalculate an order total after changing the billing country ).

Score:1
kz flag

So you want to refresh some content in the page that's not part of the checkout form? Basically, this can be done using an Ajax callback and one or more Ajax callback commands:

https://www.drupal.org/docs/drupal-apis/ajax-api/core-ajax-callback-commands

You'll need to add an Ajax callback to the country field using a form_alter(), and in this callback return the Ajax commands needed to replace the targeted content, selected by class or id.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.