fix: add country code on preCartCreation
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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 => {
|
||||
|
||||
Reference in New Issue
Block a user