Advertisement
Guest User

Untitled

a guest
Nov 15th, 2013
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  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. // load the current order
  11. $order_id = $form_state['order']->order_id;
  12. $order = commerce_order_load($order_id);
  13. // set the newly selected payment option to the order
  14. $order->data['payment_method'] = $form['commerce_payment']['payment_method']['#default_value'];
  15. // refresh the current order (more specific: update it's line items
  16. commerce_cart_order_refresh($order);
  17. // save the refreshed order (more specific: recalculate the order total and save it)
  18. commerce_order_save($order);
  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', views_embed_view('commerce_cart_summary', 'default', $order_id));
  23. return array('#type' => 'ajax', '#commands' => $commands);
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement