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
17 changes: 0 additions & 17 deletions includes/fbproduct.php
Original file line number Diff line number Diff line change
Expand Up @@ -825,8 +825,6 @@ public function prepare_product( $retailer_id = null, $type_to_prepare_for = sel
$categories =
WC_Facebookcommerce_Utils::get_product_categories( $id );

$custom_fields = $this->get_facebook_specific_fields();

if ( self::PRODUCT_PREP_TYPE_ITEMS_BATCH === $type_to_prepare_for ) {
$product_data = array(
'title' => WC_Facebookcommerce_Utils::clean_string( $this->get_title() ),
Expand All @@ -842,7 +840,6 @@ public function prepare_product( $retailer_id = null, $type_to_prepare_for = sel
'price' => $this->get_fb_price( true ),
'availability' => $this->is_in_stock() ? 'in stock' : 'out of stock',
'visibility' => Products::is_product_visible( $this->woo_product ) ? \WC_Facebookcommerce_Integration::FB_SHOP_PRODUCT_VISIBLE : \WC_Facebookcommerce_Integration::FB_SHOP_PRODUCT_HIDDEN,
'custom_fields' => $custom_fields,
);
$product_data = $this->add_sale_price( $product_data, true );
if ( ! empty( $video_urls ) ) {
Expand Down Expand Up @@ -875,7 +872,6 @@ public function prepare_product( $retailer_id = null, $type_to_prepare_for = sel
'currency' => get_woocommerce_currency(),
'availability' => $this->is_in_stock() ? 'in stock' : 'out of stock',
'visibility' => Products::is_product_visible( $this->woo_product ) ? \WC_Facebookcommerce_Integration::FB_SHOP_PRODUCT_VISIBLE : \WC_Facebookcommerce_Integration::FB_SHOP_PRODUCT_HIDDEN,
'custom_fields' => $custom_fields
);

if ( self::PRODUCT_PREP_TYPE_NORMAL !== $type_to_prepare_for && ! empty( $video_urls ) ) {
Expand Down Expand Up @@ -1240,17 +1236,4 @@ public function prepare_variants_for_group( $feed_data = false ) {
return $final_variants;
}

/**
* Returns information about which fields are using Facebook-specific values.
*
* @return array
*/
private function get_facebook_specific_fields(): array {
return array(
'has_fb_description' => (bool) get_post_meta($this->id, self::FB_PRODUCT_DESCRIPTION, true),
'has_fb_price' => (bool) get_post_meta($this->id, self::FB_PRODUCT_PRICE, true),
'has_fb_image' => (bool) get_post_meta($this->id, self::FB_PRODUCT_IMAGE, true)
);
}

}
9 changes: 0 additions & 9 deletions tests/Unit/WCFacebookCommerceIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -528,11 +528,6 @@ public function test_on_product_save_existing_simple_product_sync_enabled_update
$facebook_product_data['rich_text_description'] = 'Facebook product description.';
$facebook_product_data['price'] = '199 USD';
$facebook_product_data['google_product_category'] = 1718;
$facebook_product_data['custom_fields'] = [
'has_fb_description' => true,
'has_fb_price' => true,
'has_fb_image' => true
];

$requests = WC_Facebookcommerce_Utils::prepare_product_requests_items_batch($facebook_product_data);

Expand Down Expand Up @@ -565,10 +560,6 @@ public function test_on_product_save_existing_simple_product_sync_enabled_update
$this->assertEquals( 'Facebook product description.', get_post_meta( $facebook_product_to_update->get_id(), WC_Facebook_Product::FB_PRODUCT_DESCRIPTION, true ) );
$this->assertEquals( 'Facebook product description.', get_post_meta( $facebook_product_to_update->get_id(), WC_Facebook_Product::FB_RICH_TEXT_DESCRIPTION, true ) );

$this->assertEquals(true, $updated_product_data['custom_fields']['has_fb_description']);
$this->assertEquals(true, $updated_product_data['custom_fields']['has_fb_price']);
$this->assertEquals(true, $updated_product_data['custom_fields']['has_fb_image']);

// Verify the actual values are still stored in meta
$this->assertEquals( 'Facebook product description.', get_post_meta( $facebook_product_to_update->get_id(), WC_Facebook_Product::FB_PRODUCT_DESCRIPTION, true ) );
$this->assertEquals( '199', get_post_meta( $facebook_product_to_update->get_id(), WC_Facebook_Product::FB_PRODUCT_PRICE, true ) );
Expand Down
47 changes: 0 additions & 47 deletions tests/Unit/fbproductTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -527,34 +527,6 @@ public function test_enhanced_catalog_fields_from_attributes(
$this->assertEquals($product_data[$key], $value);
}
}

public function test_prepare_product_with_default_fields() {
// test when no fb specific fields are set
$product_data = $this->fb_product->prepare_product();

$this->assertArrayHasKey('custom_fields', $product_data);
$this->assertEquals(false, $product_data['custom_fields']['has_fb_description']);
$this->assertEquals(false, $product_data['custom_fields']['has_fb_price']);
$this->assertEquals(false, $product_data['custom_fields']['has_fb_image']);
}

public function test_prepare_product_with_custom_fields() {
// Set facebook specific fields
$fb_description = 'Facebook specific description';
$fb_price = '15';
$fb_image = 'https:example.com/fb-image.jpg';

update_post_meta($this->product->get_id(), WC_Facebook_Product::FB_PRODUCT_DESCRIPTION, $fb_description);
update_post_meta($this->product->get_id(), WC_Facebook_Product::FB_PRODUCT_PRICE, $fb_price);
update_post_meta($this->product->get_id(), WC_Facebook_Product::FB_PRODUCT_IMAGE, $fb_image);

$product_data = $this->fb_product->prepare_product();

$this->assertArrayHasKey('custom_fields', $product_data);
$this->assertEquals(true, $product_data['custom_fields']['has_fb_description']);
$this->assertEquals(true, $product_data['custom_fields']['has_fb_price']);
$this->assertEquals(true, $product_data['custom_fields']['has_fb_image']);
}

public function test_prepare_product_with_video_field() {
// Set facebook specific fields
Expand Down Expand Up @@ -616,20 +588,6 @@ public function test_set_product_video_urls() {
$this->assertNotContains('', $saved_video_urls);
}

public function test_prepare_product_with_mixed_fields() {
// Set only facebook description
$fb_description = 'Facebook specific description';

update_post_meta($this->product->get_id(), WC_Facebook_Product::FB_PRODUCT_DESCRIPTION, $fb_description);

$product_data = $this->fb_product->prepare_product();

$this->assertArrayHasKey('custom_fields', $product_data);
$this->assertEquals(true, $product_data['custom_fields']['has_fb_description']);
$this->assertEquals(false, $product_data['custom_fields']['has_fb_price']);
$this->assertEquals(false, $product_data['custom_fields']['has_fb_image']);
}

public function test_prepare_product_items_batch() {
// Test the PRODUCT_PREP_TYPE_ITEMS_BATCH preparation type
$fb_description = 'Facebook specific description';
Expand All @@ -638,11 +596,6 @@ public function test_prepare_product_items_batch() {

$product_data = $this->fb_product->prepare_product(null, WC_Facebook_Product::PRODUCT_PREP_TYPE_ITEMS_BATCH);

$this->assertArrayHasKey('custom_fields', $product_data);
$this->assertEquals(true, $product_data['custom_fields']['has_fb_description']);
$this->assertEquals(false, $product_data['custom_fields']['has_fb_price']);
$this->assertEquals(false, $product_data['custom_fields']['has_fb_image']);

// Also verify the main product data structure for items batch
$this->assertArrayHasKey('title', $product_data);
$this->assertArrayHasKey('description', $product_data);
Expand Down