Can we make the firing of the click() event in render_line_items() an optional thing? The event is fired on the '#edit-panes-payment-current-total' DOM item after its value is updated. I assume the firing of this event allows other modules to get notified when the total is updated.
However, this can lead to an infinite loop if the notified modules use the event to make their own adjustments to the line items. In this case, the module is notified about the update, makes its own updates, and is notified again, and so makes its own updates again, and on and on...
What's a use case? A discount module that needs to recalculate and apply its discount whenever other modules add line items. For example, a customer may use a promo code to apply a 15% discount -- and then might choose the gift wrapping option, which adds $4 to the order. It would be ideal for the promo code module to listen for the update, and then adjust its total discount. As it is now, the $4 gets tacked on without a discount and can confuse the customer (who doesn't realize that the values will sort themselves out once they submit the form.)
So what I'm proposing is that render_line_items() in uc_payment.js look like this:
function render_line_items(click) {
if(click == null) {
click = TRUE; //default to true for backward compatability
}
...
if(click) {
$('#edit-panes-payment-current-total').val(cur_total).click();
}
...
}
We would also have to modify set_line_item() so we could pass along the extra parameter when it calls render_line_items(). Setting the parameter default to TRUE would allow for backward compatibility.
Making this change would allow modules that manipulate the line items at checkout to do a better job of showing actual totals.
Thoughts? Other ways to do this? Thanks!
Comments
Comment #1
longwaveThis tangle of JavaScript is extremely ugly, but something we cannot really change very much now in 2.x without breaking backward compatibility. In 3.x, this has all been replaced with true Ajax functionality.