Currently I am hooking into the add to cart form on my website. I added ajax to the edit quantity buttons like :
$form_quantity[$key]['#ajax'] = [
'callback' => 'update_cart_order',
'disable-refocus' => FALSE,
'wrapper' => $form_div_id,
'event' => 'change',
'progress' => [
'type' => 'throbber',
'message' => t('Updating Cart...'),
],
];
Which works lovely. I will note that $form_div_id
is an id I'm wrapping the entire form in just above this.
Now I don't think I fully understand what I am supposed to return from my ajax. The view I am hooking into lists the products on one side and the order total on the other.
In my callback I (seem to) successfully update my cart quantities. But returning gets rid of the order total from this form.
I do nothing to edit the form and just return $form
. All I do is update the order item.
I've looked around and think I may not understand what the ajax return really does but cannot seem to make sense of it. I just want to update my total price without refreshing the whole page.
In 'update_cart_order' I am changing the quantities and ending with this :
$order->save();
$order->recalculateTotalPrice();
return $form;
This causes the total price display to disappear. After refreshing the page to get it back the quantities are properly adjusted.
Please let me know if any more information is needed. :)