Tax rate rules and autofill

Posts: 70
Joined: 04/14/2008

I'm seeing the exact same behavior observed in this thread. Taxes aren't displayed in the "Order total preview" pane on the checkout page when address information is autofilled (w/ firefox). When the information is entered manually, or if the page is refreshed following an autofill, it appears to update properly.

I'm assuming the preview is generated w/ JS or jQuery? What events are used to trigger the update? onBlur, perhaps? I find this behavior really odd, and a bit of a limitation from a customer service standpoint, and would love to help resolve it.

Posts: 5245
Joined: 08/07/2007
AdministratorHead Code Monkey - I eat bugs.

There are several ways for this to get triggered, primarily onchanges. However, Google seems to bypass any JS event. I'm not sure what a solution would entail.

Posts: 70
Joined: 04/14/2008

I suppose I wasn't accurate in my description -- it's not the "exact" behavior as described in the previous thread. I wasn't using Google toolbar to complete the autofill -- I simply used firefox's autocomplete feature to test it out. I'll see how it behaves in safari as well. Using onchange certainly makes sense -- although it would appear autocomplete fills on text fields don't trigger an onchange.

Where's the order preview code located?

Posts: 70
Joined: 04/14/2008

Never mind. I found it. Looks like it uses jQuery event binding to change events for the text fields if I'm not mistaken. I don't see any reason why this shouldn't work unless autocomplete just doesn't trigger a change event. This probably isn't anything new -- maybe there's something out there about this in the drupal world. I'll dig around and see what I can find out.

Posts: 70
Joined: 04/14/2008

I did a little thinking on this, and it seems to me autofill shouldn't matter. Since the tax rule depends on a postal zone and nothing else, autofill doesn't apply. so I did a little test --

Tax rules are applied via a change event on the postal zone field of the BILLING information. No other info is necessary. If you populate the information in the billing fields via the "My billing information is the same as my delivery information" checkbox, the change event for the billing fields isn't triggered, and the tax information doesn't update.

If you change the state in the billing information by hand, it works as expected.

So seems to me all that would be required is a tweak to the update code to have it update the preview line items whenever the clone info checkbox is checked as well. Seems that's doable, no?

Posts: 70
Joined: 04/14/2008

I haven't wired this up yet to test it, but might adding a triggerTaxCallback funtion similar to the triggerQuoteCallback function work? Or perhaps even calling setTaxCallback from within setQuoteCallback (maybe not the later -- looks like it is bound to radio button change events within the shipping methods filed (div id="quote")).

I'll keep thinking on this.

Gash

Posts: 70
Joined: 04/14/2008

I think I've found a fix. Change the following function in sites/all/modules/ubercart/uc_taxes/uc_taxes.js:

$(document).ready(function() {
  getTax();
  $("select[@name*=delivery_country], "
    + "select[@name*=delivery_zone], "
    + "input[@name*=delivery_postal_code], "
    + "select[@name*=billing_country], "
    + "select[@name*=billing_zone], "
    + "input[@name*=billing_postal_code]").change(getTax);
});

Add an event watch for the copy_address checkbox:

$(document).ready(function() {
  getTax();
  $("select[@name*=delivery_country], "
    + "select[@name*=delivery_zone], "
    + "input[@name*=delivery_postal_code], "
    + "select[@name*=billing_country], "
    + "select[@name*=billing_zone], "
    + "input[@name*=billing_postal_code], "
    + "input[@name*=copy_address]").change(getTax);
});

That will ensure tax rules are applied if the billing address is copied from the shipping address.

Gash

Posts: 2243
Joined: 08/07/2007
AdministratoreLiTe!

Tax calculations are actually based off the delivery address if it's available. If only the billing address exists, it'll use that, but the delivery address is given priority. Therefore, nothing should have to change if the "same address" checkbox is checked or not. Taxes should have already been calculated for that address.

Posts: 70
Joined: 04/14/2008

Based on the function I pasted from uc_taxes, I agree that it should work that way, but for some reason it's not in my install. onChange event for changes to the shipping zone select box don't result in an update to the preview line items. The small stopwatch animation doesn't even appear in the preview pane to show that an update to the line items has been called.

Posts: 70
Joined: 04/14/2008

I am, officially, the dumbest person on the planet (at least for today). I was utterly puzzled as to why I wasn't seeing updates when I changed the shipping zone. I obviously fell down the rabbit hole of trying to jimmy the JS to make it behave like I wanted. After walking away from it for a bit (and having my morning coffee), I decided to have a look at my workflow-ng settings. Turns out I had selected only the billing zone. Making an or group with the shipping zone as well fixed things perfectly. Imagine that.

Since I've proved myself as completely worthless, I send my apologies to you as developers. Sometimes my propensity for utter stupidity astounds me (but at least I'll own up to it!).

Posts: 5245
Joined: 08/07/2007
AdministratorHead Code Monkey - I eat bugs.

hehe No sweat. I appreciate you taking the time to post your progress, even if it turned out to be unrelated. It's a lot easier to help someone who gives more information that little information. Smiling