Просмотр исходного кода

fix(core): Import localeString custom fields from csv

Fixes #1001
Michael Bromley 4 лет назад
Родитель
Сommit
d25ea26558

+ 4 - 0
packages/core/e2e/__snapshots__/import.e2e-spec.ts.snap

@@ -22,6 +22,7 @@ Object {
       "stretching",
       "watercolor",
     ],
+    "localName": "localPPS",
     "owner": Object {
       "id": "T_1",
     },
@@ -120,6 +121,7 @@ Object {
   "assets": Array [],
   "customFields": Object {
     "keywords": Array [],
+    "localName": "localMabef",
     "owner": Object {
       "id": "T_1",
     },
@@ -167,6 +169,7 @@ Object {
   "assets": Array [],
   "customFields": Object {
     "keywords": Array [],
+    "localName": "localGiotto",
     "owner": Object {
       "id": "T_1",
     },
@@ -261,6 +264,7 @@ Object {
       "apron",
       "clothing",
     ],
+    "localName": "localSmock",
     "owner": Object {
       "id": "T_1",
     },

+ 11 - 11
packages/core/e2e/fixtures/product-import.csv

@@ -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}",,

+ 12 - 1
packages/core/e2e/import.e2e-spec.ts

@@ -28,6 +28,10 @@ describe('Import resolver', () => {
                     type: 'string',
                     list: true,
                 },
+                {
+                    name: 'localName',
+                    type: 'localeString',
+                },
             ],
             ProductVariant: [{ type: 'int', name: 'weight' }],
         },
@@ -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);
@@ -122,6 +126,7 @@ describe('Import resolver', () => {
                                     id
                                 }
                                 keywords
+                                localName
                             }
                             variants {
                                 id
@@ -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);
 });

+ 7 - 4
packages/core/src/data-import/providers/importer/importer.ts

@@ -28,6 +28,7 @@ import { FastImporterService } from './fast-importer.service';
 export interface ImportProgress extends ImportInfo {
     currentProduct: string;
 }
+
 export type OnProgressFn = (progess: ImportProgress) => void;
 
 @Injectable()
@@ -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),
@@ -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 } = {};