From f80b1e0d20093824185badf9f13b305d7a455a5c Mon Sep 17 00:00:00 2001 From: Rithik Bhandari Date: Wed, 9 Jul 2025 21:07:38 +0100 Subject: [PATCH 1/3] feat: add variable to track sync latency --- includes/fbproduct.php | 3 +++ includes/fbproductfeed.php | 3 ++- tests/Unit/fbproductTest.php | 20 ++++++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/includes/fbproduct.php b/includes/fbproduct.php index d5c2a1fd6..23120a22b 100644 --- a/includes/fbproduct.php +++ b/includes/fbproduct.php @@ -2204,6 +2204,9 @@ public function prepare_product( $retailer_id = null, $type_to_prepare_for = sel $product_data['external_update_time'] = $date_modified->getTimestamp(); } + // Add product preparation timestamp + $product_data['product_prepare_time'] = time(); + // Only use checkout URLs if they exist. $checkout_url = $this->build_checkout_url( $product_url ); if ( $checkout_url ) { diff --git a/includes/fbproductfeed.php b/includes/fbproductfeed.php index 5db4b94c2..55019483f 100644 --- a/includes/fbproductfeed.php +++ b/includes/fbproductfeed.php @@ -421,7 +421,7 @@ public function get_product_feed_header_row() { 'additional_image_link,sale_price_effective_date,sale_price,condition,' . 'visibility,gender,color,size,pattern,google_product_category,default_product,' . 'variant,gtin,quantity_to_sell_on_facebook,rich_text_description,internal_label,external_update_time,' . - 'external_variant_id, is_woo_all_products_sync' . PHP_EOL; + 'product_prepare_time,external_variant_id, is_woo_all_products_sync' . PHP_EOL; } @@ -581,6 +581,7 @@ private function prepare_product_for_feed( $woo_product, &$attribute_variants ) static::format_string_for_feed( static::get_value_from_product_data( $product_data, 'rich_text_description' ) ) . ',' . static::format_internal_labels_for_feed( static::get_value_from_product_data( $product_data, 'internal_label' ) ) . ',' . static::get_value_from_product_data( $product_data, 'external_update_time' ) . ',' . + static::get_value_from_product_data( $product_data, 'product_prepare_time' ) . ',' . static::get_value_from_product_data( $product_data, 'external_variant_id' ) . ',' . static::format_string_for_feed( $is_woo_all_products_sync ) . PHP_EOL; } diff --git a/tests/Unit/fbproductTest.php b/tests/Unit/fbproductTest.php index 4746d1348..7859ea267 100644 --- a/tests/Unit/fbproductTest.php +++ b/tests/Unit/fbproductTest.php @@ -1085,6 +1085,26 @@ public function test_external_update_time_unset() { $this->assertEquals(isset($data['external_update_time']), false); } + /** + * Test prepare_product_time is populated + * @return void + */ + public function test_prepare_product_time_set() { + $woo_product = WC_Helper_Product::create_simple_product(); + + $before_time = time(); + $fb_product = new \WC_Facebook_Product( $woo_product ); + $data = $fb_product->prepare_product(); + $after_time = time(); + + $this->assertArrayHasKey('prepare_product_time', $data); + $this->assertIsNumeric($data['prepare_product_time']); + + // Verify the timestamp is within the expected range (between before and after the prepare_product call) + $this->assertGreaterThanOrEqual($before_time, $data['prepare_product_time']); + $this->assertLessThanOrEqual($after_time, $data['prepare_product_time']); + } + /** * Test fallback to main description when it's less than 1000 characters. */ From 0e40a7f2365d461dd502b2898bba5a8872aba819 Mon Sep 17 00:00:00 2001 From: Rithik Bhandari Date: Wed, 9 Jul 2025 21:27:12 +0100 Subject: [PATCH 2/3] chore: fixed name --- tests/Unit/fbproductTest.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/Unit/fbproductTest.php b/tests/Unit/fbproductTest.php index 7859ea267..cfa6742cf 100644 --- a/tests/Unit/fbproductTest.php +++ b/tests/Unit/fbproductTest.php @@ -1086,23 +1086,23 @@ public function test_external_update_time_unset() { } /** - * Test prepare_product_time is populated + * Test product_prepare_time is populated * @return void */ - public function test_prepare_product_time_set() { + public function test_product_prepare_time_set() { $woo_product = WC_Helper_Product::create_simple_product(); $before_time = time(); $fb_product = new \WC_Facebook_Product( $woo_product ); - $data = $fb_product->prepare_product(); + $data = $fb_product->product_prepare(); $after_time = time(); - $this->assertArrayHasKey('prepare_product_time', $data); - $this->assertIsNumeric($data['prepare_product_time']); + $this->assertArrayHasKey('product_prepare_time', $data); + $this->assertIsNumeric($data['product_prepare_time']); - // Verify the timestamp is within the expected range (between before and after the prepare_product call) - $this->assertGreaterThanOrEqual($before_time, $data['prepare_product_time']); - $this->assertLessThanOrEqual($after_time, $data['prepare_product_time']); + // Verify the timestamp is within the expected range (between before and after the product_prepare call) + $this->assertGreaterThanOrEqual($before_time, $data['product_prepare_time']); + $this->assertLessThanOrEqual($after_time, $data['product_prepare_time']); } /** From f9e0f3bf765659d92e4979731cd4774381a2a754 Mon Sep 17 00:00:00 2001 From: Rithik Bhandari Date: Wed, 9 Jul 2025 21:30:55 +0100 Subject: [PATCH 3/3] small fix --- tests/Unit/fbproductTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Unit/fbproductTest.php b/tests/Unit/fbproductTest.php index cfa6742cf..8521e0765 100644 --- a/tests/Unit/fbproductTest.php +++ b/tests/Unit/fbproductTest.php @@ -1094,7 +1094,7 @@ public function test_product_prepare_time_set() { $before_time = time(); $fb_product = new \WC_Facebook_Product( $woo_product ); - $data = $fb_product->product_prepare(); + $data = $fb_product->prepare_product(); $after_time = time(); $this->assertArrayHasKey('product_prepare_time', $data);