feat(medusa-plugin-contentful): Initial implementation of inventory module (#3991)
* cleanup contentful plugin * initial implementation of inventory module in contentful --------- Co-authored-by: olivermrbl <oliver@mrbltech.com>
This commit is contained in:
co-authored by
olivermrbl
parent
e73c3e51c9
commit
eba21d9c5f
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"medusa-plugin-contentful": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
feat(medusa-plugin-contentful): include sku from inventory module when syncing variants and products
|
||||||
@@ -12,6 +12,8 @@ class ContentfulService extends BaseService {
|
|||||||
cacheService,
|
cacheService,
|
||||||
productVariantService,
|
productVariantService,
|
||||||
eventBusService,
|
eventBusService,
|
||||||
|
productVariantInventoryService,
|
||||||
|
featureFlagRouter,
|
||||||
},
|
},
|
||||||
options
|
options
|
||||||
) {
|
) {
|
||||||
@@ -33,6 +35,10 @@ class ContentfulService extends BaseService {
|
|||||||
|
|
||||||
this.cacheService_ = cacheService
|
this.cacheService_ = cacheService
|
||||||
|
|
||||||
|
this.productVariantInventoryService_ = productVariantInventoryService
|
||||||
|
|
||||||
|
this.featureFlagRouter_ = featureFlagRouter
|
||||||
|
|
||||||
this.capab_ = {}
|
this.capab_ = {}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -234,6 +240,17 @@ class ContentfulService extends BaseService {
|
|||||||
relations: ["prices", "options"],
|
relations: ["prices", "options"],
|
||||||
})
|
})
|
||||||
|
|
||||||
|
let sku = v.sku
|
||||||
|
if (this.featureFlagRouter_.isFeatureEnabled("inventoryService")) {
|
||||||
|
const [inventoryItem] =
|
||||||
|
await this.productVariantInventoryService_.listInventoryItemsByVariant(
|
||||||
|
v.id
|
||||||
|
)
|
||||||
|
if (inventoryItem) {
|
||||||
|
sku = inventoryItem.sku
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const environment = await this.getContentfulEnvironment_()
|
const environment = await this.getContentfulEnvironment_()
|
||||||
const result = await environment.createEntryWithId("productVariant", v.id, {
|
const result = await environment.createEntryWithId("productVariant", v.id, {
|
||||||
fields: {
|
fields: {
|
||||||
@@ -241,7 +258,7 @@ class ContentfulService extends BaseService {
|
|||||||
"en-US": v.title,
|
"en-US": v.title,
|
||||||
},
|
},
|
||||||
[this.getCustomField("sku", "variant")]: {
|
[this.getCustomField("sku", "variant")]: {
|
||||||
"en-US": v.sku,
|
"en-US": sku,
|
||||||
},
|
},
|
||||||
[this.getCustomField("prices", "variant")]: {
|
[this.getCustomField("prices", "variant")]: {
|
||||||
"en-US": this.transformMedusaIds(v.prices),
|
"en-US": this.transformMedusaIds(v.prices),
|
||||||
@@ -698,13 +715,24 @@ class ContentfulService extends BaseService {
|
|||||||
relations: ["prices", "options"],
|
relations: ["prices", "options"],
|
||||||
})
|
})
|
||||||
|
|
||||||
|
let sku = v.sku
|
||||||
|
if (this.featureFlagRouter_.isFeatureEnabled("inventoryService")) {
|
||||||
|
const [inventoryItem] =
|
||||||
|
await this.productVariantInventoryService_.listInventoryItemsByVariant(
|
||||||
|
v.id
|
||||||
|
)
|
||||||
|
if (inventoryItem) {
|
||||||
|
sku = inventoryItem.sku
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const variantEntryFields = {
|
const variantEntryFields = {
|
||||||
...variantEntry.fields,
|
...variantEntry.fields,
|
||||||
[this.getCustomField("title", "variant")]: {
|
[this.getCustomField("title", "variant")]: {
|
||||||
"en-US": v.title,
|
"en-US": v.title,
|
||||||
},
|
},
|
||||||
[this.getCustomField("sku", "variant")]: {
|
[this.getCustomField("sku", "variant")]: {
|
||||||
"en-US": v.sku,
|
"en-US": sku,
|
||||||
},
|
},
|
||||||
[this.getCustomField("options", "variant")]: {
|
[this.getCustomField("options", "variant")]: {
|
||||||
"en-US": this.transformMedusaIds(v.options),
|
"en-US": this.transformMedusaIds(v.options),
|
||||||
|
|||||||
Reference in New Issue
Block a user