View difference between Paste ID: uAHviRMx and LkEGABeQ
SHOW: | | - or go back to the newest paste.
1-
<?php
1+
2
  // give the form a custom callback
3
  $form['commerce_payment']['payment_method']['#ajax']['callback'] = "custom_ajax_order_review_refresh_custom_callback";
4
  //refresh the current order
5
  commerce_cart_order_refresh($form_state['order']);
6
}
7
8
function custom_ajax_order_review_refresh_custom_callback(&$form, $form_state) {
9
  // set the newly selected payment option to the order
10
  $order_id = $form_state['order']->order_id;
11
  $order = commerce_order_load($order_id);
12
  $order->data['payment_method'] = $form['commerce_payment']['payment_method']['#default_value'];
13
14
  // load the order and directly save it again to store the new payment option
15
  $order_wrapper = entity_metadata_wrapper('commerce_order', $order);
16
  commerce_order_save($order_wrapper->value());
17
18
  // define the ajax commands and refresh the targeted fieldsets
19
  $commands = array();
20
  $commands[] = ajax_command_replace("#payment-details", render($form['commerce_payment']['payment_details']));
21
  $commands[] = ajax_command_replace(".view-commerce-cart-summary", render($form['cart_contents']['cart_contents_view']));
22
  return array('#type' => 'ajax', '#commands' => $commands);
23
}