Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- 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) {
- // load the current order
- $order_id = $form_state['order']->order_id;
- $order = commerce_order_load($order_id);
- // set the newly selected payment option to the order
- $order->data['payment_method'] = $form['commerce_payment']['payment_method']['#default_value'];
- // refresh the current order (more specific: update it's line items
- commerce_cart_order_refresh($order);
- // save the refreshed order (more specific: recalculate the order total and save it)
- commerce_order_save($order);
- // 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', views_embed_view('commerce_cart_summary', 'default', $order_id));
- return array('#type' => 'ajax', '#commands' => $commands);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement