Skip to content

Commit

Permalink
add postalcode to the itemswithsimulation
Browse files Browse the repository at this point in the history
  • Loading branch information
hiagolcm committed Sep 12, 2024
1 parent ad93c65 commit 39c2b3f
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
1 change: 1 addition & 0 deletions graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,7 @@ type Query {
items: [ItemInput]
regionId: String
salesChannel: String
postalCode: String
): [SKU] @cacheControl(scope: SEGMENT, maxAge: SHORT) @withSegment
}

Expand Down
8 changes: 7 additions & 1 deletion node/resolvers/checkout/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -383,10 +383,12 @@ export const queries: Record<string, Resolver> = {
items,
regionId,
salesChannel,
postalCode,
}: {
items: ItemWithSimulationInput[]
regionId?: string
salesChannel?: string
postalCode?: string
},
ctx: Context
) => {
Expand All @@ -399,14 +401,18 @@ export const queries: Record<string, Resolver> = {
ctx.vtex.account
)

const countryCode = ctx.vtex.segment?.countryCode

return items.map((item) => {
// eslint-disable-next-line no-async-promise-executor
return new Promise(async (resolve) => {
const simulationPayloads = getSimulationPayloadsByItem(
item,
segment,
regionId,
changeSeller
changeSeller,
postalCode,
countryCode
)

const simulationPromises = simulationPayloads.map((payload) =>
Expand Down
2 changes: 2 additions & 0 deletions node/typings/Checkout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,8 @@ interface PayloadItem {
seller: string
parentItemIndex?: number | null
parentAssemblyBinding?: string | null
country?: string
postalCode?: string
}

interface SimulationPayload {
Expand Down
15 changes: 12 additions & 3 deletions node/utils/simulation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ export const getSimulationPayloadsByItem = (
item: ItemWithSimulationInput,
segment?: SegmentData,
regionId?: string,
useSellerFromRegion?: boolean
useSellerFromRegion?: boolean,
postalCode?: string,
countryCode?: string
) => {
const payloadItems = item.sellers.map((seller) => {
let sellerFromRegion = null
Expand All @@ -74,11 +76,18 @@ export const getSimulationPayloadsByItem = (
}
}

return {
const payLoad: PayloadItem = {
id: item.itemId,
quantity: 1,
seller: sellerFromRegion || seller.sellerId,
} as PayloadItem
}

if (countryCode && postalCode) {
payLoad.country = countryCode
payLoad.postalCode = postalCode
}

return payLoad
})

return payloadItems.map((payloadItem) => {
Expand Down

0 comments on commit 39c2b3f

Please sign in to comment.