-
Notifications
You must be signed in to change notification settings - Fork 69
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
Use recommended order currency API for multicurrency subscription renewal | switch | resubscribe #4228
Merged
haszari
merged 26 commits into
develop
from
fix/4152-subscribe-renew-multicurrency-order-meta-api
Jun 29, 2022
Merged
Use recommended order currency API for multicurrency subscription renewal | switch | resubscribe #4228
Changes from 4 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
e154bb3
use recommended `WC_Order::get_currency()` for getting renewal currency:
14eb4e3
add changelog
2a78530
Merge branch 'develop' into fix/4152-subscribe-renew-multicurrency-or…
haszari e01a19c
Merge branch 'develop' into fix/4152-subscribe-renew-multicurrency-or…
haszari 20ea6b0
convert id to order/subscription object before calling get_currency:
dfbde74
Merge branch 'develop' into fix/4152-subscribe-renew-multicurrency-or…
haszari c433f4e
fix fatal error on resubscribe – get subscription from ID
bc31724
Merge remote-tracking branch 'origin/fix/4152-subscribe-renew-multicu…
23ec842
Merge branch 'develop' into fix/4152-subscribe-renew-multicurrency-or…
haszari 4b733df
fix override_selected_currency test for renewal case:
37bb933
Repair multicurrency sub switch unit test:
053bf3c
repair multicurrency subs switch in cart unit test:
f45d6b9
refactor mock_wcs_get_order_type_cart_items so can pass a real order id
3d97600
repair multicurrency sub resubscribe unit test:
4a1cfc8
remove a bunch of extraneous whitespace / php linter fixes
02cf94e
remove extraneous whitespace / php linter fixes
1dda55e
add local wrapper for wcs_get_subscription() – attempt psalm fix:
b21922a
Merge branch 'develop' into fix/4152-subscribe-renew-multicurrency-or…
haszari 73780a4
fix mismatched param name in docblock for get_subscription wrapper
d3eeea8
Merge branch 'develop' into fix/4152-subscribe-renew-multicurrency-or…
haszari 76365db
remove incorrect return type (array) from get_subscription test helper +
9290953
Merge remote-tracking branch 'origin/fix/4152-subscribe-renew-multicu…
6c139f6
remove whitespace offending the linter
91cfcc0
Merge branch 'develop' into fix/4152-subscribe-renew-multicurrency-or…
haszari a5ccf31
rename subscription variable – it's resubscribe not switch
98afc22
Merge remote-tracking branch 'origin/fix/4152-subscribe-renew-multicu…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
changelog/fix-4152-subscribe-renew-multicurrency-order-meta-api
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Significance: minor | ||
Type: fix | ||
|
||
Use high-level order currency API for multicurrency subscription renewal orders (get_post_meta is not recommended for orders). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -148,7 +148,7 @@ public function override_selected_currency( $return ) { | |
|
||
$subscription_renewal = $this->cart_contains_renewal(); | ||
if ( $subscription_renewal ) { | ||
return get_post_meta( $subscription_renewal['subscription_renewal']['renewal_order_id'], '_order_currency', true ); | ||
return $subscription_renewal['subscription_renewal']['renewal_order_id']->get_currency(); | ||
} | ||
|
||
$switch_id = $this->get_subscription_switch_id_from_superglobal(); | ||
|
@@ -159,12 +159,12 @@ public function override_selected_currency( $return ) { | |
$switch_cart_items = $this->get_subscription_switch_cart_items(); | ||
if ( 0 < count( $switch_cart_items ) ) { | ||
$switch_cart_item = array_shift( $switch_cart_items ); | ||
return get_post_meta( $switch_cart_item['subscription_switch']['subscription_id'], '_order_currency', true ); | ||
return $switch_cart_item['subscription_switch']['subscription_id']->get_currency(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similarly for these lines as well, however since we're using the subscription ID we should get a subscription object using: Then call |
||
} | ||
|
||
$subscription_resubscribe = $this->cart_contains_resubscribe(); | ||
if ( $subscription_resubscribe ) { | ||
return get_post_meta( $subscription_resubscribe['subscription_resubscribe']['subscription_id'], '_order_currency', true ); | ||
return $subscription_resubscribe['subscription_resubscribe']['subscription_id']->get_currency(); | ||
} | ||
|
||
return $return; | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$subscription_renewal['subscription_renewal']['renewal_order_id']
is an order ID/integer which doesn't have aget_currency()
method.We'll have to get the order object first, i.e.:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
D'oh! Of course! Fixed in 20ea6b0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note in all these I'm returning
$return
instead of hard-coded "false". Should be equivalent, but feels more in-keeping with the function comment.Side note – I don't really understand what this function is doing. The early return when passed
$return = [currency]
param makes no sense to me; if passing a valid currency code, the function can't "override"?woocommerce-payments/includes/multi-currency/Compatibility/WooCommerceSubscriptions.php
Lines 136 to 147 in e01a19c
We can dig into that when testing, I'm still figuring out how to test this 🤔