Skip to content

Commit

Permalink
fix(core): Import localeString custom fields from csv
Browse files Browse the repository at this point in the history
Fixes #1001
  • Loading branch information
michaelbromley committed Jul 26, 2021
1 parent 02f9995 commit d25ea26
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 16 deletions.
4 changes: 4 additions & 0 deletions packages/core/e2e/__snapshots__/import.e2e-spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Object {
"stretching",
"watercolor",
],
"localName": "localPPS",
"owner": Object {
"id": "T_1",
},
Expand Down Expand Up @@ -120,6 +121,7 @@ Object {
"assets": Array [],
"customFields": Object {
"keywords": Array [],
"localName": "localMabef",
"owner": Object {
"id": "T_1",
},
Expand Down Expand Up @@ -167,6 +169,7 @@ Object {
"assets": Array [],
"customFields": Object {
"keywords": Array [],
"localName": "localGiotto",
"owner": Object {
"id": "T_1",
},
Expand Down Expand Up @@ -261,6 +264,7 @@ Object {
"apron",
"clothing",
],
"localName": "localSmock",
"owner": Object {
"id": "T_1",
},
Expand Down
22 changes: 11 additions & 11 deletions packages/core/e2e/fixtures/product-import.csv
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
name ,slug ,description ,assets ,facets ,optionGroups ,optionValues ,sku ,price,taxCategory,stockOnHand,trackInventory,variantAssets ,variantFacets ,product:pageType,variant:weight,product:owner,product:keywords
Perfect Paper Stretcher,perfect-paper-stretcher,A great device for stretching paper.,"pps1.jpg|pps2.jpg", ,size ,Half Imperial ,PPS12 ,45.3 ,standard ,0 ,false , ,Brand:KB|Type:Accessory,default ,100 ,"{""id"": 1}",paper|stretching|watercolor
, , , , , ,Quarter Imperial,PPS14 ,32.5 ,standard ,0 ,false , ,Brand:KB|Type:Accessory, ,100 ,"{""id"": 1}",
, , , , , ,Full Imperial ,PPSF ,59.5 ,standard ,-10 ,false , ,Brand:KB|Type:Accessory, ,100 ,"{""id"": 1}",
Mabef M/02 Studio Easel, ,Mabef description , , , , ,M02 ,910.7,standard ,100 ,false , ,Brand:Mabef|Type:Easel ,expanded ,300 ,"{""id"": 1}",
Giotto Mega Pencils , ,Really mega pencils , , ,box size ,Box of 8 ,225400,4.16 ,standard , ,false ,"box-of-8.jpg" ,Collection:Xmas Sale ,default ,200 ,"{""id"": 1}",
, , , , , ,Box of 12 ,225600,6.24 ,standard , ,false ,"box-of-12.jpg",Collection:Xmas Sale , ,200 ,"{""id"": 1}",
name ,slug ,description ,assets ,facets ,optionGroups ,optionValues ,sku ,price,taxCategory,stockOnHand,trackInventory,variantAssets ,variantFacets ,product:pageType,variant:weight,product:owner,product:keywords,product:localName
Perfect Paper Stretcher,perfect-paper-stretcher,A great device for stretching paper.,"pps1.jpg|pps2.jpg", ,size ,Half Imperial ,PPS12 ,45.3 ,standard ,0 ,false , ,Brand:KB|Type:Accessory,default ,100 ,"{""id"": 1}",paper|stretching|watercolor,localPPS
, , , , , ,Quarter Imperial,PPS14 ,32.5 ,standard ,0 ,false , ,Brand:KB|Type:Accessory, ,100 ,"{""id"": 1}",,
, , , , , ,Full Imperial ,PPSF ,59.5 ,standard ,-10 ,false , ,Brand:KB|Type:Accessory, ,100 ,"{""id"": 1}",,
Mabef M/02 Studio Easel, ,Mabef description , , , , ,M02 ,910.7,standard ,100 ,false , ,Brand:Mabef|Type:Easel ,expanded ,300 ,"{""id"": 1}",,localMabef
Giotto Mega Pencils , ,Really mega pencils , , ,box size ,Box of 8 ,225400,4.16 ,standard , ,false ,"box-of-8.jpg" ,Collection:Xmas Sale ,default ,200 ,"{""id"": 1}",,localGiotto
, , , , , ,Box of 12 ,225600,6.24 ,standard , ,false ,"box-of-12.jpg",Collection:Xmas Sale , ,200 ,"{""id"": 1}",,

Artists Smock , ,Keeps the paint off the clothes , ,Material:Denim|Collection:clothes,"size|colour","small|beige" ,10112 ,11.99,reduced , ,false , , ,default ,500 ,"{""id"": 1}",apron|clothing
, , , , , ,"large|beige" ,10113 ,11.99,reduced , ,false , , ,default ,500 ,"{""id"": 1}",
, , , , , ,"small|navy" ,10114 ,11.99,reduced , ,false , , ,default ,500 ,"{""id"": 1}",
, , , , , ,"large|navy" ,10115 ,11.99,reduced , ,false , , ,default ,500 ,"{""id"": 1}",
Artists Smock , ,Keeps the paint off the clothes , ,Material:Denim|Collection:clothes,"size|colour","small|beige" ,10112 ,11.99,reduced , ,false , , ,default ,500 ,"{""id"": 1}",apron|clothing,localSmock
, , , , , ,"large|beige" ,10113 ,11.99,reduced , ,false , , ,default ,500 ,"{""id"": 1}",,
, , , , , ,"small|navy" ,10114 ,11.99,reduced , ,false , , ,default ,500 ,"{""id"": 1}",,
, , , , , ,"large|navy" ,10115 ,11.99,reduced , ,false , , ,default ,500 ,"{""id"": 1}",,
13 changes: 12 additions & 1 deletion packages/core/e2e/import.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ describe('Import resolver', () => {
type: 'string',
list: true,
},
{
name: 'localName',
type: 'localeString',
},
],
ProductVariant: [{ type: 'int', name: 'weight' }],
},
Expand Down Expand Up @@ -76,7 +80,7 @@ describe('Import resolver', () => {
});

expect(result.importProducts.errors).toEqual([
'Invalid Record Length: header length is 18, got 1 on line 8',
'Invalid Record Length: header length is 19, got 1 on line 8',
]);
expect(result.importProducts.imported).toBe(4);
expect(result.importProducts.processed).toBe(4);
Expand Down Expand Up @@ -122,6 +126,7 @@ describe('Import resolver', () => {
id
}
keywords
localName
}
variants {
id
Expand Down Expand Up @@ -235,5 +240,11 @@ describe('Import resolver', () => {
expect(easel.customFields.keywords).toEqual([]);
expect(pencils.customFields.keywords).toEqual([]);
expect(smock.customFields.keywords).toEqual(['apron', 'clothing']);

// Import localeString custom fields
expect(paperStretcher.customFields.localName).toEqual('localPPS');
expect(easel.customFields.localName).toEqual('localMabef');
expect(pencils.customFields.localName).toEqual('localGiotto');
expect(smock.customFields.localName).toEqual('localSmock');
}, 20000);
});
11 changes: 7 additions & 4 deletions packages/core/src/data-import/providers/importer/importer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { FastImporterService } from './fast-importer.service';
export interface ImportProgress extends ImportInfo {
currentProduct: string;
}

export type OnProgressFn = (progess: ImportProgress) => void;

@Injectable()
Expand Down Expand Up @@ -149,6 +150,10 @@ export class Importer {
if (createProductAssets.errors.length) {
errors = errors.concat(createProductAssets.errors);
}
const customFields = this.processCustomFieldValues(
product.customFields,
this.configService.customFields.Product,
);
const createdProductId = await this.fastImporter.createProduct({
featuredAssetId: productAssets.length ? productAssets[0].id : undefined,
assetIds: productAssets.map(a => a.id),
Expand All @@ -159,12 +164,10 @@ export class Importer {
name: product.name,
description: product.description,
slug: product.slug,
customFields,
},
],
customFields: this.processCustomFieldValues(
product.customFields,
this.configService.customFields.Product,
),
customFields,
});

const optionsMap: { [optionName: string]: ID } = {};
Expand Down

0 comments on commit d25ea26

Please sign in to comment.