Merge pull request #12525 from mkllnk/fdc-import

Add compatibility to the DFC product import for FDC (Shopify) API
This commit is contained in:
Maikel
2024-06-13 09:51:05 +10:00
committed by GitHub
11 changed files with 569 additions and 19 deletions

View File

@@ -20,7 +20,7 @@ module Admin
catalog_url = params.require(:catalog_url)
json_catalog = DfcRequest.new(spree_current_user).get(catalog_url)
json_catalog = fetch_catalog(catalog_url)
graph = DfcIo.import(json_catalog)
# * First step: import all products for given enterprise.
@@ -34,6 +34,16 @@ module Admin
private
def fetch_catalog(url)
if url =~ /food-data-collaboration/
fdc_json = FdcRequest.new(spree_current_user).call(url)
fdc_message = JSON.parse(fdc_json)
fdc_message["products"]
else
DfcRequest.new(spree_current_user).call(url)
end
end
# Most of this code is the same as in the DfcProvider::SuppliedProductsController.
def import_product(subject, enterprise)
return unless subject.is_a? DataFoodConsortium::Connector::SuppliedProduct