fix: adds transform medusa ids (#385)
This commit is contained in:
@@ -174,7 +174,7 @@ class ContentfulService extends BaseService {
|
|||||||
"en-US": variantLinks,
|
"en-US": variantLinks,
|
||||||
},
|
},
|
||||||
[this.getCustomField("options", "product")]: {
|
[this.getCustomField("options", "product")]: {
|
||||||
"en-US": p.options,
|
"en-US": this.transformMedusaIds(p.options),
|
||||||
},
|
},
|
||||||
[this.getCustomField("medusaId", "product")]: {
|
[this.getCustomField("medusaId", "product")]: {
|
||||||
"en-US": p.id,
|
"en-US": p.id,
|
||||||
@@ -285,10 +285,10 @@ class ContentfulService extends BaseService {
|
|||||||
"en-US": v.sku,
|
"en-US": v.sku,
|
||||||
},
|
},
|
||||||
[this.getCustomField("prices", "variant")]: {
|
[this.getCustomField("prices", "variant")]: {
|
||||||
"en-US": v.prices,
|
"en-US": this.transformMedusaIds(v.prices),
|
||||||
},
|
},
|
||||||
[this.getCustomField("options", "variant")]: {
|
[this.getCustomField("options", "variant")]: {
|
||||||
"en-US": v.options,
|
"en-US": this.transformMedusaIds(v.options),
|
||||||
},
|
},
|
||||||
[this.getCustomField("medusaId", "variant")]: {
|
[this.getCustomField("medusaId", "variant")]: {
|
||||||
"en-US": v.id,
|
"en-US": v.id,
|
||||||
@@ -476,7 +476,7 @@ class ContentfulService extends BaseService {
|
|||||||
"en-US": p.description,
|
"en-US": p.description,
|
||||||
},
|
},
|
||||||
[this.getCustomField("options", "product")]: {
|
[this.getCustomField("options", "product")]: {
|
||||||
"en-US": p.options,
|
"en-US": this.transformMedusaIds(p.options),
|
||||||
},
|
},
|
||||||
[this.getCustomField("variants", "product")]: {
|
[this.getCustomField("variants", "product")]: {
|
||||||
"en-US": variantLinks,
|
"en-US": variantLinks,
|
||||||
@@ -538,9 +538,8 @@ class ContentfulService extends BaseService {
|
|||||||
"en-US": p.collection.title,
|
"en-US": p.collection.title,
|
||||||
}
|
}
|
||||||
|
|
||||||
productEntryFields[
|
productEntryFields[this.getCustomField("collection", "product")] =
|
||||||
this.getCustomField("collection", "product")
|
collection
|
||||||
] = collection
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (p.tags) {
|
if (p.tags) {
|
||||||
@@ -624,10 +623,10 @@ class ContentfulService extends BaseService {
|
|||||||
"en-US": v.sku,
|
"en-US": v.sku,
|
||||||
},
|
},
|
||||||
[this.getCustomField("options", "variant")]: {
|
[this.getCustomField("options", "variant")]: {
|
||||||
"en-US": v.options,
|
"en-US": this.transformMedusaIds(v.options),
|
||||||
},
|
},
|
||||||
[this.getCustomField("prices", "variant")]: {
|
[this.getCustomField("prices", "variant")]: {
|
||||||
"en-US": v.prices,
|
"en-US": this.transformMedusaIds(v.prices),
|
||||||
},
|
},
|
||||||
[this.getCustomField("medusaId", "variant")]: {
|
[this.getCustomField("medusaId", "variant")]: {
|
||||||
"en-US": v.id,
|
"en-US": v.id,
|
||||||
@@ -734,6 +733,28 @@ class ContentfulService extends BaseService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
transformMedusaIds(objOrArray) {
|
||||||
|
let input = objOrArray
|
||||||
|
let isArray = true
|
||||||
|
if (!Array.isArray(objOrArray)) {
|
||||||
|
input = [objOrArray]
|
||||||
|
isArray = false
|
||||||
|
}
|
||||||
|
|
||||||
|
let output = []
|
||||||
|
for (const obj of input) {
|
||||||
|
let transformed = Object.assign({}, objOrArray)
|
||||||
|
transformed.medusaId = output.id
|
||||||
|
output.push(transformed)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isArray) {
|
||||||
|
return output[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
return output
|
||||||
|
}
|
||||||
|
|
||||||
async getType(type) {
|
async getType(type) {
|
||||||
const environment = await this.getContentfulEnvironment_()
|
const environment = await this.getContentfulEnvironment_()
|
||||||
return environment.getContentType(type)
|
return environment.getContentType(type)
|
||||||
|
|||||||
Reference in New Issue
Block a user