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:
Philip Korsholm
2023-05-18 10:12:34 +02:00
committed by GitHub
parent e73c3e51c9
commit eba21d9c5f
2 changed files with 35 additions and 2 deletions

View File

@@ -0,0 +1,5 @@
---
"medusa-plugin-contentful": patch
---
feat(medusa-plugin-contentful): include sku from inventory module when syncing variants and products

View File

@@ -12,6 +12,8 @@ class ContentfulService extends BaseService {
cacheService,
productVariantService,
eventBusService,
productVariantInventoryService,
featureFlagRouter,
},
options
) {
@@ -33,6 +35,10 @@ class ContentfulService extends BaseService {
this.cacheService_ = cacheService
this.productVariantInventoryService_ = productVariantInventoryService
this.featureFlagRouter_ = featureFlagRouter
this.capab_ = {}
}
@@ -234,6 +240,17 @@ class ContentfulService extends BaseService {
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 result = await environment.createEntryWithId("productVariant", v.id, {
fields: {
@@ -241,7 +258,7 @@ class ContentfulService extends BaseService {
"en-US": v.title,
},
[this.getCustomField("sku", "variant")]: {
"en-US": v.sku,
"en-US": sku,
},
[this.getCustomField("prices", "variant")]: {
"en-US": this.transformMedusaIds(v.prices),
@@ -698,13 +715,24 @@ class ContentfulService extends BaseService {
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 = {
...variantEntry.fields,
[this.getCustomField("title", "variant")]: {
"en-US": v.title,
},
[this.getCustomField("sku", "variant")]: {
"en-US": v.sku,
"en-US": sku,
},
[this.getCustomField("options", "variant")]: {
"en-US": this.transformMedusaIds(v.options),