Discussions

Update commerce cart form view on ajax submit

Hi!

I have altered the views_form_commerce_cart_form_default form to allow ajax submission on quantity change.

My ajax attribute is as follows:

$ajax_field_settings = array(
  'event' => 'blur',
  'callback' => '_ajax_cart_update_cart',
  'method' => 'replace',
  'wrapper' => 'ajax-cart-form-wrapper',
  'progress' => array('type' => 'none'),
);

foreach (element_children($form['edit_quantity']) as $key) {
  $form['edit_quantity'][$key]['#ajax'] = $ajax_field_settings;
}

The ajax callback is:

function _ajax_cart_update_cart($form, $form_state) {
  // submits form
  views_form_views_form_submit($form, $form_state);
  commerce_cart_line_item_views_form_submit($form, $form_state);

  // return updated cart view
  return commerce_cart_view();
}

The two first callback are the usual cart form callbacks used to save the form and line items. The functions returns the cart view (the original callback from the menu item 'cart'. Thing works perfectly except one little thing. The line total does not change. The order total changes as it should, but the total amount per line stays the same.

Can someone help me out here?

Thanks!

Posted: Apr 2, 2013

Comments