hotfix(medusa-plugin-add-on): Adds cart decorator to add-on plugin
This commit is contained in:
1 parent
8d24f69829
commit
6b241a13de
4 files changed
+27
-20
No files matched your search
@@ -11,4 +11,5 @@ node_modules
|
|||||||
/services
|
/services
|
||||||
/models
|
/models
|
||||||
/subscribers
|
/subscribers
|
||||||
|
/loaders
|
||||||
|
|
||||||
@@ -32,16 +32,6 @@ export default async (req, res) => {
|
|||||||
cart = await cartService.addLineItem(cart._id, lineItem)
|
cart = await cartService.addLineItem(cart._id, lineItem)
|
||||||
cart = await cartService.decorate(cart, [], ["region"])
|
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 })
|
res.status(200).json({ cart })
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
throw err
|
throw err
|
||||||
|
|||||||
@@ -45,16 +45,6 @@ export default async (req, res) => {
|
|||||||
|
|
||||||
cart = await cartService.decorate(cart, [], ["region"])
|
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 })
|
res.status(200).json({ cart })
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
throw err
|
throw err
|
||||||
|
|||||||
@@ -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