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 this region exists, add it to the body of the cart creation request
|
||||||
if (regions[0]) {
|
if (regions[0]) {
|
||||||
req.body.region_id = regions[0]._id.toString()
|
req.body.region_id = regions[0]._id.toString()
|
||||||
|
req.body.country_code = data.country_code
|
||||||
}
|
}
|
||||||
|
|
||||||
next()
|
next()
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { Validator, MedusaError } from "medusa-core-utils"
|
|||||||
export default async (req, res) => {
|
export default async (req, res) => {
|
||||||
const schema = Validator.object().keys({
|
const schema = Validator.object().keys({
|
||||||
region_id: Validator.string(),
|
region_id: Validator.string(),
|
||||||
|
country_code: Validator.string().optional(),
|
||||||
items: Validator.array()
|
items: Validator.array()
|
||||||
.items({
|
.items({
|
||||||
variant_id: Validator.string().required(),
|
variant_id: Validator.string().required(),
|
||||||
@@ -37,12 +38,19 @@ export default async (req, res) => {
|
|||||||
email = customer.email
|
email = customer.email
|
||||||
}
|
}
|
||||||
|
|
||||||
let cart = await cartService.create({
|
const toCreate = {
|
||||||
region_id: regionId,
|
region_id: regionId,
|
||||||
customer_id: customerId,
|
customer_id: customerId,
|
||||||
email,
|
email,
|
||||||
})
|
}
|
||||||
|
|
||||||
|
if (value.country_code) {
|
||||||
|
toCreate.shipping_address = {
|
||||||
|
country_code: value.country_code.toUpperCase(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let cart = await cartService.create(toCreate)
|
||||||
if (value.items) {
|
if (value.items) {
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
value.items.map(async i => {
|
value.items.map(async i => {
|
||||||
|
|||||||
Reference in New Issue
Block a user