Merge branch 'master' of github.com:medusajs/medusa
This commit is contained in:
commit
0c0177799a
6 files changed
+36
-21
No files matched your search
@@ -11,4 +11,5 @@ node_modules
|
|||||||
/services
|
/services
|
||||||
/models
|
/models
|
||||||
/subscribers
|
/subscribers
|
||||||
|
/loaders
|
||||||
|
|
||||||
@@ -3,6 +3,14 @@
|
|||||||
All notable changes to this project will be documented in this file.
|
All notable changes to this project will be documented in this file.
|
||||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||||
|
|
||||||
|
## [1.0.4](https://github.com/medusajs/medusa/compare/medusa-plugin-add-ons@1.0.3...medusa-plugin-add-ons@1.0.4) (2020-10-09)
|
||||||
|
|
||||||
|
**Note:** Version bump only for package medusa-plugin-add-ons
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## [1.0.3](https://github.com/medusajs/medusa/compare/medusa-plugin-add-ons@1.0.2...medusa-plugin-add-ons@1.0.3) (2020-10-05)
|
## [1.0.3](https://github.com/medusajs/medusa/compare/medusa-plugin-add-ons@1.0.2...medusa-plugin-add-ons@1.0.3) (2020-10-05)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "medusa-plugin-add-ons",
|
"name": "medusa-plugin-add-ons",
|
||||||
"version": "1.0.3",
|
"version": "1.0.4",
|
||||||
"description": "Add-on plugin for Medusa Commerce",
|
"description": "Add-on plugin for Medusa Commerce",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"repository": {
|
"repository": {
|
||||||
|
|||||||
@@ -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