Guest User

Untitled

a guest
Oct 27th, 2013
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. function custom_ajax_order_review_refresh_form_commerce_checkout_form_review_alter(&$form, &$form_state) {
  3. // give the form a custom callback
  4. $form['commerce_payment']['payment_method']['#ajax']['callback'] = "custom_ajax_order_review_refresh_custom_callback";
  5. //refresh the current order
  6. commerce_cart_order_refresh($form_state['order']);
  7. }
  8.  
  9. function custom_ajax_order_review_refresh_custom_callback(&$form, $form_state) {
  10. // set the newly selected payment option to the order
  11. $order_id = $form_state['order']->order_id;
  12. $order = commerce_order_load($order_id);
  13. $order->data['payment_method'] = $form['commerce_payment']['payment_method']['#default_value'];
  14.  
  15. // load the order and directly save it again to store the new payment option
  16. $order_wrapper = entity_metadata_wrapper('commerce_order', $order);
  17. commerce_order_save($order_wrapper->value());
  18.  
  19. // define the ajax commands and refresh the targeted fieldsets
  20. $commands = array();
  21. $commands[] = ajax_command_replace("#payment-details", render($form['commerce_payment']['payment_details']));
  22. $commands[] = ajax_command_replace(".view-commerce-cart-summary", render($form['cart_contents']['cart_contents_view']));
  23. return array('#type' => 'ajax', '#commands' => $commands);
  24. }
Advertisement
Add Comment
Please, Sign In to add comment