Bläddra i källkod

feat(server): Create assets based on variantAssets column when importing

Michael Bromley 7 år sedan
förälder
incheckning
45a6996b88

+ 36 - 0
server/e2e/__snapshots__/import.e2e-spec.ts.snap

@@ -30,6 +30,8 @@ Array [
     "slug": "perfect-paper-stretcher",
     "variants": Array [
       Object {
+        "assets": Array [],
+        "featuredAsset": null,
         "id": "T_1",
         "name": "Perfect Paper Stretcher Half Imperial",
         "options": Array [
@@ -46,6 +48,8 @@ Array [
         },
       },
       Object {
+        "assets": Array [],
+        "featuredAsset": null,
         "id": "T_2",
         "name": "Perfect Paper Stretcher Quarter Imperial",
         "options": Array [
@@ -62,6 +66,8 @@ Array [
         },
       },
       Object {
+        "assets": Array [],
+        "featuredAsset": null,
         "id": "T_3",
         "name": "Perfect Paper Stretcher Full Imperial",
         "options": Array [
@@ -89,6 +95,8 @@ Array [
     "slug": "mabef-m02-studio-easel",
     "variants": Array [
       Object {
+        "assets": Array [],
+        "featuredAsset": null,
         "id": "T_4",
         "name": "Mabef M/02 Studio Easel",
         "options": Array [],
@@ -117,6 +125,16 @@ Array [
     "slug": "giotto-mega-pencils",
     "variants": Array [
       Object {
+        "assets": Array [
+          Object {
+            "id": "T_8",
+            "name": "box-of-8.jpg",
+          },
+        ],
+        "featuredAsset": Object {
+          "id": "T_8",
+          "name": "box-of-8.jpg",
+        },
         "id": "T_5",
         "name": "Giotto Mega Pencils Box of 8",
         "options": Array [
@@ -133,6 +151,16 @@ Array [
         },
       },
       Object {
+        "assets": Array [
+          Object {
+            "id": "T_9",
+            "name": "box-of-12.jpg",
+          },
+        ],
+        "featuredAsset": Object {
+          "id": "T_9",
+          "name": "box-of-12.jpg",
+        },
         "id": "T_6",
         "name": "Giotto Mega Pencils Box of 12",
         "options": Array [
@@ -171,6 +199,8 @@ Array [
     "slug": "artists-smock",
     "variants": Array [
       Object {
+        "assets": Array [],
+        "featuredAsset": null,
         "id": "T_7",
         "name": "Artists Smock small beige",
         "options": Array [
@@ -195,6 +225,8 @@ Array [
         },
       },
       Object {
+        "assets": Array [],
+        "featuredAsset": null,
         "id": "T_8",
         "name": "Artists Smock large beige",
         "options": Array [
@@ -219,6 +251,8 @@ Array [
         },
       },
       Object {
+        "assets": Array [],
+        "featuredAsset": null,
         "id": "T_9",
         "name": "Artists Smock small navy",
         "options": Array [
@@ -243,6 +277,8 @@ Array [
         },
       },
       Object {
+        "assets": Array [],
+        "featuredAsset": null,
         "id": "T_10",
         "name": "Artists Smock large navy",
         "options": Array [

BIN
server/e2e/fixtures/box-of-12.jpg


BIN
server/e2e/fixtures/box-of-8.jpg


+ 2 - 2
server/e2e/fixtures/product-import.csv

@@ -3,8 +3,8 @@ Perfect Paper Stretcher , perfect-paper-stretcher , A great device for stretchin
                         ,                         ,                                      ,                      ,                , Quarter Imperial , PPS14  , 32.5  , standard    ,
                         ,                         ,                                      ,                      ,                , Full Imperial    , PPSF   , 59.5  , standard    ,
 Mabef M/02 Studio Easel ,                         , Mabef description                    ,                      ,                ,                  , M02    , 910.7 , standard    ,
-Giotto Mega Pencils     ,                         , Really mega pencils                  ,                      , box size       , Box of 8         , 225400 , 4.16  , standard    ,
-                        ,                         ,                                      ,                      ,                , Box of 12        , 225600 , 6.24  , standard    ,
+Giotto Mega Pencils     ,                         , Really mega pencils                  ,                      , box size       , Box of 8         , 225400 , 4.16  , standard    , "box-of-8.jpg"
+                        ,                         ,                                      ,                      ,                , Box of 12        , 225600 , 6.24  , standard    , "box-of-12.jpg"
 Artists Smock           ,                         , Keeps the paint off the clothes      ,                      , "size, colour" , "small, beige"   , 10112  , 11.99 , reduced     ,
                         ,                         ,                                      ,                      ,                , "large, beige"   , 10113  , 11.99 , reduced     ,
                         ,                         ,                                      ,                      ,                , "small, navy"    , 10114  , 11.99 , reduced     ,

+ 8 - 0
server/e2e/import.e2e-spec.ts

@@ -77,6 +77,14 @@ describe('Import resolver', () => {
                                     id
                                     code
                                 }
+                                assets {
+                                    id
+                                    name
+                                }
+                                featuredAsset {
+                                    id
+                                    name
+                                }
                             }
                         }
                     }

+ 3 - 1
server/src/data-import/providers/importer/importer.ts

@@ -127,8 +127,10 @@ export class Importer {
             }
 
             for (const variant of variants) {
-                // TODO: implement Assets for ProductVariants
+                const variantAssets = await this.createAssets(variant.assetPaths);
                 await this.productVariantService.create(ctx, createdProduct, {
+                    featuredAssetId: variantAssets.length ? (variantAssets[0].id as string) : undefined,
+                    assetIds: variantAssets.map(a => a.id) as string[],
                     sku: variant.sku,
                     taxCategoryId: this.getMatchingTaxCategoryId(variant.taxCategory, taxCategories),
                     optionCodes: variant.optionValues.map(v => normalizeString(v, '-')),