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
24 changes: 22 additions & 2 deletions includes/Products/Sync.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,28 @@ public function create_or_update_all_products() {
$profiling_logger = facebook_for_woocommerce()->get_profiling_logger();
$profiling_logger->start( 'create_or_update_all_products' );

// Queue up these IDs for sync. they will only be included in the final requests if they should be synced.
$this->create_or_update_products( \WC_Facebookcommerce_Utils::get_all_product_ids_for_sync() );
// Get all product IDs that are eligible for sync
$all_product_ids = \WC_Facebookcommerce_Utils::get_all_product_ids_for_sync();

// Filter to only get products modified since last sync
$products_to_sync = array();
foreach ( $all_product_ids as $product_id ) {
$product = wc_get_product( $product_id );
if ( ! $product ) {
continue;
}

$last_sync_time = get_post_meta( $product_id, '_fb_sync_last_time', true );
$modified_time = $product->get_date_modified() ? $product->get_date_modified()->getTimestamp() : 0;

// If never synced or modified since last sync, add to sync queue
if ( ! $last_sync_time || $modified_time > $last_sync_time ) {
$products_to_sync[] = $product_id;
}
}

// Queue up filtered IDs for sync
$this->create_or_update_products( $products_to_sync );

$profiling_logger->stop( 'create_or_update_all_products' );
}
Expand Down
8 changes: 6 additions & 2 deletions includes/Products/Sync/Background.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,14 @@ private function process_item_update( $prefixed_product_id ) {
$product_data['id'] = $retailer_id;

$request = [
'method' => Sync::ACTION_UPDATE,
'data' => $product_data,
'method' => Sync::ACTION_UPDATE,
'data' => $product_data,
'product_id' => $product_id, // Store the product ID for later use
];

// Update the sync timestamp after preparing the product for sync
update_post_meta( $product_id, '_fb_sync_last_time', time() );

/**
* Filters the data that will be included in a UPDATE sync request.
*
Expand Down
Loading