Skip to content
Open
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
3 changes: 3 additions & 0 deletions includes/fbproduct.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down
3 changes: 2 additions & 1 deletion includes/fbproductfeed.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}


Expand Down Expand Up @@ -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;
}
Expand Down
20 changes: 20 additions & 0 deletions tests/Unit/fbproductTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
Loading