From 11dee862cd5aad24991d04d7697d350c134217aa Mon Sep 17 00:00:00 2001 From: Sayan Pandey Date: Fri, 13 Jun 2025 15:45:15 +0100 Subject: [PATCH 1/6] Revert "Removing `Enable sync` checkbox, Global sync logic and tagging newly synced products (#3241)" This reverts commit dbaa0504dada129770554ece7e6dd28a16cc7bcc. --- facebook-commerce.php | 21 ++++++++ .../Admin/Settings_Screens/Product_Sync.php | 9 ++++ includes/Lifecycle.php | 7 +++ includes/ProductSync/ProductValidator.php | 14 +++++ includes/Products/Feed.php | 6 ++- includes/Utilities/Tracker.php | 7 +-- .../WCFacebookCommerceIntegrationTest.php | 53 +++++++++++++++++++ 7 files changed, 113 insertions(+), 4 deletions(-) diff --git a/facebook-commerce.php b/facebook-commerce.php index b83c9d278..b8dc5d925 100644 --- a/facebook-commerce.php +++ b/facebook-commerce.php @@ -75,6 +75,9 @@ class WC_Facebookcommerce_Integration extends WC_Integration { /** @var string the "access token" setting ID */ const SETTING_ACCESS_TOKEN = 'access_token'; + /** @var string the "enable product sync" setting ID */ + const SETTING_ENABLE_PRODUCT_SYNC = 'wc_facebook_enable_product_sync'; + /** @var string the excluded product category IDs setting ID */ const SETTING_EXCLUDED_PRODUCT_CATEGORY_IDS = 'wc_facebook_excluded_product_category_ids'; @@ -2503,6 +2506,24 @@ public function is_advanced_matching_enabled() { return (bool) apply_filters( 'wc_facebook_is_advanced_matching_enabled', true, $this ); } + /** + * Determines whether product sync is enabled. + * + * @return bool + * @since 1.10.0 + */ + public function is_product_sync_enabled() { + /** + * Filters whether product sync is enabled. + * + * @param bool $is_enabled whether product sync is enabled + * @param \WC_Facebookcommerce_Integration $integration the integration instance + * + * @since 1.10.0 + */ + return (bool) apply_filters( 'wc_facebook_is_product_sync_enabled', 'yes' === get_option( self::SETTING_ENABLE_PRODUCT_SYNC, 'yes' ), $this ); + } + /** * Return true if (legacy) feed generation is enabled. * diff --git a/includes/Admin/Settings_Screens/Product_Sync.php b/includes/Admin/Settings_Screens/Product_Sync.php index e4f68b040..2d62cab7a 100644 --- a/includes/Admin/Settings_Screens/Product_Sync.php +++ b/includes/Admin/Settings_Screens/Product_Sync.php @@ -269,6 +269,15 @@ public function get_settings(): array { 'type' => 'product_sync_title', 'title' => __( 'Product sync', 'facebook-for-woocommerce' ), ), + array( + 'id' => \WC_Facebookcommerce_Integration::SETTING_ENABLE_PRODUCT_SYNC, + 'title' => __( 'Enable product sync', 'facebook-for-woocommerce' ), + 'type' => 'checkbox', + 'label' => ' ', + 'default' => 'yes', + 'desc_tip' => __( 'Enable product syncing with Facebook.', 'facebook-for-woocommerce' ), + ), + array( 'id' => \WC_Facebookcommerce_Integration::SETTING_EXCLUDED_PRODUCT_CATEGORY_IDS, 'title' => __( 'Exclude categories from sync', 'facebook-for-woocommerce' ), diff --git a/includes/Lifecycle.php b/includes/Lifecycle.php index 895ce977b..e3e23d1a7 100644 --- a/includes/Lifecycle.php +++ b/includes/Lifecycle.php @@ -144,6 +144,12 @@ private function migrate_1_9_settings() { } } + // migrate settings from standalone options + if ( ! isset( $new_settings[ \WC_Facebookcommerce_Integration::SETTING_ENABLE_PRODUCT_SYNC ] ) ) { + $product_sync_enabled = empty( get_option( 'fb_disable_sync_on_dev_environment', 0 ) ); + $new_settings[ \WC_Facebookcommerce_Integration::SETTING_ENABLE_PRODUCT_SYNC ] = $product_sync_enabled ? 'yes' : 'no'; + } + if ( ! isset( $new_settings[ \WC_Facebookcommerce_Integration::SETTING_SCHEDULED_RESYNC_OFFSET ] ) ) { $autosync_time = get_option( 'woocommerce_fb_autosync_time' ); $parsed_time = ! empty( $autosync_time ) ? strtotime( $autosync_time ) : false; @@ -208,6 +214,7 @@ protected function upgrade_to_2_0_0() { $settings_map = array( 'facebook_pixel_id' => \WC_Facebookcommerce_Integration::SETTING_FACEBOOK_PIXEL_ID, 'facebook_page_id' => \WC_Facebookcommerce_Integration::SETTING_FACEBOOK_PAGE_ID, + 'enable_product_sync' => \WC_Facebookcommerce_Integration::SETTING_ENABLE_PRODUCT_SYNC, 'excluded_product_category_ids' => \WC_Facebookcommerce_Integration::SETTING_EXCLUDED_PRODUCT_CATEGORY_IDS, 'excluded_product_tag_ids' => \WC_Facebookcommerce_Integration::SETTING_EXCLUDED_PRODUCT_TAG_IDS, 'enable_messenger' => self::SETTING_ENABLE_MESSENGER, diff --git a/includes/ProductSync/ProductValidator.php b/includes/ProductSync/ProductValidator.php index 413dba5c1..e44596ef8 100644 --- a/includes/ProductSync/ProductValidator.php +++ b/includes/ProductSync/ProductValidator.php @@ -109,6 +109,7 @@ public function __get( $key ) { * @throws ProductExcludedException If product should not be synced. */ public function validate() { + $this->validate_sync_enabled_globally(); $this->validate_product_sync_field(); $this->validate_product_status(); $this->validate_product_visibility(); @@ -122,6 +123,7 @@ public function validate() { * @throws ProductExcludedException If product should not be synced. */ public function validate_but_skip_status_check() { + $this->validate_sync_enabled_globally(); $this->validate_product_sync_field(); $this->validate_product_visibility(); } @@ -133,6 +135,7 @@ public function validate_but_skip_status_check() { * @throws ProductExcludedException|ProductInvalidException If product should not be synced. */ public function validate_but_skip_sync_field() { + $this->validate_sync_enabled_globally(); $this->validate_product_visibility(); } @@ -187,6 +190,17 @@ public function passes_all_checks_except_sync_field(): bool { return true; } + /** + * Check whether product sync is globally disabled. + * + * @throws ProductExcludedException If product should not be synced. + */ + protected function validate_sync_enabled_globally() { + if ( ! $this->integration->is_product_sync_enabled() ) { + throw new ProductExcludedException( __( 'Product sync is globally disabled.', 'facebook-for-woocommerce' ) ); + } + } + /** * Check whether the product's status excludes it from sync. * diff --git a/includes/Products/Feed.php b/includes/Products/Feed.php index dc2d33407..afd3433f0 100644 --- a/includes/Products/Feed.php +++ b/includes/Products/Feed.php @@ -193,9 +193,11 @@ public function schedule_feed_generation() { set_transient( $flag_name, 'yes', HOUR_IN_SECONDS ); $integration = facebook_for_woocommerce()->get_integration(); $configured_ok = $integration && $integration->is_configured(); + // Only schedule feed job if store has not opted out of product sync. + $store_allows_sync = $configured_ok && $integration->is_product_sync_enabled(); // Only schedule if has not opted out of feed generation (e.g. large stores). $store_allows_feed = $configured_ok && $integration->is_legacy_feed_file_generation_enabled(); - if ( ! $store_allows_feed || ! $configured_ok ) { + if ( ! $store_allows_sync || ! $store_allows_feed ) { as_unschedule_all_actions( self::GENERATE_FEED_ACTION ); $message = ''; @@ -203,6 +205,8 @@ public function schedule_feed_generation() { $message = 'Integration not configured.'; } elseif ( ! $store_allows_feed ) { $message = 'Store does not allow feed.'; + } elseif ( ! $store_allows_sync ) { + $message = 'Store does not allow sync.'; } Logger::log( sprintf( 'Product feed scheduling failed: %s', $message ), diff --git a/includes/Utilities/Tracker.php b/includes/Utilities/Tracker.php index bb9c10657..95ee506cf 100644 --- a/includes/Utilities/Tracker.php +++ b/includes/Utilities/Tracker.php @@ -114,11 +114,12 @@ public function add_tracker_data( array $data = [] ) { $data['extensions']['facebook-for-woocommerce']['is-connected'] = wc_bool_to_string( $connection_is_happy ); /** - * Synchronization will always be permitted once we initiate the process of syncing all WooCommerce products. + * What features are enabled on this site? * - * @since 3.5.3 + * @since 2.3.4 */ - $data['extensions']['facebook-for-woocommerce']['product-sync-enabled'] = true; + $product_sync_enabled = facebook_for_woocommerce()->get_integration()->is_product_sync_enabled(); + $data['extensions']['facebook-for-woocommerce']['product-sync-enabled'] = wc_bool_to_string( $product_sync_enabled ); /** * How long did the last feed generation take (or did it fail - 0)? This counts just the time when the batches have been generated. diff --git a/tests/Unit/WCFacebookCommerceIntegrationTest.php b/tests/Unit/WCFacebookCommerceIntegrationTest.php index 83f4bd4e2..11dcf3fcb 100644 --- a/tests/Unit/WCFacebookCommerceIntegrationTest.php +++ b/tests/Unit/WCFacebookCommerceIntegrationTest.php @@ -2404,6 +2404,59 @@ function ( $is_enabled ) { $this->assertFalse( $output ); } + /** + * Tests is product sync enabled returns default value. + * + * @return void + */ + public function test_is_product_sync_enabled_no_filter_no_option() { + $this->teardown_callback_category_safely( 'wc_facebook_is_product_sync_enabled' ); + delete_option( WC_Facebookcommerce_Integration::SETTING_ENABLE_PRODUCT_SYNC ); + + $result = $this->integration->is_product_sync_enabled(); + + $this->assertTrue( $result ); + } + + /** + * Tests is product sync enabled returns option value. + * + * @return void + */ + public function test_is_product_sync_enabled_no_filter() { + $this->teardown_callback_category_safely( 'wc_facebook_is_product_sync_enabled' ); + add_option( + WC_Facebookcommerce_Integration::SETTING_ENABLE_PRODUCT_SYNC, + 'no' + ); + + $result = $this->integration->is_product_sync_enabled(); + + $this->assertFalse( $result ); + } + + /** + * Tests is product sync enabled with filter. + * + * @return void + */ + public function test_is_product_sync_enabled_with_filter() { + $this->add_filter_with_safe_teardown( + 'wc_facebook_is_product_sync_enabled', + function ( $is_enabled ) { + return false; + } + ); + add_option( + WC_Facebookcommerce_Integration::SETTING_ENABLE_PRODUCT_SYNC, + 'yes' + ); + + $result = $this->integration->is_product_sync_enabled(); + + $this->assertFalse( $result ); + } + /** * Tests is legacy feed file generation enabled with no option set. * From 0ea465fe62ea652070d0d90ae5d4a74e5515cd04 Mon Sep 17 00:00:00 2001 From: Sayan Pandey Date: Fri, 13 Jun 2025 16:04:52 +0100 Subject: [PATCH 2/6] Reverting not required tests --- .../WCFacebookCommerceIntegrationTest.php | 53 ------------------- 1 file changed, 53 deletions(-) diff --git a/tests/Unit/WCFacebookCommerceIntegrationTest.php b/tests/Unit/WCFacebookCommerceIntegrationTest.php index 11dcf3fcb..83f4bd4e2 100644 --- a/tests/Unit/WCFacebookCommerceIntegrationTest.php +++ b/tests/Unit/WCFacebookCommerceIntegrationTest.php @@ -2404,59 +2404,6 @@ function ( $is_enabled ) { $this->assertFalse( $output ); } - /** - * Tests is product sync enabled returns default value. - * - * @return void - */ - public function test_is_product_sync_enabled_no_filter_no_option() { - $this->teardown_callback_category_safely( 'wc_facebook_is_product_sync_enabled' ); - delete_option( WC_Facebookcommerce_Integration::SETTING_ENABLE_PRODUCT_SYNC ); - - $result = $this->integration->is_product_sync_enabled(); - - $this->assertTrue( $result ); - } - - /** - * Tests is product sync enabled returns option value. - * - * @return void - */ - public function test_is_product_sync_enabled_no_filter() { - $this->teardown_callback_category_safely( 'wc_facebook_is_product_sync_enabled' ); - add_option( - WC_Facebookcommerce_Integration::SETTING_ENABLE_PRODUCT_SYNC, - 'no' - ); - - $result = $this->integration->is_product_sync_enabled(); - - $this->assertFalse( $result ); - } - - /** - * Tests is product sync enabled with filter. - * - * @return void - */ - public function test_is_product_sync_enabled_with_filter() { - $this->add_filter_with_safe_teardown( - 'wc_facebook_is_product_sync_enabled', - function ( $is_enabled ) { - return false; - } - ); - add_option( - WC_Facebookcommerce_Integration::SETTING_ENABLE_PRODUCT_SYNC, - 'yes' - ); - - $result = $this->integration->is_product_sync_enabled(); - - $this->assertFalse( $result ); - } - /** * Tests is legacy feed file generation enabled with no option set. * From 416ee06a02dfc5cfbee769209dfa8422e4d4128d Mon Sep 17 00:00:00 2001 From: Sayan Pandey Date: Fri, 13 Jun 2025 17:15:22 +0100 Subject: [PATCH 3/6] Adding rollout switches all across --- facebook-commerce.php | 24 +++++++++++++++++++++++ includes/Lifecycle.php | 9 +++++++++ includes/ProductSync/ProductValidator.php | 4 ++++ includes/Products/Feed.php | 2 +- includes/RolloutSwitches.php | 18 +++++++++-------- includes/Utilities/Tracker.php | 17 ++++++++++++---- 6 files changed, 61 insertions(+), 13 deletions(-) diff --git a/facebook-commerce.php b/facebook-commerce.php index b8dc5d925..216adce5d 100644 --- a/facebook-commerce.php +++ b/facebook-commerce.php @@ -16,6 +16,7 @@ use WooCommerce\Facebook\Products; use WooCommerce\Facebook\Products\Feed; use WooCommerce\Facebook\Framework\Logger; +use WooCommerce\Facebook\RolloutSwitches; defined( 'ABSPATH' ) || exit; @@ -2488,6 +2489,20 @@ public function is_configured() { return $this->get_facebook_page_id() && $this->facebook_for_woocommerce->get_connection_handler()->is_connected(); } + /** + * Determines if viewing the plugin settings in the admin. + * + * @since 3.5.3 + * + * @return bool + */ + + public function is_woo_all_products_enabled() { + return $this->facebook_for_woocommerce->get_rollout_switches()->is_switch_enabled( + RolloutSwitches::SWITCH_WOO_ALL_PRODUCTS_SYNC_ENABLED + ); + } + /** * Determines whether advanced matching is enabled. * @@ -2513,6 +2528,15 @@ public function is_advanced_matching_enabled() { * @since 1.10.0 */ public function is_product_sync_enabled() { + /** + * If all products switch is enabled + * There is no check for global sync + */ + + if($this->plugin->is_woo_all_products_enabled()){ + return true; + } + /** * Filters whether product sync is enabled. * diff --git a/includes/Lifecycle.php b/includes/Lifecycle.php index e3e23d1a7..31e2ebd51 100644 --- a/includes/Lifecycle.php +++ b/includes/Lifecycle.php @@ -150,6 +150,15 @@ private function migrate_1_9_settings() { $new_settings[ \WC_Facebookcommerce_Integration::SETTING_ENABLE_PRODUCT_SYNC ] = $product_sync_enabled ? 'yes' : 'no'; } + + $is_woo_all_products_sync_enbaled = facebook_for_woocommerce()->get_integration()->is_woo_all_products_enabled(); + + // migrate settings from standalone options + if (!$is_woo_all_products_sync_enbaled && ! isset( $new_settings[ \WC_Facebookcommerce_Integration::SETTING_ENABLE_PRODUCT_SYNC ] ) ) { + $product_sync_enabled = empty( get_option( 'fb_disable_sync_on_dev_environment', 0 ) ); + $new_settings[ \WC_Facebookcommerce_Integration::SETTING_ENABLE_PRODUCT_SYNC ] = $product_sync_enabled ? 'yes' : 'no'; + } + if ( ! isset( $new_settings[ \WC_Facebookcommerce_Integration::SETTING_SCHEDULED_RESYNC_OFFSET ] ) ) { $autosync_time = get_option( 'woocommerce_fb_autosync_time' ); $parsed_time = ! empty( $autosync_time ) ? strtotime( $autosync_time ) : false; diff --git a/includes/ProductSync/ProductValidator.php b/includes/ProductSync/ProductValidator.php index e44596ef8..b327d5fef 100644 --- a/includes/ProductSync/ProductValidator.php +++ b/includes/ProductSync/ProductValidator.php @@ -196,6 +196,10 @@ public function passes_all_checks_except_sync_field(): bool { * @throws ProductExcludedException If product should not be synced. */ protected function validate_sync_enabled_globally() { + if($this->integration->is_woo_all_products_enabled()){ + return true; + } + if ( ! $this->integration->is_product_sync_enabled() ) { throw new ProductExcludedException( __( 'Product sync is globally disabled.', 'facebook-for-woocommerce' ) ); } diff --git a/includes/Products/Feed.php b/includes/Products/Feed.php index afd3433f0..0018d5305 100644 --- a/includes/Products/Feed.php +++ b/includes/Products/Feed.php @@ -194,7 +194,7 @@ public function schedule_feed_generation() { $integration = facebook_for_woocommerce()->get_integration(); $configured_ok = $integration && $integration->is_configured(); // Only schedule feed job if store has not opted out of product sync. - $store_allows_sync = $configured_ok && $integration->is_product_sync_enabled(); + $store_allows_sync = $configured_ok && $integration->is_product_sync_enabled() || $integration->is_woo_all_products_enabled(); // Only schedule if has not opted out of feed generation (e.g. large stores). $store_allows_feed = $configured_ok && $integration->is_legacy_feed_file_generation_enabled(); if ( ! $store_allows_sync || ! $store_allows_feed ) { diff --git a/includes/RolloutSwitches.php b/includes/RolloutSwitches.php index 5d7caa396..c3456bffa 100644 --- a/includes/RolloutSwitches.php +++ b/includes/RolloutSwitches.php @@ -24,15 +24,17 @@ class RolloutSwitches { /** @var \WC_Facebookcommerce commerce handler */ private \WC_Facebookcommerce $plugin; - public const SWITCH_ROLLOUT_FEATURES = 'rollout_enabled'; - public const WHATSAPP_UTILITY_MESSAGING = 'whatsapp_utility_messages_enabled'; - public const SWITCH_PRODUCT_SETS_SYNC_ENABLED = 'product_sets_sync_enabled'; - private const SETTINGS_KEY = 'wc_facebook_for_woocommerce_rollout_switches'; + public const SWITCH_ROLLOUT_FEATURES = 'rollout_enabled'; + public const WHATSAPP_UTILITY_MESSAGING = 'whatsapp_utility_messages_enabled'; + public const SWITCH_PRODUCT_SETS_SYNC_ENABLED = 'product_sets_sync_enabled'; + public const SWITCH_WOO_ALL_PRODUCTS_SYNC_ENABLED = 'woo_all_products_sync_enabled'; + private const SETTINGS_KEY = 'wc_facebook_for_woocommerce_rollout_switches'; private const ACTIVE_SWITCHES = array( self::SWITCH_ROLLOUT_FEATURES, self::WHATSAPP_UTILITY_MESSAGING, self::SWITCH_PRODUCT_SETS_SYNC_ENABLED, + self::SWITCH_WOO_ALL_PRODUCTS_SYNC_ENABLED, ); public function __construct( \WC_Facebookcommerce $plugin ) { @@ -82,13 +84,13 @@ public function init() { Logger::log( $e->getMessage(), array( - 'flow_name' => 'rollout_switches', - 'flow_step' => 'init', + 'flow_name' => 'rollout_switches', + 'flow_step' => 'init', ), array( - 'should_send_log_to_meta' => true, + 'should_send_log_to_meta' => true, 'should_save_log_in_woocommerce' => true, - 'woocommerce_log_level' => \WC_Log_Levels::ERROR, + 'woocommerce_log_level' => \WC_Log_Levels::ERROR, ) ); } diff --git a/includes/Utilities/Tracker.php b/includes/Utilities/Tracker.php index 95ee506cf..41f7898ce 100644 --- a/includes/Utilities/Tracker.php +++ b/includes/Utilities/Tracker.php @@ -114,12 +114,21 @@ public function add_tracker_data( array $data = [] ) { $data['extensions']['facebook-for-woocommerce']['is-connected'] = wc_bool_to_string( $connection_is_happy ); /** - * What features are enabled on this site? + * Synchronization will always be permitted once we initiate the process of syncing all WooCommerce products. * - * @since 2.3.4 + * @since 3.5.3 */ - $product_sync_enabled = facebook_for_woocommerce()->get_integration()->is_product_sync_enabled(); - $data['extensions']['facebook-for-woocommerce']['product-sync-enabled'] = wc_bool_to_string( $product_sync_enabled ); + + $is_woo_all_products_enabled = facebook_for_woocommerce()->get_integration()->is_woo_all_products_enabled(); + if(!$is_woo_all_products_enabled){ + $product_sync_enabled = facebook_for_woocommerce()->get_integration()->is_product_sync_enabled(); + $data['extensions']['facebook-for-woocommerce']['product-sync-enabled'] = wc_bool_to_string( $product_sync_enabled ); + } + else { + $data['extensions']['facebook-for-woocommerce']['product-sync-enabled'] = wc_bool_to_string( true ); + } + + /** * How long did the last feed generation take (or did it fail - 0)? This counts just the time when the batches have been generated. From c4d227e39cc419c8b3638ff37187f27cca2e901a Mon Sep 17 00:00:00 2001 From: Sayan Pandey Date: Fri, 13 Jun 2025 17:23:49 +0100 Subject: [PATCH 4/6] Removing redundant check --- includes/Lifecycle.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/includes/Lifecycle.php b/includes/Lifecycle.php index 31e2ebd51..7b0879386 100644 --- a/includes/Lifecycle.php +++ b/includes/Lifecycle.php @@ -144,13 +144,6 @@ private function migrate_1_9_settings() { } } - // migrate settings from standalone options - if ( ! isset( $new_settings[ \WC_Facebookcommerce_Integration::SETTING_ENABLE_PRODUCT_SYNC ] ) ) { - $product_sync_enabled = empty( get_option( 'fb_disable_sync_on_dev_environment', 0 ) ); - $new_settings[ \WC_Facebookcommerce_Integration::SETTING_ENABLE_PRODUCT_SYNC ] = $product_sync_enabled ? 'yes' : 'no'; - } - - $is_woo_all_products_sync_enbaled = facebook_for_woocommerce()->get_integration()->is_woo_all_products_enabled(); // migrate settings from standalone options From cc8f12e4db68c816ac0f252563989dbd5f0d650a Mon Sep 17 00:00:00 2001 From: Sayan Pandey Date: Fri, 13 Jun 2025 17:54:16 +0100 Subject: [PATCH 5/6] Adding test fixes --- facebook-commerce.php | 2 +- tests/Unit/WCFacebookCommerceIntegrationTest.php | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/facebook-commerce.php b/facebook-commerce.php index 216adce5d..7213ff0c0 100644 --- a/facebook-commerce.php +++ b/facebook-commerce.php @@ -2533,7 +2533,7 @@ public function is_product_sync_enabled() { * There is no check for global sync */ - if($this->plugin->is_woo_all_products_enabled()){ + if($this->is_woo_all_products_enabled()){ return true; } diff --git a/tests/Unit/WCFacebookCommerceIntegrationTest.php b/tests/Unit/WCFacebookCommerceIntegrationTest.php index 83f4bd4e2..adca55878 100644 --- a/tests/Unit/WCFacebookCommerceIntegrationTest.php +++ b/tests/Unit/WCFacebookCommerceIntegrationTest.php @@ -560,6 +560,8 @@ public function test_on_product_save_existing_simple_product_sync_disabled_updat // The mock below is hit otherwise it would generate a random Mock_Response and throw error $integration_mock = $this->createMock(WC_Facebookcommerce_Integration::class); $integration_mock->method('delete_product_item'); + $integration_mock->method('is_woo_all_products_enabled') + ->willReturn(false); $this->integration = $integration_mock; $_POST['wc_facebook_sync_mode'] = Admin::SYNC_MODE_SYNC_DISABLED; From 382a170b65efd9ad9ffb753ea62c339aa3c33803 Mon Sep 17 00:00:00 2001 From: Sayan Pandey Date: Fri, 13 Jun 2025 17:59:04 +0100 Subject: [PATCH 6/6] Adding phpcs fixes --- facebook-commerce.php | 7 +++---- includes/Lifecycle.php | 2 +- includes/ProductSync/ProductValidator.php | 2 +- includes/Products/Feed.php | 2 +- includes/Utilities/Tracker.php | 7 ++----- 5 files changed, 8 insertions(+), 12 deletions(-) diff --git a/facebook-commerce.php b/facebook-commerce.php index 7213ff0c0..280b803e8 100644 --- a/facebook-commerce.php +++ b/facebook-commerce.php @@ -2496,12 +2496,11 @@ public function is_configured() { * * @return bool */ - - public function is_woo_all_products_enabled() { + public function is_woo_all_products_enabled() { return $this->facebook_for_woocommerce->get_rollout_switches()->is_switch_enabled( RolloutSwitches::SWITCH_WOO_ALL_PRODUCTS_SYNC_ENABLED ); - } + } /** * Determines whether advanced matching is enabled. @@ -2533,7 +2532,7 @@ public function is_product_sync_enabled() { * There is no check for global sync */ - if($this->is_woo_all_products_enabled()){ + if ( $this->is_woo_all_products_enabled() ) { return true; } diff --git a/includes/Lifecycle.php b/includes/Lifecycle.php index 7b0879386..b2da960e6 100644 --- a/includes/Lifecycle.php +++ b/includes/Lifecycle.php @@ -147,7 +147,7 @@ private function migrate_1_9_settings() { $is_woo_all_products_sync_enbaled = facebook_for_woocommerce()->get_integration()->is_woo_all_products_enabled(); // migrate settings from standalone options - if (!$is_woo_all_products_sync_enbaled && ! isset( $new_settings[ \WC_Facebookcommerce_Integration::SETTING_ENABLE_PRODUCT_SYNC ] ) ) { + if ( ! $is_woo_all_products_sync_enbaled && ! isset( $new_settings[ \WC_Facebookcommerce_Integration::SETTING_ENABLE_PRODUCT_SYNC ] ) ) { $product_sync_enabled = empty( get_option( 'fb_disable_sync_on_dev_environment', 0 ) ); $new_settings[ \WC_Facebookcommerce_Integration::SETTING_ENABLE_PRODUCT_SYNC ] = $product_sync_enabled ? 'yes' : 'no'; } diff --git a/includes/ProductSync/ProductValidator.php b/includes/ProductSync/ProductValidator.php index b327d5fef..afe3e0c0a 100644 --- a/includes/ProductSync/ProductValidator.php +++ b/includes/ProductSync/ProductValidator.php @@ -196,7 +196,7 @@ public function passes_all_checks_except_sync_field(): bool { * @throws ProductExcludedException If product should not be synced. */ protected function validate_sync_enabled_globally() { - if($this->integration->is_woo_all_products_enabled()){ + if ( $this->integration->is_woo_all_products_enabled() ) { return true; } diff --git a/includes/Products/Feed.php b/includes/Products/Feed.php index 0018d5305..f407444e9 100644 --- a/includes/Products/Feed.php +++ b/includes/Products/Feed.php @@ -194,7 +194,7 @@ public function schedule_feed_generation() { $integration = facebook_for_woocommerce()->get_integration(); $configured_ok = $integration && $integration->is_configured(); // Only schedule feed job if store has not opted out of product sync. - $store_allows_sync = $configured_ok && $integration->is_product_sync_enabled() || $integration->is_woo_all_products_enabled(); + $store_allows_sync = ( $configured_ok && $integration->is_product_sync_enabled() ) || $integration->is_woo_all_products_enabled(); // Only schedule if has not opted out of feed generation (e.g. large stores). $store_allows_feed = $configured_ok && $integration->is_legacy_feed_file_generation_enabled(); if ( ! $store_allows_sync || ! $store_allows_feed ) { diff --git a/includes/Utilities/Tracker.php b/includes/Utilities/Tracker.php index 41f7898ce..0384d7d60 100644 --- a/includes/Utilities/Tracker.php +++ b/includes/Utilities/Tracker.php @@ -120,16 +120,13 @@ public function add_tracker_data( array $data = [] ) { */ $is_woo_all_products_enabled = facebook_for_woocommerce()->get_integration()->is_woo_all_products_enabled(); - if(!$is_woo_all_products_enabled){ + if ( ! $is_woo_all_products_enabled ) { $product_sync_enabled = facebook_for_woocommerce()->get_integration()->is_product_sync_enabled(); $data['extensions']['facebook-for-woocommerce']['product-sync-enabled'] = wc_bool_to_string( $product_sync_enabled ); - } - else { + } else { $data['extensions']['facebook-for-woocommerce']['product-sync-enabled'] = wc_bool_to_string( true ); } - - /** * How long did the last feed generation take (or did it fail - 0)? This counts just the time when the batches have been generated. * It does not take into account the time between the batches.