Skip to content

Conversation

@agibson-godaddy
Copy link
Contributor

@agibson-godaddy agibson-godaddy commented May 13, 2025

Summary

This updates our code to only call wcs_get_subscriptions_for_order() if we have an order with a real ID.

Story: MWC-18156

Release: #778 (release PR)

QA

Old FW version

I don't actually know how to reproduce the original issue, so we're just going to confirm behaviour matching with what we know.

  1. Deactivate all SkyVerge plugins except Authorize[dot]net. This just ensures we're definitely loading Anet's version of the framework.
  2. Activate Subscriptions.
  3. Activate Authorize[dot]net (use master branch) and edit this file: woocommerce-gateway-authorize-net-cim/vendor/skyverge/wc-plugin-framework/woocommerce/payment-gateway/integrations/class-sv-wc-payment-gateway-integration-subscriptions.php
  4. Find the add_subscriptions_details_to_order() function definition (changed in this PR) and add logging right after we define $subscriptions.
	public function add_subscriptions_details_to_order( $order, $gateway ) {

		if ( isset( $order->payment ) ) {

			// defaults
			$order->payment->subscriptions = [];
			$order->payment->recurring     = ! empty( $order->payment->recurring ) ?: false;

			// if the order contains a subscription (but is not a renewal)
			if ( wcs_order_contains_subscription( $order ) ) {

				$order->payment->recurring = true;

				$subscriptions = wcs_get_subscriptions_for_order( $order );
+				error_log(sprintf('Order ID: %d; Number Subscriptions: %d', $order->get_id(), count($subscriptions)));

				if ( ! empty( $subscriptions ) ) {

					foreach ( $subscriptions as $subscription ) {

						if ( $subscription instanceof \WC_Subscription ) {

							$order->payment->subscriptions[] = $this->add_subscription_details_to_order( $subscription, false );
						}
					}
				}

			// order is for a subscription renewal
			} elseif ( wcs_order_contains_renewal( $order ) ) {

				$order->payment->recurring = true;

				$subscriptions = wcs_get_subscriptions_for_renewal_order( $order );
+				error_log(sprintf('Order ID: %d; Number Subscriptions: %d', $order->get_id(), count($subscriptions)));

				if ( ! empty( $subscriptions ) ) {

					foreach ( $subscriptions as $subscription ) {

						if ( $subscription instanceof \WC_Subscription ) {

							$order->payment->subscriptions[] = $this->add_subscription_details_to_order( $subscription, true );
						}
					}
				}
			}
		}

		return $order;
	}
  1. Order a subscription product while tailing your logs. Note the results. (I get one subscription like this: Order ID: 1114; Number Subscriptions: 1)

New FW version

  1. Checkout this branch of anet: https://github.com/gdcorp-partners/woocommerce-gateway-authorize-net-cim/pull/117
  2. Run composer install
  3. Edit that same file again woocommerce-gateway-authorize-net-cim/vendor/skyverge/wc-plugin-framework/woocommerce/payment-gateway/integrations/class-sv-wc-payment-gateway-integration-subscriptions.php
  4. Put the same error_log(sprintf('Order ID: %d; Number Subscriptions: %d', $order->get_id(), count($subscriptions))); in place
  5. Order a subscription product while tailing your logs.
    • Results match old FW version

Before merge

  • I have confirmed these changes in each supported minor WooCommerce version

@agibson-godaddy agibson-godaddy self-assigned this May 13, 2025
@agibson-godaddy agibson-godaddy marked this pull request as ready for review May 13, 2025 11:04
Base automatically changed from release/5.15.11 to master May 19, 2025 09:06
Copy link
Contributor

@ajaynes-godaddy ajaynes-godaddy left a comment

Choose a reason for hiding this comment

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

QA checks out. LGTM!

@ajaynes-godaddy ajaynes-godaddy merged commit bcd4103 into master May 24, 2025
5 checks passed
@ajaynes-godaddy ajaynes-godaddy mentioned this pull request May 24, 2025
ajaynes-godaddy added a commit that referenced this pull request May 24, 2025
@agibson-godaddy agibson-godaddy deleted the mwc-18156 branch May 27, 2025 09:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants