Woocommerce-services: Immediately (re) fetch schemas if store country is changed

Created on 8 Jan 2018  Â·  6Comments  Â·  Source: Automattic/woocommerce-services

i.e. don't make a merchant wait for the services schemas cache to expire (1 day) if they change their store country (e.g. from US to CA - that way they can set immediately set up Canada Post and not have to wait)

[Type] Bug

Most helpful comment

We're already hooking into woocommerce_settings_saved to refresh schema data

That action isn't fired when saving through the REST API, I've just checked it. This is a legitimate issue.

don't make a merchant wait for the services schemas cache to expire (1 day) if they change their store country

@allendav Just FYI, we're checking the store currency to select between CanadaPost & USPS.

All 6 comments

@allendav can you provide reproduction steps for this?

We're already hooking into woocommerce_settings_saved to refresh schema data: https://github.com/Automattic/woocommerce-services/blob/master/woocommerce-services.php?utf8=%E2%9C%93#L646

We're already hooking into woocommerce_settings_saved to refresh schema data

That action isn't fired when saving through the REST API, I've just checked it. This is a legitimate issue.

don't make a merchant wait for the services schemas cache to expire (1 day) if they change their store country

@allendav Just FYI, we're checking the store currency to select between CanadaPost & USPS.

Besides — or as part of — fetching schemas in this case, do we want to narrow down a condition for when we actually want to refetch schemas, beyond just any time WC settings are saved?

  • change in store currency, as mentioned above
  • change in measurement units, as mentioned as an example in the original PR
  • change in postcode (used as default origin)

Can we just check for these, or do we want to keep this subject to change on the server (in which case it seems safe to just check for what we're passing in the settings object)?

@DanReyLop wrote:

@allendav Just FYI, we're checking the store currency to select between CanadaPost & USPS.

Could we use detecting a change in store base location country instead?

@allendav As far as I understand, the only reason we care to restrict the services (and cut off the possibility of getting rates from origins in multiple countries) is that we aren't doing any handling of the currency unit, so if the store _currency_ doesn't match what the service returns, the rate amounts would be incorrect. Original issue: https://github.com/Automattic/woocommerce-services/issues/225

Can we just check for these, or do we want to keep this subject to change on the server (in which case it seems safe to just check for what we're passing in the settings object)?

That seems like a fair compromise. Right now, every time anything is changed, the schemas are re-fetched. I suspect that's the reason why some clients are hitting our server dozens of times per minute.

Was this page helpful?
0 / 5 - 0 ratings