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
4 changes: 4 additions & 0 deletions includes/fbproduct.php
Original file line number Diff line number Diff line change
Expand Up @@ -896,6 +896,10 @@ public function prepare_product( $retailer_id = null, $type_to_prepare_for = sel
$product_data['gtin'] = $gtin;
}

if ( $date_modified = $this->woo_product->get_date_modified() ) {
$product_data[ 'external_update_time' ] = $date_modified->getTimestamp();
}

// Only use checkout URLs if they exist.
$checkout_url = $this->build_checkout_url( $product_url );
if ( $checkout_url ) {
Expand Down
5 changes: 3 additions & 2 deletions includes/fbproductfeed.php
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ public function get_product_feed_header_row() {
return 'id,title,description,image_link,link,product_type,' .
'brand,price,availability,item_group_id,checkout_url,' .
'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' . PHP_EOL;
'visibility,gender,color,size,pattern,google_product_category,default_product,variant,gtin,quantity_to_sell_on_facebook,rich_text_description,external_update_time' . PHP_EOL;
}


Expand Down Expand Up @@ -533,7 +533,8 @@ private function prepare_product_for_feed( $woo_product, &$attribute_variants )
static::format_string_for_feed( static::get_value_from_product_data( $product_data, 'variant' )) . ',' .
static::format_string_for_feed( static::get_value_from_product_data( $product_data, 'gtin' )) . ',' .
static::format_string_for_feed( static::get_value_from_product_data( $product_data, 'quantity_to_sell_on_facebook' )) . ',' .
static::format_string_for_feed( static::get_value_from_product_data( $product_data, 'rich_text_description' ) ) . PHP_EOL;
static::format_string_for_feed( static::get_value_from_product_data( $product_data, 'rich_text_description' ) ) . ',' .
static::get_value_from_product_data( $product_data, 'external_update_time' ) . PHP_EOL;
}

private static function format_additional_image_url( $product_image_urls ) {
Expand Down
30 changes: 30 additions & 0 deletions tests/Unit/fbproductTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -865,4 +865,34 @@ public function test_get_fb_brand_variable_products() {
$brand = $facebook_product_variation->get_fb_brand();
$this->assertEquals($brand, 'Adidas');
}

/**
* Test external_update_time is populated
* @return void
*/
public function test_external_update_time_set() {
$woo_product = WC_Helper_Product::create_simple_product();

$timestamp = time();
$woo_product->set_date_modified($timestamp);

$fb_product = new \WC_Facebook_Product( $woo_product );
$data = $fb_product->prepare_product();

$this->assertEquals( $data['external_update_time'], $timestamp);
}

/**
* Test external_update_time is not populated
* @return void
*/
public function test_external_update_time_unset() {
$woo_product = WC_Helper_Product::create_simple_product();
$woo_product->set_date_modified(null);

$fb_product = new \WC_Facebook_Product( $woo_product );
$data = $fb_product->prepare_product();

$this->assertEquals(isset($data['external_update_time']), false);
}
}