hotfix(medusa-plugin-add-on): Adds cart decorator to add-on plugin
This commit is contained in:
committed by
GitHub
parent
8d24f69829
commit
6b241a13de
1
packages/medusa-plugin-add-ons/.gitignore
vendored
1
packages/medusa-plugin-add-ons/.gitignore
vendored
@@ -11,4 +11,5 @@ node_modules
|
||||
/services
|
||||
/models
|
||||
/subscribers
|
||||
/loaders
|
||||
|
||||
|
||||
@@ -32,16 +32,6 @@ export default async (req, res) => {
|
||||
cart = await cartService.addLineItem(cart._id, lineItem)
|
||||
cart = await cartService.decorate(cart, [], ["region"])
|
||||
|
||||
cart.items = await Promise.all(
|
||||
cart.items.map((item) =>
|
||||
lineItemService.decorate(
|
||||
item,
|
||||
["title", "quantity", "thumbnail", "content", "should_merge"],
|
||||
["add_ons"]
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
res.status(200).json({ cart })
|
||||
} catch (err) {
|
||||
throw err
|
||||
|
||||
@@ -45,16 +45,6 @@ export default async (req, res) => {
|
||||
|
||||
cart = await cartService.decorate(cart, [], ["region"])
|
||||
|
||||
cart.items = await Promise.all(
|
||||
cart.items.map((item) =>
|
||||
lineItemService.decorate(
|
||||
item,
|
||||
["title", "quantity", "thumbnail", "content", "should_merge"],
|
||||
["add_ons"]
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
res.status(200).json({ cart })
|
||||
} catch (err) {
|
||||
throw err
|
||||
|
||||
26
packages/medusa-plugin-add-ons/src/loaders/decorator.js
Normal file
26
packages/medusa-plugin-add-ons/src/loaders/decorator.js
Normal file
@@ -0,0 +1,26 @@
|
||||
export default (container, config) => {
|
||||
const cartService = container.resolve("cartService")
|
||||
const addOnLineItemService = container.resolve("addOnLineItemService")
|
||||
|
||||
cartService.addDecorator(async (cart) => {
|
||||
try {
|
||||
cart.items = await Promise.all(
|
||||
cart.items.map((item) => {
|
||||
if (item.metadata && item.metadata.add_ons) {
|
||||
return addOnLineItemService.decorate(
|
||||
item,
|
||||
["title", "quantity", "thumbnail", "content", "should_merge"],
|
||||
["add_ons"]
|
||||
)
|
||||
} else {
|
||||
return item
|
||||
}
|
||||
})
|
||||
)
|
||||
|
||||
return cart
|
||||
} catch (error) {
|
||||
return cart
|
||||
}
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user