openfoodfoundation / integrations

A place to store scripts and other little integration scripts
0 stars 1 forks source link

[Bug] N8N Product Export should return correct products for an enterprise #7

Closed lin-d-hop closed 1 year ago

lin-d-hop commented 1 year ago

Describe the bug Issue 1 - the export file is NOT capturing all the products in the enterprise product list. Products that are missing all have one thing in common. On the product list, they are showing an import date. All products, on my product list, showing an import date, are not included in the export file. All products, on my product list, without an import date, are included in the export file. (SO - maybe previously imported products are not included in the current n8n download?)

Issue 2 - for this recent export David used a unique login for an enterprise called Garden Party (162) (thats the enterprise I want the export for) But SOME products (and not all) from 2 other enterprises were included in the export file also. The export for this unique login included products from Garden Party Plants (333) and Garden Party Flower Farm (243). Those 2 enterprise (333 & 243) have given enterprise 162 permission for 'everything', so perhaps this is why some of their products got included? I've tried to figure out why some of these 'other enterprise' products are being included in the export file, but others are not and i can't see anything that defines them. But for now - it seems that when doing the n8n export file for a given enterprise, that enterprise needs to have 1. a unique login, and ALSO 2. no other enterprise has given 'everything' permissions.

How did you experience it Running the N8N workflow

Expected behaviour Ideally it should give a csv file with all the products/variants for an enterprise in the format required for OFN product upload file. This will allow hubs to edit the CSV file with new stock level and upload the same directly on OFN website.

The product list returned should be ALL products for the specified enterprises and no products for enterprises that this enterprise does not have permission to access.

Workflows or tools involved N8N to CSV export Link to workflow: https://n8n.openfoodnetwork.org.uk/workflow/55

Additional context Add any other context about the problem here. Slack thread

lin-d-hop commented 1 year ago

Notes from Theresa:

Re: it seems that when doing the n8n export file for a given enterprise, that enterprise needs to have 1. a unique login, and ALSO 2. no other enterprise has given 'everything' permissions. I just removed permissions from the enterprise I was testing - and indeed, the n8n export no longer includes the products from those permission-giving enterprises. So - at present - as long as the enterprise has a unique login, and no other enterprise has given it 'manage products' permission, the 8n8 export pulls the correct products.

Re: (SO - maybe previously imported products are not included in the current n8n download?) Did you update this since I posted on slack @div-yansh-1 ? Because I just tested another export file - same enterprise as 2 days ago - and now, the products that were missing in the first test, are present. So - confirming that the n8n export is drawing all the products from the enterprise's product list (no idea why before previously imported products weren't included.)

So it seems like the 8n8 download is ALMOST there. BUT - I'm getting an error that 'shipping category cannot be blank' when I go to import the data from the n8n export. So - I guess we need to include shipping category data in the export? If I just put 'default' manually into my import file - it works (I can get rid of that import error)

AND - one last thing. The n8n export needs to include the 'on demand' field. Right now it seems that if a producer has set a product to 'on demand' in their product list, the n8n export reads 'on hand' =0. And then importing using this file, changes on demand to on hand = 0 in the product list. The import file template needs an on-demand column, and the on demand field = 1 when on demand is set. Otherwise, the import file just re-sets on-demand to on-hand =0.

I am SO SO excited that we are close......

div-yansh-1 commented 1 year ago

Hi @tschumilas,

I have updated the workflow and it should work fine now. Can you check and confirm.

Issue 1 (Not showing all the products): Didn’t encounter this. Saw your message that it's working so left this one.

Issue 2 (Unique login + giving permission issue): Resolved.

You can use any login as long as the user has access to the products you are looking for. For ex. you can use hub login to get product list of a specific producer using enterprise id of that producer.

Add the enterprise id of the producer in the query parameter section on the HTTP module (”GET bulk products”):

image

Issue 3: Blank Shipping category: So how it works is, the Products API (v0) doesn't give us the shipping category for a product, but shipping category is required for the product upload. And we cannot change any category values using the product upload CSV. Therefore, we need to have a field/column in the product export csv for shipping category and it should have exact same shipping category for the product as it is on OFN. Most of the time it's just “Default” in the shipping category. So, I have added a default value of “Default” shipping category in the CSV. But it would need to be changed by the producer if they are using any other shipping category for their products.

Issue 4 (on_demand field not present in the CSV): Added the field

Issue 5 (Gmail module error-not mentioned in the thread): I think it just needs a refresh/re-verification of the Gmail connection. Since I don’t have access to OFN CA gmail account at the moment, I wasn’t able to sort it out. But anyone with access to that email should be able to update the connection by editing the OFN CA Platform Email (Gmail) connection and then signing in. Otherwise, I can do it, if I get temporary access to this gmail account. image

div-yansh-1 commented 1 year ago

@tschumilas, don't test it at the moment. Some of the recent changes to this workflow were reverted/lost due to n8n crash today. So, I will update/modify the workflow again and let you know. Then you can test it.

div-yansh-1 commented 1 year ago

@tschumilas can you check now