Skip to content

feat: Shipping methods integration #2847

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
May 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 93 additions & 0 deletions packages/api/src/__generated__/schema.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
interface GeoCoordinatesInput {
interface GeoCoordinates {
latitude: number
longitude: number
}

export interface PickupPointsInput {
country?: string
geoCoordinates?: GeoCoordinatesInput
postalCode?: string
country?: string | null
geoCoordinates?: GeoCoordinates | null
postalCode?: string | null
}

interface Address {
Expand Down
8 changes: 8 additions & 0 deletions packages/api/src/platforms/vtex/clients/search/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,14 @@ const POLICY_KEY = 'trade-policy'
const REGION_KEY = 'region-id'
const FUZZY_KEY = 'fuzzy'
const OPERATOR_KEY = 'operator'
const PICKUP_POINT_KEY = 'pickupPoint'

const EXTRA_FACETS_KEYS = new Set([
POLICY_KEY,
REGION_KEY,
FUZZY_KEY,
OPERATOR_KEY,
PICKUP_POINT_KEY,
])

export const isFacetBoolean = (
Expand Down Expand Up @@ -165,6 +167,8 @@ export const IntelligentSearch = (
) => {
const fuzzyFacet = facets.find(({ key }) => key === FUZZY_KEY) ?? null
const operatorFacet = facets.find(({ key }) => key === OPERATOR_KEY) ?? null
const pickupPointFacet =
facets.find(({ key }) => key === PICKUP_POINT_KEY) ?? null

if (fuzzyFacet && isFuzzyFacet(fuzzyFacet)) {
params.append(FUZZY_KEY, fuzzyFacet.value)
Expand All @@ -173,6 +177,10 @@ export const IntelligentSearch = (
if (operatorFacet && isOperatorFacet(operatorFacet)) {
params.append(OPERATOR_KEY, operatorFacet.value)
}

if (pickupPointFacet) {
params.append(PICKUP_POINT_KEY, `${account}_${pickupPointFacet.value}`)
}
}

const search = <T>({
Expand Down
18 changes: 18 additions & 0 deletions packages/api/src/platforms/vtex/resolvers/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type {
QuerySellersArgs,
QueryShippingArgs,
QueryUserOrderArgs,
QueryPickupPointsArgs,
} from '../../../__generated__/schema'
import { BadRequestError, ForbiddenError, NotFoundError } from '../../errors'
import type { CategoryTree } from '../clients/commerce/types/CategoryTree'
Expand Down Expand Up @@ -457,4 +458,21 @@ export const Query = {
paging: orders.paging,
}
},
pickupPoints: async (
_: unknown,
{ country, postalCode, geoCoordinates }: QueryPickupPointsArgs,
ctx: Context
) => {
const {
clients: { commerce },
} = ctx

const result = await commerce.checkout.pickupPoints({
country,
postalCode,
geoCoordinates,
})

return result
},
}
137 changes: 137 additions & 0 deletions packages/api/src/typeDefs/pickupPoints.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
type PickupPointAddress {
"""
Address id.
"""
addressId: String
"""
Address type.
"""
addressType: String
"""
Address city.
"""
city: String
"""
Address complement
"""
complement: String
"""
Address country.
"""
country: String
"""
Address geo coordinates.
"""
geoCoordinates: [Float]
"""
Inform whether the address is disposable.
"""
isDisposable: Boolean
"""
Address neighborhood.
"""
neighborhood: String
"""
Address number.
"""
number: String
"""
Address postal code.
"""
postalCode: String
"""
Address receiver name.
"""
receiverName: String
"""
Address reference.
"""
reference: String
"""
Address state.
"""
state: String
"""
Address street.
"""
street: String
}

type BusinessHour {
"""
Number that represents the day of the week.
"""
DayOfWeek: Int
"""
Business hour opening time.
"""
OpeningTime: String
"""
Business hour closing time.
"""
ClosingTime: String
}

type PickupPoint {
"""
Pickup point additional info.
"""
additionalInfo: String
"""
Pickup point address.
"""
address: PickupPointAddress
"""
Pickup point business hours.
"""
businessHours: BusinessHour
"""
Pickup point friendly name.
"""
friendlyName: String
"""
Pickup point id.
"""
id: String
}

type Item {
"""
Pickup point distance.
"""
distance: Float
"""
Pickup point.
"""
pickupPoint: PickupPoint
}

type Paging {
"""
Current page.
"""
page: Int
"""
Total number of pages.
"""
pages: Int
"""
Number of items per page.
"""
pageSize: Int
"""
Total number of items.
"""
total: Int
}

type PickupPoints {
"""
List of pickup points of the given location.
"""
items: [Item]
"""
Pagination details.
"""
paging: Paging
}
19 changes: 19 additions & 0 deletions packages/api/src/typeDefs/query.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,25 @@ type Query {
clientEmail: String
): UserOrderListMinimalResult
@cacheControl(scope: "public", sMaxAge: 120, staleWhileRevalidate: 3600)

"""
Returns a list of pickup points near to the given geo coordinates or postal code + country code.
"""
pickupPoints(
"""
Geo coordinates input.
"""
geoCoordinates: IStoreGeoCoordinates
"""
Postal code input.
"""
postalCode: String
"""
Country input.
"""
country: String
): PickupPoints
@cacheControl(scope: "public", sMaxAge: 120, staleWhileRevalidate: 3600)
}

"""
Expand Down
1 change: 1 addition & 0 deletions packages/api/test/integration/schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ const QUERIES = [
'productCount',
'userOrder',
'listUserOrders',
'pickupPoints',
]

const MUTATIONS = [
Expand Down
Loading