Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
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
4 changes: 4 additions & 0 deletions projects/packages/sync/changelog/fix-phan-issues_in_old_woo
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

Improve compatibility with old WooCommerce versions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

namespace Automattic\Jetpack\Sync\Modules;

use Automattic\WooCommerce\Enums\ProductType;
use DateTimeZone;
use WC_DateTime;
use WP_Error;
Expand Down Expand Up @@ -292,10 +291,12 @@ public function get_product_by_ids( $ids, $order = '' ) {
);

$post_type = $post->post_type;
// ProductType::VARIATION and ProductType::SIMPLE have only existed since WooCommerce 9.7, so
// we can't rely on that existing, but using the strings is probably safe enough.
if ( 'product_variation' === $post_type ) {
$product_type = ProductType::VARIATION;
$product_type = 'variation';
} elseif ( 'product' === $post_type ) {
$product_type = $product_types[ $post->ID ] ?? ProductType::SIMPLE;
$product_type = $product_types[ $post->ID ] ?? 'simple';
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems fine! I guess we haven't run into any issues here yet, because sync runs on newer stores? or maybe sync has a different plugin requirement?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As best I can tell we were lucky and the module itself isn't enabled. It seems to have been added in #44601 and modified in #44601, but both those PRs require a filter to test it, and probably when it was being tested it was done against a newer store.

In other words, this (along with the earlier issues discovered) is precisely what we're hoping to catch with static analysis. 🥳

Copy link
Contributor

Choose a reason for hiding this comment

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

In other words, this (along with the earlier issues discovered) is precisely what we're hoping to catch with static analysis. 🥳

Totally!!

} else {
$product_type = null;
}
Expand Down Expand Up @@ -444,7 +445,8 @@ private function get_product_posts( $ids, $order = '' ) {
* @return array
*/
private function get_product_cogs_data( $ids, $order = '' ) {
$is_cogs_enabled = class_exists( '\Automattic\WooCommerce\Utilities\FeaturesUtil' ) && \Automattic\WooCommerce\Utilities\FeaturesUtil::feature_is_enabled( 'cost_of_goods_sold' );
// @phan-suppress-current-line UnusedPluginSuppression @phan-suppress-next-line PhanUndeclaredClassReference, PhanUndeclaredClassMethod -- we're checking for the class and method before using them. See also: https://github.com/phan/phan/issues/1204
$is_cogs_enabled = class_exists( '\Automattic\WooCommerce\Utilities\FeaturesUtil' ) && method_exists( '\Automattic\WooCommerce\Utilities\FeaturesUtil', 'feature_is_enabled' ) && \Automattic\WooCommerce\Utilities\FeaturesUtil::feature_is_enabled( 'cost_of_goods_sold' );
Copy link
Contributor

Choose a reason for hiding this comment

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

The extra method_exists check seems unnecessary here as the feature_is_enabled was added since the creation of the FeaturesUtil class: https://github.com/woocommerce/woocommerce/pull/34727/files#diff-f5ea913d075d5ad173fcb2099d072ce0bf286922e41a3131442ab99c6ae58263

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed! I must have confused it with something else I checked. Removed: c4f17d1


if ( ! $is_cogs_enabled ) {
return array();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

Improve compatibility with old WooCommerce versions.
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ public static function send_batched_pixels() {
foreach ( self::$pixel_batch_queue as $pixel ) {
// Check if the method exists for backwards compatibility with older WooCommerce versions.
if ( method_exists( WC_Tracks_Client::class, 'add_request_timestamp_and_nocache' ) ) {
// @phan-suppress-current-line UnusedPluginSuppression @phan-suppress-next-line PhanUndeclaredStaticMethod -- We verify the method exists before using it. See also: https://github.com/phan/phan/issues/1204
$pixels_to_send[] = WC_Tracks_Client::add_request_timestamp_and_nocache( $pixel );
} else {
// Fallback for older versions - add timestamp and nocache parameters manually.
Expand Down Expand Up @@ -387,7 +388,7 @@ public static function get_server_details() {
$data = parent::get_server_details();
} elseif ( method_exists( WC_Site_Tracking::class, 'get_server_details' ) ) {
// WC < 6.8
$data = WC_Site_Tracking::get_server_details(); // @phan-suppress-current-line PhanUndeclaredStaticMethod -- method is available in WC < 6.8
$data = WC_Site_Tracking::get_server_details(); // @phan-suppress-current-line PhanUndeclaredStaticMethod -- method is available in WC < 6.8. See also: https://github.com/phan/phan/issues/1204
}

return array_merge(
Expand All @@ -413,7 +414,7 @@ public static function get_blog_details( $blog_id ) {
return parent::get_blog_details( $blog_id );
} elseif ( method_exists( WC_Site_Tracking::class, 'get_blog_details' ) ) {
// WC < 6.8
return WC_Site_Tracking::get_blog_details( $blog_id ); // @phan-suppress-current-line PhanUndeclaredStaticMethod -- method is available in WC < 6.8
return WC_Site_Tracking::get_blog_details( $blog_id ); // @phan-suppress-current-line PhanUndeclaredStaticMethod -- method is available in WC < 6.8. See also: https://github.com/phan/phan/issues/1204
}
return array();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ public function find_cart_checkout_content_sources() {

$this->cart_checkout_templates_in_use = wp_is_block_theme()
&& class_exists( '\Automattic\WooCommerce\Blocks\Package' )
// @phan-suppress-current-line UnusedPluginSuppression @phan-suppress-next-line PhanUndeclaredClassMethod -- If the class exists (as of WooCommerce 8.5.0), the method exists. See also: https://github.com/phan/phan/issues/1204
&& version_compare( \Automattic\WooCommerce\Blocks\Package::get_version(), '10.6.0', '>=' );

// Cart/Checkout *pages* are in use if the templates are not in use. Return their content and do nothing else.
Expand Down Expand Up @@ -260,6 +261,7 @@ public function find_cart_checkout_content_sources() {
public function get_common_properties() {
$site_info = array(
'blog_id' => Jetpack_Connection::get_site_id(),
// @phan-suppress-current-line UnusedPluginSuppression @phan-suppress-next-line PhanUndeclaredConstantOfClass -- The constant has only existed since WooCommerce 8.4, but we check for its existence. See also: https://github.com/phan/phan/issues/1204
'store_id' => defined( '\\WC_Install::STORE_ID_OPTION' ) ? get_option( \WC_Install::STORE_ID_OPTION ) : false,
'ui' => $this->get_user_id(),
'url' => home_url(),
Expand Down
5 changes: 5 additions & 0 deletions projects/plugins/wpcomsh/changelog/fix-phan-issues_in_old_woo
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: fixed
Comment: Suppress Phan confusion.


1 change: 1 addition & 0 deletions projects/plugins/wpcomsh/woa.php
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ function wpcomsh_woa_post_process_store_woocommerce_connection_details( $args, $
WP_CLI::success( 'WooCommerce connection details stored' );

if ( class_exists( 'WC_Helper' ) && method_exists( 'WC_Helper', 'refresh_helper_subscriptions' ) ) {
// @phan-suppress-current-line UnusedPluginSuppression @phan-suppress-next-line PhanUndeclaredStaticMethod -- We check if the class and method exist before using them; see https://github.com/phan/phan/issues/1204
WC_Helper::refresh_helper_subscriptions();

WP_CLI::success( 'Cleared WooCommerce Helper cache' );
Expand Down
Loading