medusa
medusa copied to clipboard
Implement `ProductImportStrategy`
-
add
ProductImportStrategy
class for processing products batch import which implements the common batch job strategy interface -
depends on: https://github.com/medusajs/medusa/issues/1264
DoD
- [ ] When
dry_run: true
ProductImportStrategy should first move BatchJob to anawaiting_confirmation
state before importing data.
// pre-confirmation.json
[
{ operation: "create", type: "product", data: { .... },
{ operation: "create", type: "product-variant", data: { ... }
]
// ON CONFIRM
await Promise.all(preconfirmops.map((op) => {
switch(op.operation)
case "create":
productService.create(op.data)
break
case "update":
productVariantService.update(op.existing_id, op.data)
}))
- [ ] Should create a summary of the data to be imported e.g.
create_count: 32, update_count: 13, error_count: 2
which should be kept in the BatchJobresult
until completion. - [ ] Should report progress to the BatchJobService
- [ ] The default import format should support the same columns as the export format
View more from the discussion here
The required fields for a new product are:
- handle, title
- Other fields that have defaults if not provided:
- Status - draft
- Product Option 1 - Default Option
- Profile - Default Profile
- Discountable - true
The required fields for a new product variant are:
- If product has product option then Variant Option Value must be defined
- Other fields that have defaults if not provided:
- Title - concat of option values
- Allow Backorder - false
- Manage Inventory - true
- Variant Option Value 1 (if not defined on product) - Default Variant
Fixes CORE-413
DoD
- [ ] When
dry_run: true
ProductImportStrategy should first move BatchJob to anawaiting_confirmation
state before importing data.
// pre-confirmation.json
[
{ operation: "create", type: "product", data: { .... },
{ operation: "create", type: "product-variant", data: { ... }
]
// ON CONFIRM
await Promise.all(preconfirmops.map((op) => {
switch(op.operation)
case "create":
productService.create(op.data)
break
case "update":
productVariantService.update(op.existing_id, op.data)
}))
- [ ] Should create a summary of the data to be imported e.g.
create_count: 32, update_count: 13, error_count: 2
which should be kept in the BatchJobresult
until completion. - [ ] Should report progress to the BatchJobService
- [ ] The default import format should support the same columns as the export format
View more from the discussion here
The required fields for a new product are:
- handle, title
- Other fields that have defaults if not provided:
- Status - draft
- Product Option 1 - Default Option
- Profile - Default Profile
- Discountable - true
The required fields for a new product variant are:
- If product has product option then Variant Option Value must be defined
- Other fields that have defaults if not provided:
- Title - concat of option values
- Allow Backorder - false
- Manage Inventory - true
- Variant Option Value 1 (if not defined on product) - Default Variant