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:
@@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
"@medusajs/fulfillment": patch
|
||||||
|
"@medusajs/core-flows": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
feat(fulfillment, core-flows): Apply correct address and context + cleanup
|
||||||
+1
-1
@@ -46,7 +46,7 @@ export const listShippingOptionsForCartWorkflow = createWorkflow(
|
|||||||
variables: {
|
variables: {
|
||||||
id: input.sales_channel_id,
|
id: input.sales_channel_id,
|
||||||
"stock_locations.fulfillment_sets.service_zones.shipping_options": {
|
"stock_locations.fulfillment_sets.service_zones.shipping_options": {
|
||||||
context: {
|
filters: {
|
||||||
address: {
|
address: {
|
||||||
city: input.shipping_address?.city,
|
city: input.shipping_address?.city,
|
||||||
country_code: input.shipping_address?.country_code,
|
country_code: input.shipping_address?.country_code,
|
||||||
|
|||||||
@@ -137,29 +137,6 @@ export default class FulfillmentModuleService<
|
|||||||
return joinerConfig
|
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_")
|
@InjectManager("baseRepository_")
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
async listShippingOptions(
|
async listShippingOptions(
|
||||||
@@ -167,11 +144,9 @@ export default class FulfillmentModuleService<
|
|||||||
config: FindConfig<FulfillmentTypes.ShippingOptionDTO> = {},
|
config: FindConfig<FulfillmentTypes.ShippingOptionDTO> = {},
|
||||||
@MedusaContext() sharedContext: Context = {}
|
@MedusaContext() sharedContext: Context = {}
|
||||||
): Promise<FulfillmentTypes.ShippingOptionDTO[]> {
|
): Promise<FulfillmentTypes.ShippingOptionDTO[]> {
|
||||||
const optionsContext = this.setupShippingOptionsConfig_(filters, config)
|
// 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 (optionsContext) {
|
if (filters?.context || filters?.address) {
|
||||||
filters.context = optionsContext
|
|
||||||
|
|
||||||
return await this.listShippingOptionsForContext(
|
return await this.listShippingOptionsForContext(
|
||||||
filters,
|
filters,
|
||||||
config,
|
config,
|
||||||
@@ -1698,6 +1673,7 @@ export default class FulfillmentModuleService<
|
|||||||
const geoZoneConstraints =
|
const geoZoneConstraints =
|
||||||
FulfillmentModuleService.buildGeoZoneConstraintsFromAddress(address)
|
FulfillmentModuleService.buildGeoZoneConstraintsFromAddress(address)
|
||||||
|
|
||||||
|
if (geoZoneConstraints.length) {
|
||||||
normalizedFilters = {
|
normalizedFilters = {
|
||||||
...normalizedFilters,
|
...normalizedFilters,
|
||||||
service_zone: {
|
service_zone: {
|
||||||
@@ -1714,6 +1690,7 @@ export default class FulfillmentModuleService<
|
|||||||
|
|
||||||
normalizedConfig.relations.push("service_zone.geo_zones")
|
normalizedConfig.relations.push("service_zone.geo_zones")
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
normalizedConfig.relations = Array.from(new Set(normalizedConfig.relations))
|
normalizedConfig.relations = Array.from(new Set(normalizedConfig.relations))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user