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

Use recommended order currency API for multicurrency subscription renewal | switch | resubscribe #4228

Merged
merged 26 commits into from
Jun 29, 2022
Merged
Show file tree
Hide file tree
Changes from all 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:
May 4, 2022
14eb4e3
add changelog
May 4, 2022
2a78530
Merge branch 'develop' into fix/4152-subscribe-renew-multicurrency-or…
haszari May 4, 2022
e01a19c
Merge branch 'develop' into fix/4152-subscribe-renew-multicurrency-or…
haszari May 8, 2022
20ea6b0
convert id to order/subscription object before calling get_currency:
May 9, 2022
dfbde74
Merge branch 'develop' into fix/4152-subscribe-renew-multicurrency-or…
haszari Jun 14, 2022
c433f4e
fix fatal error on resubscribe – get subscription from ID
Jun 14, 2022
bc31724
Merge remote-tracking branch 'origin/fix/4152-subscribe-renew-multicu…
Jun 14, 2022
23ec842
Merge branch 'develop' into fix/4152-subscribe-renew-multicurrency-or…
haszari Jun 15, 2022
4b733df
fix override_selected_currency test for renewal case:
Jun 17, 2022
37bb933
Repair multicurrency sub switch unit test:
Jun 17, 2022
053bf3c
repair multicurrency subs switch in cart unit test:
Jun 23, 2022
f45d6b9
refactor mock_wcs_get_order_type_cart_items so can pass a real order id
Jun 23, 2022
3d97600
repair multicurrency sub resubscribe unit test:
Jun 23, 2022
4a1cfc8
remove a bunch of extraneous whitespace / php linter fixes
Jun 23, 2022
02cf94e
remove extraneous whitespace / php linter fixes
Jun 23, 2022
1dda55e
add local wrapper for wcs_get_subscription() – attempt psalm fix:
Jun 23, 2022
b21922a
Merge branch 'develop' into fix/4152-subscribe-renew-multicurrency-or…
haszari Jun 23, 2022
73780a4
fix mismatched param name in docblock for get_subscription wrapper
Jun 23, 2022
d3eeea8
Merge branch 'develop' into fix/4152-subscribe-renew-multicurrency-or…
haszari Jun 27, 2022
76365db
remove incorrect return type (array) from get_subscription test helper +
Jun 27, 2022
9290953
Merge remote-tracking branch 'origin/fix/4152-subscribe-renew-multicu…
Jun 27, 2022
6c139f6
remove whitespace offending the linter
Jun 27, 2022
91cfcc0
Merge branch 'develop' into fix/4152-subscribe-renew-multicurrency-or…
haszari Jun 28, 2022
a5ccf31
rename subscription variable – it's resubscribe not switch
Jun 28, 2022
98afc22
Merge remote-tracking branch 'origin/fix/4152-subscribe-renew-multicu…
Jun 29, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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).
26 changes: 22 additions & 4 deletions includes/multi-currency/Compatibility/WooCommerceSubscriptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ 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 );
$order = wc_get_order( $subscription_renewal['subscription_renewal']['renewal_order_id'] );
return $order ? $order->get_currency() : $return;
}

$switch_id = $this->get_subscription_switch_id_from_superglobal();
Expand All @@ -158,13 +159,15 @@ 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 );
$switch_cart_item = array_shift( $switch_cart_items );
$switch_subscription = $this->get_subscription( $switch_cart_item['subscription_switch']['subscription_id'] );
return $switch_subscription ? $switch_subscription->get_currency() : $return;
}

$subscription_resubscribe = $this->cart_contains_resubscribe();
if ( $subscription_resubscribe ) {
return get_post_meta( $subscription_resubscribe['subscription_resubscribe']['subscription_id'], '_order_currency', true );
$subscription = $this->get_subscription( $subscription_resubscribe['subscription_resubscribe']['subscription_id'] );
return $subscription ? $subscription->get_currency() : $return;
}

return $return;
Expand Down Expand Up @@ -293,6 +296,21 @@ private function get_subscription_switch_cart_items(): array {
return wcs_get_order_type_cart_items( 'switch' );
}

/**
* Getter for subscription objects.
*
* @param mixed $the_subscription Post object or post ID of the order.
* @return mixed The subscription object, or false if it cannot be found.
* Note: this is WC_Subscription|bool in normal use, but in tests
* we use WC_Order to simulate a subscription (hence `mixed`).
*/
private function get_subscription( $the_subscription ) {
if ( ! function_exists( 'wcs_get_subscription' ) ) {
return false;
}
return wcs_get_subscription( $the_subscription );
}

/**
* Checks $_GET superglobal for a switch id and returns it if found.
*
Expand Down
Loading