Adds default shipping profile

This commit is contained in:
olivermrbl
2020-07-02 18:04:33 +02:00
parent e4f75be5ca
commit 63a2f126c5
7 changed files with 48 additions and 11 deletions
@@ -43,6 +43,8 @@ export default async (req, res) => {
delete value.variants
const productService = req.scope.resolve("productService")
const shippingProfileService = req.scope.resolve("shippingProfileService")
let newProduct = await productService.createDraft(value)
if (variants) {
@@ -64,6 +66,10 @@ export default async (req, res) => {
)
}
// Add to default shipping profile
const { _id } = await shippingProfileService.retrieveDefault()
await shippingProfileService.addProduct(_id, newProduct._id)
newProduct = await productService.decorate(newProduct, [
"title",
"description",
@@ -27,10 +27,17 @@ export default async (req, res) => {
try {
const optionService = req.scope.resolve("shippingOptionService")
const shippingProfileService = req.scope.resolve("shippingProfileService")
const data = await optionService.create(value)
// Add to default shipping profile
const { _id } = await shippingProfileService.retrieveDefault()
await shippingProfileService.addProduct(_id, data._id)
res.status(200).json({ shipping_option: data })
} catch (err) {
console.log(err)
throw err
}
}