feat(fulfillment, core-flows): Apply correct address and context + cleanup (#7230)

The tests will be added in subsequent requests where the worklows are being worked on
This commit is contained in:
Adrien de Peretti
2024-05-03 15:44:22 +00:00
committed by GitHub
parent 4fe28f5a95
commit 520867b074
3 changed files with 25 additions and 42 deletions
+6
View File
@@ -0,0 +1,6 @@
---
"@medusajs/fulfillment": patch
"@medusajs/core-flows": patch
---
feat(fulfillment, core-flows): Apply correct address and context + cleanup
@@ -46,7 +46,7 @@ export const listShippingOptionsForCartWorkflow = createWorkflow(
variables: {
id: input.sales_channel_id,
"stock_locations.fulfillment_sets.service_zones.shipping_options": {
context: {
filters: {
address: {
city: input.shipping_address?.city,
country_code: input.shipping_address?.country_code,
@@ -137,29 +137,6 @@ export default class FulfillmentModuleService<
return joinerConfig
}
private setupShippingOptionsConfig_(
filters,
config
):
| FulfillmentTypes.FilterableShippingOptionForContextProps["context"]
| undefined {
const fieldIdx = config.relations?.indexOf("shipping_options_context")
const shouldCalculatePrice = fieldIdx > -1
const shippingOptionsContext = filters.context ?? {}
delete filters.context
if (!shouldCalculatePrice) {
return
}
// cleanup virtual field "shipping_options_context"
config.relations?.splice(fieldIdx, 1)
return shippingOptionsContext
}
@InjectManager("baseRepository_")
// @ts-ignore
async listShippingOptions(
@@ -167,11 +144,9 @@ export default class FulfillmentModuleService<
config: FindConfig<FulfillmentTypes.ShippingOptionDTO> = {},
@MedusaContext() sharedContext: Context = {}
): Promise<FulfillmentTypes.ShippingOptionDTO[]> {
const optionsContext = this.setupShippingOptionsConfig_(filters, config)
if (optionsContext) {
filters.context = optionsContext
// Eventually, we could call normalizeListShippingOptionsForContextParams to translate the address and make a and condition with the other filters
// In that case we could remote the address check below
if (filters?.context || filters?.address) {
return await this.listShippingOptionsForContext(
filters,
config,
@@ -1698,6 +1673,7 @@ export default class FulfillmentModuleService<
const geoZoneConstraints =
FulfillmentModuleService.buildGeoZoneConstraintsFromAddress(address)
if (geoZoneConstraints.length) {
normalizedFilters = {
...normalizedFilters,
service_zone: {
@@ -1714,6 +1690,7 @@ export default class FulfillmentModuleService<
normalizedConfig.relations.push("service_zone.geo_zones")
}
}
normalizedConfig.relations = Array.from(new Set(normalizedConfig.relations))