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

DFC import: Find broader taxon if we don't have a specific one #13109

Merged
merged 4 commits into from
Feb 4, 2025

Conversation

mkllnk
Copy link
Member

@mkllnk mkllnk commented Jan 30, 2025

What? Why?

One of the suppliers in the UK is importing beef products but we don't have a beef product category (taxon). Luckily the DFC organises product types with links to broader concepts. So we can go up in the product type hierarchy until we find a matching type, like meat product.

What should we test?

  • Import a DFC catalog with not-quite matching product types.
  • But I think that the specs are enough.

Release notes

Changelog Category (reviewers may add a label for the release notes):

  • User facing changes
  • API changes (V0, V1, DFC or Webhook)
  • Technical changes only
  • Feature toggled

The title of the pull request will be included in the release notes.

Dependencies

Documentation updates

We didn't actually need the extra class.
For example, when importing `beef` products associate the type `meat-product`
instead because we don't have a specific beef category.
@mkllnk mkllnk added the technical changes only These pull requests do not contain user facing changes and are grouped in release notes label Jan 30, 2025
@mkllnk mkllnk self-assigned this Jan 30, 2025
@mkllnk mkllnk marked this pull request as ready for review January 30, 2025 00:30
# recursive call
record_type(current_product_type, narrower)
end
DataFoodConsortium::Connector::SKOSParser.concepts[dfc_id]
Copy link
Member Author

Choose a reason for hiding this comment

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

In this commit I kept the spec file untouched and it passes.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice ! Is this a recent addition to the connector ?

@dacook dacook self-requested a review January 30, 2025 00:51
Copy link
Member

@dacook dacook left a comment

Choose a reason for hiding this comment

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

Very clever!

My first thought was: why not just load all DFC taxons into OFN? But I imagine that list would be very unwieldy and cause other challenges for categorising products.
This method makes is way more manageable.

Comment on lines +13 to +17
taxons = priority_list.lazy.map do |type|
Spree::Taxon.find_by(dfc_id: type.semanticId)
end.compact

taxons.first || Spree::Taxon.first
Copy link
Member

Choose a reason for hiding this comment

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

Nice to see different ways of doing things. I probably would have ended up with an each or reduce loop, but this is nice 👍

@mkllnk
Copy link
Member Author

mkllnk commented Jan 30, 2025

why not just load all DFC taxons into OFN?

Yes, that is a long-term idea. But for the migration, we need to map current taxons to DFC types. Therefore we added UI in OFN to add a dfc_id to each taxon. I don't know how many instances have done that. They all have different taxons in the database and that is part of discovery for DFC as well. If the DFC is missing something, we need to add it there. Then we would be in a position to migrate taxon associations to pure DFC ids and get rid of OFN's custom taxons.

Then there are of course a lot more product types then we currently have as taxons. So first we would need to improve the UX to make the selection easier. But none of this work has been requested and scheduled so far. We have bigger fish to fry.

@RaggedStaff RaggedStaff added the pr-staged-uk staging.openfoodnetwork.org.uk label Jan 30, 2025
Copy link
Collaborator

@rioug rioug left a comment

Choose a reason for hiding this comment

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

Nice one 👍

# recursive call
record_type(current_product_type, narrower)
end
DataFoodConsortium::Connector::SKOSParser.concepts[dfc_id]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice ! Is this a recent addition to the connector ?

@dacook
Copy link
Member

dacook commented Feb 3, 2025

@RaggedStaff I see you deployed this to staging. Did you want to do any further testing, or are you happy to merge this?

@mkllnk
Copy link
Member Author

mkllnk commented Feb 4, 2025

Is this a recent addition to the connector ?

No. I needed to add that for the DFC importer.

@mkllnk mkllnk removed the pr-staged-uk staging.openfoodnetwork.org.uk label Feb 4, 2025
@mkllnk
Copy link
Member Author

mkllnk commented Feb 4, 2025

Shopify catalog is not ready for testing. It doesn't have the right product types. We can merge this.

@mkllnk mkllnk merged commit 0eb9dcc into openfoodfoundation:master Feb 4, 2025
38 checks passed
@mkllnk mkllnk deleted the product-type-lookup branch February 4, 2025 04:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
technical changes only These pull requests do not contain user facing changes and are grouped in release notes
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants