diff --git a/packages/medusa-plugin-ip-lookup/src/api/medusa-middleware.js b/packages/medusa-plugin-ip-lookup/src/api/medusa-middleware.js index 4a26b1ee56..a602b678bf 100644 --- a/packages/medusa-plugin-ip-lookup/src/api/medusa-middleware.js +++ b/packages/medusa-plugin-ip-lookup/src/api/medusa-middleware.js @@ -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() diff --git a/packages/medusa/src/api/routes/store/carts/create-cart.js b/packages/medusa/src/api/routes/store/carts/create-cart.js index faced103d9..de1db2682c 100644 --- a/packages/medusa/src/api/routes/store/carts/create-cart.js +++ b/packages/medusa/src/api/routes/store/carts/create-cart.js @@ -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 => {