Skip to content

Fix Product Syncing via Feeds#2841

Closed
mshymon wants to merge 15 commits intofacebook:mainfrom
mshymon:fix_feeds
Closed

Fix Product Syncing via Feeds#2841
mshymon wants to merge 15 commits intofacebook:mainfrom
mshymon:fix_feeds

Conversation

@mshymon
Copy link
Copy Markdown
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
    • Adding rich_text_description to the feed file
  3. Fixed incorrect values in the Feed file content:

    • Fixed google_product_category (was empty)
    • Fixed product_type (was incorrect, we were populating a GPC here)
    • Fixed description (was incorrect values for variants)

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.

continue;
}

$woo_feed_name_option_1 = self::FEED_NAME;
Copy link
Copy Markdown
Contributor

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 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
Copy Markdown
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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is a pattern I saw in the code for checking $catalog_id presence. This is mostly because we should not get into a state with no catalog.
But this is actually possible if user disconnects the plugin from a catalog (basically offboards).
This is a good use case to test our plugin behaviour overall, not just feed.

*
* @internal
*/
private function query_and_filter_integration_feed_id() {
Copy link
Copy Markdown
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

$response->data
);
}

Copy link
Copy Markdown
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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think it won't bring value in this case, as we just mock response. Test with error mocks were added for other calls. that should be enough I think.

Copy link
Copy Markdown
Contributor Author

@mshymon mshymon left a comment

Choose a reason for hiding this comment

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

Addressed the PR comments. Thanks everyone for reviewing the code!

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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is a pattern I saw in the code for checking $catalog_id presence. This is mostly because we should not get into a state with no catalog.
But this is actually possible if user disconnects the plugin from a catalog (basically offboards).
This is a good use case to test our plugin behaviour overall, not just feed.

$response->data
);
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think it won't bring value in this case, as we just mock response. Test with error mocks were added for other calls. that should be enough I think.

@facebook-github-bot
Copy link
Copy Markdown
Contributor

@mshymon has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Copy Markdown
Contributor

@mshymon has updated the pull request. You must reimport the pull request before landing.

1 similar comment
@facebook-github-bot
Copy link
Copy Markdown
Contributor

@mshymon has updated the pull request. You must reimport the pull request before landing.

@facebook-github-bot
Copy link
Copy Markdown
Contributor

@mshymon has updated the pull request. You must reimport the pull request before landing.

@facebook-github-bot
Copy link
Copy Markdown
Contributor

@mshymon merged this pull request in 08cb559.

facebook-github-bot pushed a commit that referenced this pull request Feb 25, 2025
Summary:
## Changelog:

* Add - FB product video field to add videos. Also added products sync to support the video field with Batch API by gurtejrehal in #2874
* Tweak - tests for #2874 by gurtejrehal in #2888
* Tweak - tests for Product Update action as ramp up task by nealweiMeta in #2883
* Fix - translations loading before the init hook by iodic in #2866
* Fix - Fixed feeds by requesting a feed file upload session after feed file is generated and added missing new fields to the feed file by mshymon in #2841

Pull Request resolved: #2891

Reviewed By: akpurifb

Differential Revision: D69836863

Pulled By: vahidkay-meta

fbshipit-source-id: 32408ab4b42f60f921bd599ed982933017185b5e
@Jmencab Jmencab mentioned this pull request Mar 3, 2025
1 task
facebook-github-bot pushed a commit that referenced this pull request Mar 6, 2025
Summary:
### Changes proposed in this Pull Request:
Changes in detail here: https://docs.google.com/document/d/1PaXHKK1PRVtiBEwJtH_8ZP8h0UitDCXZnpFFDWo-eik/edit?tab=t.0#heading=h.m8p14s8600vn
The main idea is to add a FeedManager singleton that will manage all the distinct Feed singletons. The Feed singletons will inherit from an AbstractFeed which will delegate the actual file creation to the Feed Handler or Feed Generator given the admin preferences. With that being said, the sequence will look similar to the existing product flow, but with the above simplifications:

![image](https://github.com/user-attachments/assets/1f0b3929-e4b5-4d37-bd53-6c3792e12a93)

Closes # .
Detailed test instructions:
Added an API test as done in this PR: #2841
Integration test not yet possible as dependent on Mice framework addition and Ent creation
Added comments for how to test/dogfood as well as included instructions in the above linked doc
Successful upload via Feed Handler:
https://www.internalfb.com/intern/cat/sessions/642042718535396/
Successful upload via Feed Generator:
https://www.internalfb.com/intern/cat/sessions/642101398529528/

**See branch common_framework_test to see an example proof of concept that utilizes the base classes.**
This will just include what will be checked in via diff.

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

- [ ] Do the changed files pass `phpcs` checks? Please remove `phpcs:ignore` comments in changed files and fix any issues, or delete if not practical.

Pull Request resolved: #2875

Reviewed By: carterbuce, nrostrow-meta

Differential Revision: D69409593

Pulled By: Jmencab

fbshipit-source-id: 8ec2feb7f1ac54d89c9a84f9e6f7ca31592f3f02
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.

6 participants