1

I'm quite obsessed on one page checkout using drupal commerce kickstart. I'm using commerce coupon(wonderful module) and we all know that there's a possibility that the order total price could be zero if you we apply a 100% coupon module. I see this post Commerce - how to set no payment for free orders when 100% coupon applied and I guess we are having the same problem. I did not see any way to ajax refresh the payment method pane, and my last work around is to reload the entire page after applying coupons.

Is there a way to reload the entire page after applying coupons?

Thanks.

2
  • I've never used commerce, but you could check to see if there's a Rules Event for applying a coupon and go from there
    – Geoff
    May 7, 2015 at 3:31
  • @Geoff I already tried that option. I add a redirect action after applying coupon using rules. Unfortunately, it doesn't redirect or load to the page I specified. I guess it is because coupons is using ajax. Thanks for the help!
    – Imat
    May 8, 2015 at 6:16

1 Answer 1

0

One solution here is to add a custom JS behavior to your module that looks for the AJAX callback context of applying a coupon. Upon such context, you can refresh the page or update the DOM as you see fit.

(function ($) {
Drupal.behaviors.mymodule = {
  attach: function (context, settings) {

    //Look for the context of a coupon form AJAX callback
    //If there's no error message, assume successful coupon application
    if($(context[0]).attr('id') == 'commerce-checkout-coupon-ajax-wrapper' && !$(context[0]).find('.messages').hasClass('error')) {
      //@TODO: Reload page or other JS to refresh coupon usage
    }
  }
};
}(jQuery));
1
  • Very much appreciated @shawn. I found out that it is not needed to refresh the page or create a callback function to refresh the payment method pane. I just add a custom condition on Rules so Drupal will automatically skip the payment processing if the total amount of order is less than 0 or 0. Thank you so much for your response. Perhaps I can use this on other circumstances.
    – Imat
    Sep 4, 2015 at 8:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.