Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function custom_ajax_order_review_refresh_form_commerce_checkout_form_review_alter(&$form, &$form_state) {
- // give the form a custom callback
- $form['commerce_payment']['payment_method']['#ajax']['callback'] = "custom_ajax_order_review_refresh_custom_callback";
- //refresh the current order
- commerce_cart_order_refresh($form_state['order']);
- }
- function custom_ajax_order_review_refresh_custom_callback(&$form, $form_state) {
- // set the newly selected payment option to the order
- $order_id = $form_state['order']->order_id;
- $order = commerce_order_load($order_id);
- $order->data['payment_method'] = $form['commerce_payment']['payment_method']['#default_value'];
- // load the order and directly save it again to store the new payment option
- $order_wrapper = entity_metadata_wrapper('commerce_order', $order);
- commerce_order_save($order_wrapper->value());
- // define the ajax commands and refresh the targeted fieldsets
- $commands = array();
- $commands[] = ajax_command_replace("#payment-details", render($form['commerce_payment']['payment_details']));
- $commands[] = ajax_command_replace(".view-commerce-cart-summary", render($form['cart_contents']['cart_contents_view']));
- return array('#type' => 'ajax', '#commands' => $commands);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement