Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Product Syncing via Feeds #2841

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open

Conversation

mshymon
Copy link
Contributor

@mshymon mshymon commented Dec 17, 2024

Changes proposed in this Pull Request:

The current state of the product syncing via Feeds is broken - while plugin code base has business logic to generate feed file daily and serve the feed file on request, there is no logic for triggering a feed one time upload.

In this PR I am suggesting the following fixes to unblock product sync via feeds:

  1. Trigger a daily feed upload sessions.

    • Sending a one time create feed upload request to Meta would happen on feed file generation completion (this is to ensure we upload as feed file fresh data as possible).
    • Added logic of choosing or creating the correct feed to which such feed upload would happen. This included local caching of the integrated feed ID, validating it is valid, choosing a feed from catalog or creating a new one.
  2. Update Feed file content by:

    • Adding GTIN to the feed file
    • Adding quantity_to_sell_on_facebook to the feed file

Detailed test instructions:

  1. Unit Tests
    A. Run new tests:
    • ./vendor/bin/phpunit --filter ApiTest
    • ./vendor/bin/phpunit --filter fbproductTest
      B. Run all tests:
    • npm run test:php
  2. Manual Tests.
    • Steps were added via an internal dogfooding doc and requires access to Meta internal tools to validate feed upload sessions status.

Changelog entry

Fix - Fixed feeds by requesting a feed file upload session after feed file is generated and added missing new fields to the feed file.

}

// Step 2 - Query feeds data from Meta and filter the right one
$feed_id = self::query_and_filter_integration_feed_id();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could throw an error that is currently not being caught

continue;
}

$woo_feed_name_option_1 = self::FEED_NAME;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggest factor out to private function named something like private function pattern_match_feed_names()

private function query_and_filter_integration_feed_id() {
$catalog_id = facebook_for_woocommerce()->get_integration()->get_product_catalog_id();
if ( '' === $catalog_id ) {
throw new Error( 'No catalog ID' );
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not being caught in retrieve_or_create_integrationFeed_id()

includes/Products/Feed.php Show resolved Hide resolved
includes/Products/Feed.php Show resolved Hide resolved
includes/Products/Feed.php Show resolved Hide resolved
WC_Facebookcommerce_Utils::log( 'Feed: retrieve_integration_feed_id(): feed_id = '.$feed_id.', created a new feed via Meta API.');
return $feed_id;
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can throw an error or log here. Something like 'couldn't create feed'

includes/Products/Feed.php Show resolved Hide resolved
includes/Products/Feed.php Show resolved Hide resolved
};
add_filter( 'pre_http_request', $response, 10, 3 );

$this->api->create_upload( $product_feed_id, $data );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't there be an assert here?

private function validate_feed_exists($feed_id) {
$catalog_id = facebook_for_woocommerce()->get_integration()->get_product_catalog_id();
if ( '' === $catalog_id ) {
throw new Error( 'No catalog ID' );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are the errors stored in the logs or was it a conscious decision to not add any logs here

*
* @internal
*/
private function query_and_filter_integration_feed_id() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method seems like a lot of logic
Can we have it broken out a bit

@@ -715,4 +715,63 @@ public function test_read_feeds_creates_read_feeds_request() {
$response->data
);
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a test to check unhappy path
If errors are thrown or logs are generated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants