Commit 0d5dfbe 1 parent 04f5d1a commit 0d5dfbe Copy full SHA for 0d5dfbe
File tree 2 files changed +17
-3
lines changed
2 files changed +17
-3
lines changed Original file line number Diff line number Diff line change @@ -43,8 +43,16 @@ export default class StorageClient {
43
43
throw errorWithResponse ( 404 , 'Product not found' ) ;
44
44
}
45
45
46
- const productData = await object . text ( ) ;
47
- return JSON . parse ( productData ) ;
46
+ const productData = await object . json ( ) ;
47
+ productData . attributeMap = Object . fromEntries ( ( productData . attributes ?? [ ] )
48
+ . map ( ( { name, value } ) => [ name , value ] ) ) ;
49
+ productData . variants = productData . variants || [ ] ;
50
+ productData . variants . forEach ( ( variant ) => {
51
+ variant . attributeMap = Object . fromEntries ( ( variant . attributes ?? [ ] )
52
+ . map ( ( { name, value } ) => [ name , value ] ) ) ;
53
+ } ) ;
54
+
55
+ return productData ;
48
56
}
49
57
50
58
/**
Original file line number Diff line number Diff line change @@ -21,13 +21,19 @@ import htmlTemplateFromContext from '../templates/html/index.js';
21
21
export async function handle ( ctx ) {
22
22
const { config } = ctx ;
23
23
const { urlkey } = config . params ;
24
- const { sku } = config . params ;
24
+ let { sku } = config . params ;
25
25
26
26
if ( ! sku && ! urlkey ) {
27
27
return errorResponse ( 404 , 'missing sku or urlkey' ) ;
28
28
}
29
29
30
30
const storageClient = new StorageClient ( ctx , config ) ;
31
+ if ( ! sku ) {
32
+ sku = await storageClient . lookupSku ( urlkey ) ;
33
+ if ( ! sku ) {
34
+ return errorResponse ( 404 , 'could not find sku' ) ;
35
+ }
36
+ }
31
37
32
38
const product = await storageClient . fetchProduct ( sku ) ;
33
39
const html = htmlTemplateFromContext ( ctx , product , product . variants ) . render ( ) ;
You can’t perform that action at this time.
0 commit comments