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..8521e0765 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 product_prepare_time is populated + * @return void + */ + 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(); + $after_time = 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 product_prepare call) + $this->assertGreaterThanOrEqual($before_time, $data['product_prepare_time']); + $this->assertLessThanOrEqual($after_time, $data['product_prepare_time']); + } + /** * Test fallback to main description when it's less than 1000 characters. */