@@ -57,25 +57,30 @@ export async function handleProductSaveRequest(ctx, config, request) {
57
57
const product = await putProduct ( ctx , config , requestBody ) ;
58
58
const products = [ product ] ;
59
59
60
- const { base : _ , ...otherPatterns } = config . confEnvMap [ config . env ] ;
60
+ const { base : _ = undefined , ...otherPatterns } = ( config . env in config . confEnvMap )
61
+ ? config . confEnvMap [ config . env ]
62
+ : { } ;
61
63
const matchedPathPatterns = Object . keys ( otherPatterns ) ;
62
64
63
- for ( const purgeProduct of products ) {
64
- for ( const pattern of matchedPathPatterns ) {
65
- let path = pattern . replace ( '{{sku}}' , purgeProduct . sku ) ;
65
+ if ( matchedPathPatterns . length !== 0 ) {
66
+ for ( const purgeProduct of products ) {
67
+ for ( const pattern of matchedPathPatterns ) {
68
+ let path = pattern . replace ( '{{sku}}' , purgeProduct . sku ) ;
66
69
67
- if ( path . includes ( '{{urlkey}}' ) && purgeProduct . urlKey ) {
68
- path = path . replace ( '{{urlkey}}' , purgeProduct . urlKey ) ;
69
- }
70
+ if ( path . includes ( '{{urlkey}}' ) && purgeProduct . urlKey ) {
71
+ path = path . replace ( '{{urlkey}}' , purgeProduct . urlKey ) ;
72
+ }
70
73
71
- for ( const op of [ 'preview' , 'live' ] ) {
72
- const response = await callAdmin ( config , op , path , { method : 'post' } ) ;
73
- if ( ! response . ok ) {
74
- return errorResponse ( 400 , `failed to ${ op } product` ) ;
74
+ for ( const op of [ 'preview' , 'live' ] ) {
75
+ const response = await callAdmin ( config , op , path , { method : 'post' } ) ;
76
+ if ( ! response . ok ) {
77
+ return errorResponse ( 400 , `failed to ${ op } product` ) ;
78
+ }
75
79
}
76
80
}
77
81
}
78
82
}
83
+
79
84
return new Response ( undefined , { status : 201 } ) ;
80
85
} catch ( e ) {
81
86
if ( e . response ) {
0 commit comments