Skip to content

Commit

Permalink
Remove custom fields from FB Product Creation
Browse files Browse the repository at this point in the history
  • Loading branch information
David Evbodaghe committed Feb 8, 2025
1 parent 4be2987 commit 94bae7d
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 88 deletions.
19 changes: 1 addition & 18 deletions includes/fbproduct.php
Original file line number Diff line number Diff line change
Expand Up @@ -724,8 +724,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 @@ -740,7 +738,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 );
$gpc_field_name = 'google_product_category';
Expand Down Expand Up @@ -772,8 +769,7 @@ public function prepare_product( $retailer_id = null, $type_to_prepare_for = sel
'price' => $this->get_fb_price(),
'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
'visibility' => Products::is_product_visible( $this->woo_product ) ? \WC_Facebookcommerce_Integration::FB_SHOP_PRODUCT_VISIBLE : \WC_Facebookcommerce_Integration::FB_SHOP_PRODUCT_HIDDEN
);

if ( self::PRODUCT_PREP_TYPE_NORMAL !== $type_to_prepare_for && ! empty( $video_urls ) ) {
Expand Down Expand Up @@ -1139,17 +1135,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 @@ -527,11 +527,6 @@ public function test_on_product_save_existing_simple_product_sync_enabled_update
$facebook_product_data['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 @@ -560,10 +555,6 @@ public function test_on_product_save_existing_simple_product_sync_enabled_update
// Verify Facebook-specific fields were saved
$facebook_product_to_update = new WC_Facebook_Product( $product_to_update->get_id() );
$updated_product_data = $facebook_product_to_update->prepare_product(null, \WC_Facebook_Product::PRODUCT_PREP_TYPE_ITEMS_BATCH );

$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 ) );
Expand Down
62 changes: 1 addition & 61 deletions tests/Unit/fbproductTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -527,67 +527,7 @@ 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_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';

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

$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);
$this->assertArrayHasKey('image_link', $product_data);
}


/**
* Test Brand is added for simple product
Expand Down

0 comments on commit 94bae7d

Please sign in to comment.