easydigitaldownloads/Easy-Digital-Downloads — pull request #1803 by carldanley (2013-12-13 21:59:10+00:00)
Title: Improved JS for discount codes in the cart

commit: broke the discount cart JS down into smaller actions that can be toggled on/off with jQuery. This allows us to customize the discount displays and still write our own JS to handle things the way we want; it also removes the constraint of having to stick with the markup used by EDD in the event that we've replaced the checkout_cart template and filtered the discount HTML.

notes:
A lot of this was copied/pasted/moved to new sections to allow for a structure that allows me to easily customize the events that occur when a discount is applied.

With the current iteration, I can't stop the things in `processDiscountAJAX` (in this PR) from happening which translates to clunky popups (https://github.com/easydigitaldownloads/Easy-Digital-Downloads/blob/master/assets/js/edd-checkout-global.js#L156) that we don't want. Separating the code into sections like this opens up new hooks:
* `cart.discounts.submit` for when a user wants to submit a coupon code
* `cart.discount.ajaxSuccess` for handling the ajax response my own way
* `cart.discount.ajaxFail` in the event that I want to write a custom error message for my cart.

All that said, I think you need to test the patch to see what's going on here. I want to make sure that everything is still functioning as intended before committing.

To stop default EDD behaviors, I could do:
`$( document.body ).off( 'cart.discount.ajaxSuccess' );`

and then add my own:
`$( document.body ).on( 'cart.discount.ajaxSuccess', function( discount_response, recalculate_taxes ) { /* ... */ } );`

I just noticed that I have an inconsistency with `cart.discounts` and `cart.discount` so I'll patch now for consistency.

Interested to hear your feedback.