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

upkeep/1170 Bump PHP "tested up to" version 8.3 #20

Closed
wants to merge 7 commits into from

Conversation

Sidsector9
Copy link
Member

@Sidsector9 Sidsector9 commented Jan 8, 2024

All Submissions:

  • Does your code follow the WooCommerce Sniffs variant of WordPress coding standards?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully run tests with your changes locally?
  • Will this change require new documentation or changes to existing documentation?

Changes proposed in this Pull Request:

This PR simply includes a note regarding the "PHP tested up to: 8.3". While this information may not have direct utility for WordPress/WP.org, it is an internally decided retaining it would be nice to have.

The following steps are tested in the PHP 8.3 environment.

  • ✅ WordPress site connects with Square (sandbox) successfully.
  • ✅ WordPress site disconnects with Square (sandbox) successfully.
  • ✅ Sync from Square to WP site works fine.
  • ✅ Sync from the WP site to Square works fine.
  • ✅ Manual sync by clicking the “Sync now” button from settings works.
  • ✅ “Import all products from Square” setting works and imports products from square to the WP site.
  • ✅ Products are booked using Square payment cards.
  • ✅ For Authorization only transactions, transactions are Held for Review.
  • ✅ Order amounts are captured successfully at the Square dashboard.
  • ✅ A new payment method is added successfully from the Check out page and is also visible under My accounts.
  • ✅ A new payment method is added successfully from My accounts → Payment methods.
  • ✅ An existing payment method is updated successfully.
  • ✅ An existing payment method is deleted successfully.

The following warnings(s) were noticed and fixed. ✅

[19-Dec-2023 11:57:26 UTC] PHP Deprecated:  Creation of dynamic property Automattic\WooCommerce\Admin\Overrides\Order::$payment_total is deprecated in /Users/faisalalvi/LocalSites/wpne/app/public/wp-content/plugins/woocommerce-square/includes/Framework/PaymentGateway/Payment_Gateway.php on line 1628
[19-Dec-2023 11:57:26 UTC] PHP Deprecated:  Creation of dynamic property Automattic\WooCommerce\Admin\Overrides\Order::$payment is deprecated in /Users/faisalalvi/LocalSites/wpne/app/public/wp-content/plugins/woocommerce-square/includes/Framework/PaymentGateway/Payment_Gateway.php on line 1638
[19-Dec-2023 11:57:26 UTC] PHP Deprecated:  Creation of dynamic property Automattic\WooCommerce\Admin\Overrides\Order::$description is deprecated in /Users/faisalalvi/LocalSites/wpne/app/public/wp-content/plugins/woocommerce-square/includes/Framework/PaymentGateway/Payment_Gateway.php on line 1644
[19-Dec-2023 11:57:26 UTC] PHP Deprecated:  Creation of dynamic property Automattic\WooCommerce\Admin\Overrides\Order::$unique_transaction_ref is deprecated in /Users/faisalalvi/LocalSites/wpne/app/public/wp-content/plugins/woocommerce-square/includes/Gateway.php on line 1349
[19-Dec-2023 11:57:26 UTC] PHP Deprecated:  Creation of dynamic property Automattic\WooCommerce\Admin\Overrides\Order::$square_customer_id is deprecated in /Users/faisalalvi/LocalSites/wpne/app/public/wp-content/plugins/woocommerce-square/includes/Gateway.php on line 355
[19-Dec-2023 11:57:26 UTC] PHP Deprecated:  Creation of dynamic property Automattic\WooCommerce\Admin\Overrides\Order::$square_order_id is deprecated in /Users/faisalalvi/LocalSites/wpne/app/public/wp-content/plugins/woocommerce-square/includes/Gateway.php on line 356
[19-Dec-2023 11:57:26 UTC] PHP Deprecated:  Creation of dynamic property Automattic\WooCommerce\Admin\Overrides\Order::$square_version is deprecated in /Users/faisalalvi/LocalSites/wpne/app/public/wp-content/plugins/woocommerce-square/includes/Gateway.php on line 357
[21-Dec-2023 18:04:08 UTC] PHP Deprecated:  Creation of dynamic property Automattic\WooCommerce\Admin\Overrides\Order::$refund is deprecated in /Users/faisalalvi/LocalSites/wpne/app/public/wp-content/plugins/woocommerce-square/includes/Framework/PaymentGateway/Payment_Gateway.php on line 2011

While performing the test, the following warnings were reported that were coming from the WooCommerce. ⚠️

[19-Dec-2023 12:35:20 UTC] PHP Deprecated:  Creation of dynamic property WC_Order_Item_Product::$legacy_values is deprecated in /Users/faisalalvi/LocalSites/wpne/app/public/wp-content/plugins/woocommerce/includes/class-wc-checkout.php on line 520
[19-Dec-2023 12:35:20 UTC] PHP Deprecated:  Creation of dynamic property WC_Order_Item_Product::$legacy_cart_item_key is deprecated in /Users/faisalalvi/LocalSites/wpne/app/public/wp-content/plugins/woocommerce/includes/class-wc-checkout.php on line 521
[19-Dec-2023 12:35:20 UTC] PHP Deprecated:  Creation of dynamic property WC_Order_Item_Shipping::$legacy_package_key is deprecated in /Users/faisalalvi/LocalSites/wpne/app/public/wp-content/plugins/woocommerce/includes/class-wc-checkout.php on line 607

Closes #42.

Steps to test the changes in this Pull Request:

Make sure the plugin works fine in the PHP 8.3 environment and there are 0 errors/warnings reported in the error logs while/after performing the test steps mentioned above.

For the QA

Please test the following:

  1. Simple and variable product purchase and refund.
  2. Credit card, gift card and split payments and refund.
  3. Purchase of subscription products and refund.
  4. All sync types.

Changelog entry

Add - Compatibility with PHP 8.3.

[19-Dec-2023 11:57:26 UTC] PHP Deprecated:  Creation of dynamic property Automattic\WooCommerce\Admin\Overrides\Order::$payment_total is deprecated in /Users/faisalalvi/LocalSites/wpne/app/public/wp-content/plugins/woocommerce-square/includes/Framework/PaymentGateway/Payment_Gateway.php on line 1628
[19-Dec-2023 11:57:26 UTC] PHP Deprecated:  Creation of dynamic property Automattic\WooCommerce\Admin\Overrides\Order::$payment is deprecated in /Users/faisalalvi/LocalSites/wpne/app/public/wp-content/plugins/woocommerce-square/includes/Framework/PaymentGateway/Payment_Gateway.php on line 1638
[19-Dec-2023 11:57:26 UTC] PHP Deprecated:  Creation of dynamic property Automattic\WooCommerce\Admin\Overrides\Order::$description is deprecated in /Users/faisalalvi/LocalSites/wpne/app/public/wp-content/plugins/woocommerce-square/includes/Framework/PaymentGateway/Payment_Gateway.php on line 1644
[19-Dec-2023 11:57:26 UTC] PHP Deprecated:  Creation of dynamic property Automattic\WooCommerce\Admin\Overrides\Order::$unique_transaction_ref is deprecated in /Users/faisalalvi/LocalSites/wpne/app/public/wp-content/plugins/woocommerce-square/includes/Gateway.php on line 1349
[19-Dec-2023 11:57:26 UTC] PHP Deprecated:  Creation of dynamic property Automattic\WooCommerce\Admin\Overrides\Order::$square_customer_id is deprecated in /Users/faisalalvi/LocalSites/wpne/app/public/wp-content/plugins/woocommerce-square/includes/Gateway.php on line 355
[19-Dec-2023 11:57:26 UTC] PHP Deprecated:  Creation of dynamic property Automattic\WooCommerce\Admin\Overrides\Order::$square_order_id is deprecated in /Users/faisalalvi/LocalSites/wpne/app/public/wp-content/plugins/woocommerce-square/includes/Gateway.php on line 356
[19-Dec-2023 11:57:26 UTC] PHP Deprecated:  Creation of dynamic property Automattic\WooCommerce\Admin\Overrides\Order::$square_version is deprecated in /Users/faisalalvi/LocalSites/wpne/app/public/wp-content/plugins/woocommerce-square/includes/Gateway.php on line 357
@dkotter dkotter self-requested a review January 8, 2024 17:45
includes/WC_Order_Square.php Outdated Show resolved Hide resolved
@jeffpaul jeffpaul added this to the Future Release milestone Jan 16, 2024
@qasumitbagthariya
Copy link
Contributor

QA Update ⚠️


@Sidsector9 Thanks for the PR.

I have test all cases and found that below PHP Deprecated errors in logs. Can you please check from your end and also check the notice coming from Payment_Gateway.php / Gateway.php

debug.log

Testing Environment

  • WordPress: 6.4.2
  • Woo Subscriptions 5.9.1
  • WooPayments 7.0.0
  • Theme: Storefront 4.5.3
  • WooCommerce - 8.5.1
  • PHP: 8.0.21
  • Web Server: Nginx 1.20.2
  • Browser: Chrome
  • OS: macOS Ventura 13.3

@Sidsector9
Copy link
Member Author

Sidsector9 commented Jan 22, 2024

Note

Please request the Woo team for review to verify on the approach before releasing.

cc: @vikrampm1 @dkotter

@qasumitbagthariya
Copy link
Contributor

QA Update ⚠️

@Sidsector9 Thanks for the PR.

I have test all cases and found that below PHP Deprecated errors in logs. Can you please check from your end and also check the notice coming from Payment_Gateway.php / Gateway.php

debug.log

Testing Environment

@Sidsector9 I tried again several times but now the notices (Payment_Gateway.php / Gateway.php) are not coming.

* @return string
*/
public function load_custom_order_class( $classname ) {
if ( '\Automattic\WooCommerce\Admin\Overrides\Order' === $classname ) {
Copy link
Member Author

Choose a reason for hiding this comment

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

@woocommerce/quark requesting you to review this approach taken to resolve the dynamic properties notice.

Copy link
Contributor

Choose a reason for hiding this comment

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

hmm it's not ideal. Seems like a bit of an arms race and potentially flaky if other folks need to do something similar.

For example, WC core are already doing this for some purpose I don't fully understand but it seems to add functionality that might break if it's overridden further.

Having said that, I don't know if there's an alternative other than a rethink of how the Square plugin uses these dynamic properties given the current environment. From the discussion on this issue (woocommerce/woocommerce#31316) and this PR (woocommerce/woocommerce#35763), they don't seem open to broadly rolling out the AllowDynamicProperties flag across the core WC classes.

Copy link
Contributor

Choose a reason for hiding this comment

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

@diegocurbelo what's your thoughts on this then, acceptable as-is or someone else to consult on most optimal approach here?

Copy link
Contributor

Choose a reason for hiding this comment

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

Note that this just resolves some deprecated notices in PHP 8.2+ so if we're unsure on this approach, we could remove this for now and come back later.

Eventually those deprecated notices will be warnings or errors I imagine so something that needs fixed but isn't the most crucial thing at the moment.

Choose a reason for hiding this comment

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

Hmm, interesting discussion on those WooCommerce issues and I agree with @james-allan that this change isn't ideal... I ultimately don't see an alternative to this problem though and the workarounds others shared on those issues don't seem ideal either 🤔

The only suggestion I was going to make was rather than filtering every single woocommerce_order_class hook, could we get away with limiting this to just our get_order(), get_order_for_capture() and get_order_for_refund() functions to use WC_Order_Square when we need it?

i.e.

if ( is_numeric( $order ) ) {
	/** @var WC_Order_Square $order */
	add_filter( 'woocommerce_order_class', array( $this, 'load_custom_order_class' ), 999 );
	$order = wc_get_order( $order );
	remove_filter( 'woocommerce_order_class', array( $this, 'load_custom_order_class' ), 999 );
}

Or would this potentially introduce other problems?

Copy link
Member Author

Choose a reason for hiding this comment

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

Or would this potentially introduce other problems?

I don't have an answer for this 😓. We can give this a try but it will be tough to imagine for what particular configuration(s) this can fail.

@jeffpaul there is still an option to refactor the plugin which will be some decent amount of work, both development and testing wise. Would you suggest we take this approach?

Copy link
Contributor

Choose a reason for hiding this comment

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

@jeffpaul @dkotter any suggestions on the approach noted by Sid above?

@Sidsector9 Sidsector9 requested review from a team and james-allan and removed request for a team January 29, 2024 20:53
@vikrampm1
Copy link
Contributor

@james-allan noting that this PR is awaiting your review.

@Sidsector9
Copy link
Member Author

Closing in favour of PR #71

@Sidsector9 Sidsector9 closed this Feb 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ensure PHP 8.3 Compatibility
8 participants