Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
26 changes: 0 additions & 26 deletions facebook-commerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,6 @@ 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';

Expand Down Expand Up @@ -2158,11 +2155,6 @@ private function sync_facebook_products() {
* @throws PluginException If the plugin is not configured or the Catalog ID is missing.
*/
private function sync_facebook_products_using_background_processor() {
if ( ! $this->is_product_sync_enabled() ) {
WC_Facebookcommerce_Utils::log_with_debug_mode_enabled( 'Sync to Facebook is disabled' );
throw new PluginException( __( 'Product sync is disabled.', 'facebook-for-woocommerce' ) );
}

if ( ! $this->is_configured() || ! $this->get_product_catalog_id() ) {
WC_Facebookcommerce_Utils::log_with_debug_mode_enabled( sprintf( 'Not syncing, the plugin is not configured or the Catalog ID is missing' ) );
throw new PluginException( __( 'The plugin is not configured or the Catalog ID is missing.', 'facebook-for-woocommerce' ) );
Expand Down Expand Up @@ -2623,24 +2615,6 @@ 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.
*
Expand Down
9 changes: 0 additions & 9 deletions includes/Admin/Settings_Screens/Product_Sync.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,15 +269,6 @@ 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' ),
Expand Down
7 changes: 0 additions & 7 deletions includes/Lifecycle.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +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';
}

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;
Expand Down Expand Up @@ -214,7 +208,6 @@ 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,
Expand Down
14 changes: 0 additions & 14 deletions includes/ProductSync/ProductValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ 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();
Expand All @@ -132,7 +131,6 @@ 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();
$this->validate_product_terms();
Expand All @@ -145,7 +143,6 @@ 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();
$this->validate_product_terms();
}
Expand Down Expand Up @@ -218,17 +215,6 @@ 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.
*
Expand Down
6 changes: 1 addition & 5 deletions includes/Products/Feed.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,20 +168,16 @@ 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_sync || ! $store_allows_feed ) {
if ( ! $store_allows_feed || ! $configured_ok ) {
as_unschedule_all_actions( self::GENERATE_FEED_ACTION );

$message = '';
if ( ! $configured_ok ) {
$message = 'Integration not configured.';
} elseif ( ! $store_allows_feed ) {
$message = 'Store does not allow feed.';
} elseif ( ! $store_allows_sync ) {
$message = 'Store does not allow sync.';
}
WC_Facebookcommerce_Utils::log_to_meta(
sprintf( 'Product feed scheduling failed: %s', $message ),
Expand Down
7 changes: 3 additions & 4 deletions includes/Utilities/Tracker.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,11 @@ 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 );
$data['extensions']['facebook-for-woocommerce']['product-sync-enabled'] = 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.
Expand Down
15 changes: 15 additions & 0 deletions includes/fbproduct.php
Original file line number Diff line number Diff line change
Expand Up @@ -1780,6 +1780,21 @@ public function prepare_product( $retailer_id = null, $type_to_prepare_for = sel
}
}

/**
* Visibility has been set for the products, both for simple and variations
* Now if prevously they had product sync checkbox/ global products sync off, we will mark the products
*/

$deprecated_global_sync_checkbox_status = 'yes' === get_option('wc_facebook_enable_product_sync', 'yes' );
if($deprecated_global_sync_checkbox_status === false){
/**
* Previously they wouldn't have syned
* But now they are
*/
$product_data["is_woo_all_products_sync"] = 1;
}


if ( self::PRODUCT_PREP_TYPE_ITEMS_BATCH === $type_to_prepare_for ) {
$product_data['title'] = Helper::str_truncate( WC_Facebookcommerce_Utils::clean_string( $this->get_title() ), self::MAX_TITLE_LENGTH );
$product_data['image_link'] = $image_urls[0];
Expand Down
53 changes: 0 additions & 53 deletions tests/Unit/WCFacebookCommerceIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2460,59 +2460,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.
*
Expand Down