fix: add country code on preCartCreation

This commit is contained in:
Sebastian Rindom
2020-11-02 12:32:45 +01:00
parent a57c58e07e
commit e3faa646a7
2 changed files with 11 additions and 2 deletions

View File

@@ -26,6 +26,7 @@ export default {
// If this region exists, add it to the body of the cart creation request
if (regions[0]) {
req.body.region_id = regions[0]._id.toString()
req.body.country_code = data.country_code
}
next()

View File

@@ -3,6 +3,7 @@ import { Validator, MedusaError } from "medusa-core-utils"
export default async (req, res) => {
const schema = Validator.object().keys({
region_id: Validator.string(),
country_code: Validator.string().optional(),
items: Validator.array()
.items({
variant_id: Validator.string().required(),
@@ -37,12 +38,19 @@ export default async (req, res) => {
email = customer.email
}
let cart = await cartService.create({
const toCreate = {
region_id: regionId,
customer_id: customerId,
email,
})
}
if (value.country_code) {
toCreate.shipping_address = {
country_code: value.country_code.toUpperCase(),
}
}
let cart = await cartService.create(toCreate)
if (value.items) {
await Promise.all(
value.items.map(async i => {