Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/support postcode restrictions #153

Open
wants to merge 17 commits into
base: main
Choose a base branch
from

Conversation

dpanta94
Copy link

All Submissions:

  • Does your code follow the Extendables standards?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully run tests with your changes locally?

Changes proposed in this Pull Request:

Closes woo#117 .

How to test the changes in this Pull Request:

  1. Create a shipping rule for a state or country with postcode restrictions
  2. The same state or country shouldn't have more generic shipping rules since the most generic option will be passed to Amazon
  3. Try to make a purchase using Amazon Pay for an address that is included in the specified postcode restrictions and one for which isn't
  4. For the first Amazon should allow you to continue with the selected address, while with the second it shouldn't

Other information:

  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?

Changelog entry

Add - Support for postcode restrictions defined in WooCommerce > Shipping, to be supplied to Amazon API.

@dpanta94 dpanta94 requested a review from ksere March 11, 2022 20:37
@dpanta94 dpanta94 self-assigned this Mar 11, 2022
Copy link
Member

@ksere ksere left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some comments, mostly to make sure we have considered some things.

<p>
<?php
esc_html_e(
'Ranges covering thousands or more of postcodes may slow down your site, since Amazon Pay does not support postcode ranges we loop from the minimum until we reach the maximum in order to include them all. Try to use the asterisk (*) wildcard when possible for faster loading times.',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should test with a large number of postcodes (99k ?) to make sure it works.
If it ends up clogging the payload & making API requests fail, it may be better to try something different.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are correct, when using 99k zip codes as range Amazon API fails. Will try to think of an alternative.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, that's potentially a blocker.

One option would be to notify the user that their settings are "incompatible" with what Amazon supports, and not include those postcodes in the API call - so that it doesn't fail.
But again we would need to know/find what the threshold should be at which we are triggering that scenario.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented an algorithm where ranges are converted to wildcards using the '?' symbol supported by the Amazon API. Let me know your thoughts

@dpanta94 dpanta94 requested a review from ksere March 28, 2022 17:52
Copy link
Member

@ksere ksere left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good,

Left a comment about the new transient in use.
Also if possible the new stuff could be split into another file, maybe a helper class or somewhere else fitting better. Just to not add to the weight of the file.

Didn't get into how it actually works, the approach looks good, will leave it for QA to figure out where it breaks 🚀

case 'postcode':
$postcode = $location->code;
if ( strstr( $postcode, '...' ) ) {
$pers_ps_array = get_transient( 'woocommerce_amazon_pa_ps_rules_' . self::RANGE_TO_WILDCARDS_ALGO_VERSION . '_' . md5( $postcode ) );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the called method so heavy that we need a transient?
Usually we want to cache heavy DB queries or calls to remote resources.
Calculations, string operations etc can add up in some cases but here I am not sure a transient will be faster at least on setups without Object caching.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea you are right. In most cases, running the method would be less load than querying the DB. I will ask for a extensive QA checks to find out how it works in various cases. Will remove the transient for the time being.

@dpanta94 dpanta94 requested a review from ksere March 28, 2022 19:34
Copy link
Member

@ksere ksere left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👨‍🎤 🤖

@dpanta94 dpanta94 added the qa Quality Assurance label Mar 30, 2022
@dpanta94 dpanta94 requested a review from alexiglesias31 April 5, 2022 22:04
Copy link

@alexiglesias31 alexiglesias31 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a minot comment, not a blocker.

@dpanta94 dpanta94 removed their assignment Oct 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
qa Quality Assurance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants