CSV import/export
See original GitHub issueImplement CSV import/export for products.
Export
Proposed API:
type Mutation {
exportProducts(scope: ExportScope, filter: ProductFilterInput, ids: [ID!]): Job!
}
enum ExportScope {
ALL
IDS
FILTER
}
type Job {
id: ID!
status: String!
createdAt: DateTime!
url: String
}
Description
Mutation triggers a Celery task that takes given queryset of products and exports them to a file. As a result of the mutation, we return a Job
object that informs about the status of the operation. Once the task is finished, Job
will contain a link to download the CSV file (or a dashboard view with the report and download link). We will send this link in an email to the user who requested the operation.
Job objects could be used in the dashboard to render a list of scheduled jobs, query their status or access past exports, but we’ll need to agree if this in the scope of this PR.
Parms:
My idea is to use scope
, filter
and ids
to determine which products to export. filter
would be of the same shape as filter used in the products
query, so we can filter out some products first on the list and then export them. ids
is to allow exporting only selected set of product ids
. There is also the ability to export all products in the database. The scope
param would determine which of these three export options to use.
Permissions: MANAGE_PRODUCTS
(or specific permission only for import/export - needs to be discussed)
Import
type Mutation {
importProducts(file: Upload!, updateExisting: Boolean!, updateStock: Boolean!): Job!
}
Description
Mutation passes the uploaded file to a task that reads and parses the file. For each row, we create necessary model instances, create connections between them and save them in the database. Once the task is finished we send an email to the staff user who requested the operation with a report about the number of successful/failed rows and/or errors that occurred.
Params:
updateExisting
- if true and there is a product/variant ID in CSV that already exists in the database, the import will override these products with data from CSV. If false, lines that refer to existing products will be skipped.updateStock
- whether to update stock quantities with values from the CSV file. This is to guard against overriding the inventory accidentally with quantities that may be outdated in the file.
Permissions: same as exportProducts
mutation.
Notes
- Rows in the CSV file will represent either products or variants. We will assume that the first line (after the header line) will represent a product and the following lines will represent its variants until the importer recognizes the next product.
- Product images will be exported as URLs; when importing we also expect URLs where we’ll download the images from.
- The importer should be able to create new products, variants, attributes with values and images. For some other related objects, we’ll assume that they exist in the database and we’ll match them by IDs or slugs: warehouses, categories, collections, product types.
- The exact shape of CSV will be agreed on once we start working on this feature.
This is a draft and I’m open to suggestions, so we end up with API that we all agree with. The details of the shape of the proposed API is also to be adjusted if I missed something.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:5
- Comments:18 (5 by maintainers)
Hey! Any progress on the tool? When can we expect it? Will be very helpful.
I also need csv import export feature. Currently using woocommerce but can’t switch to saleor due to this.