fix(core-flows, dashboard): handling fulfillment rules (#11111)

**What**
- fix storing "true" | "false" strings from admin
- use strings instead of booleans for context filtering
This commit is contained in:
Frane Polić
2025-01-23 17:32:25 +01:00
committed by GitHub
parent b418fb129a
commit 6e5912612c
3 changed files with 53 additions and 46 deletions

View File

@@ -151,13 +151,13 @@ export function CreateShippingOptionsForm({
rules: [
{
// eslint-disable-next-line
value: isReturn ? '"true"' : '"false"',
value: isReturn ? "true" : "false",
attribute: "is_return",
operator: "eq",
},
{
// eslint-disable-next-line
value: data.enabled_in_store ? '"true"' : '"false"',
value: data.enabled_in_store ? "true" : "false",
attribute: "enabled_in_store",
operator: "eq",
},

View File

@@ -1,4 +1,4 @@
import { ShippingOptionPriceType } from "@medusajs/framework/utils"
import { isDefined, ShippingOptionPriceType } from "@medusajs/framework/utils"
import {
createWorkflow,
parallelize,
@@ -6,8 +6,8 @@ import {
WorkflowData,
WorkflowResponse,
} from "@medusajs/framework/workflows-sdk"
import {
CalculateShippingOptionPriceDTO,
import {
CalculateShippingOptionPriceDTO,
ListShippingOptionsForCartWithPricingWorkflowInput,
} from "@medusajs/types"
@@ -44,13 +44,13 @@ export const listShippingOptionsForCartWithPricingWorkflowId =
/**
* This workflow lists shipping options that can be used during checkout for a cart. It also retrieves the prices
* of these shipping options, including calculated prices that may be retrieved from third-party providers.
*
*
* This workflow is executed in other cart-related workflows, such as {@link addShippingMethodToCartWorkflow} to retrieve the
* price of the shipping method being added to the cart.
*
* You can use this workflow within your own customizations or custom workflows, allowing you to retrieve the shipping options of a cart and their prices
*
* You can use this workflow within your own customizations or custom workflows, allowing you to retrieve the shipping options of a cart and their prices
* in your custom flows.
*
*
* @example
* const { result } = await listShippingOptionsForCartWithPricingWorkflow(container)
* .run({
@@ -66,16 +66,14 @@ export const listShippingOptionsForCartWithPricingWorkflowId =
* ]
* }
* })
*
*
* @summary
*
*
* List a cart's shipping options with prices.
*/
export const listShippingOptionsForCartWithPricingWorkflow = createWorkflow(
listShippingOptionsForCartWithPricingWorkflowId,
(
input: WorkflowData<ListShippingOptionsForCartWithPricingWorkflowInput>
) => {
(input: WorkflowData<ListShippingOptionsForCartWithPricingWorkflowInput>) => {
const optionIds = transform({ input }, ({ input }) =>
(input.options ?? []).map(({ id }) => id)
)
@@ -141,8 +139,12 @@ export const listShippingOptionsForCartWithPricingWorkflow = createWorkflow(
{ input, cart, fulfillmentSetIds },
({ input, cart, fulfillmentSetIds }) => ({
context: {
is_return: input.is_return ?? false,
enabled_in_store: input.enabled_in_store ?? true,
is_return: input.is_return ? "true" : "false",
enabled_in_store: !isDefined(input.enabled_in_store)
? "true"
: input.enabled_in_store
? "true"
: "false",
},
filters: {

View File

@@ -8,23 +8,24 @@ import { useQueryGraphStep, validatePresenceOfStep } from "../../common"
import { useRemoteQueryStep } from "../../common/steps/use-remote-query"
import { cartFieldsForPricingContext } from "../utils/fields"
import { ListShippingOptionsForCartWorkflowInput } from "@medusajs/types"
import { isDefined } from "@medusajs/framework/utils"
export const listShippingOptionsForCartWorkflowId =
"list-shipping-options-for-cart"
/**
* This workflow lists the shipping options of a cart. It's executed by the
* This workflow lists the shipping options of a cart. It's executed by the
* [List Shipping Options Store API Route](https://docs.medusajs.com/api/store#shipping-options_getshippingoptions).
*
*
* :::note
*
*
* This workflow doesn't retrieve the calculated prices of the shipping options. If you need to retrieve the prices of the shipping options,
* use the {@link listShippingOptionsForCartWithPricingWorkflow} workflow.
*
*
* :::
*
* You can use this workflow within your own customizations or custom workflows, allowing you to wrap custom logic around to retrieve the shipping options of a cart
*
* You can use this workflow within your own customizations or custom workflows, allowing you to wrap custom logic around to retrieve the shipping options of a cart
* in your custom flows.
*
*
* @example
* const { result } = await listShippingOptionsForCartWorkflow(container)
* .run({
@@ -33,16 +34,14 @@ export const listShippingOptionsForCartWorkflowId =
* option_ids: ["so_123"]
* }
* })
*
*
* @summary
*
*
* List a cart's shipping options.
*/
export const listShippingOptionsForCartWorkflow = createWorkflow(
listShippingOptionsForCartWorkflowId,
(
input: WorkflowData<ListShippingOptionsForCartWorkflowInput>
) => {
(input: WorkflowData<ListShippingOptionsForCartWorkflowInput>) => {
const cartQuery = useQueryGraphStep({
entity: "cart",
filters: { id: input.cart_id },
@@ -92,27 +91,33 @@ export const listShippingOptionsForCartWorkflow = createWorkflow(
const queryVariables = transform(
{ input, fulfillmentSetIds, cart },
({ input, fulfillmentSetIds, cart }) => ({
id: input.option_ids,
({ input, fulfillmentSetIds, cart }) => {
return {
id: input.option_ids,
context: {
is_return: input.is_return ?? false,
enabled_in_store: input.enabled_in_store ?? true,
},
filters: {
fulfillment_set_id: fulfillmentSetIds,
address: {
country_code: cart.shipping_address?.country_code,
province_code: cart.shipping_address?.province,
city: cart.shipping_address?.city,
postal_expression: cart.shipping_address?.postal_code,
context: {
is_return: input.is_return ? "true" : "false",
enabled_in_store: !isDefined(input.enabled_in_store)
? "true"
: input.enabled_in_store
? "true"
: "false",
},
},
calculated_price: { context: cart },
})
filters: {
fulfillment_set_id: fulfillmentSetIds,
address: {
country_code: cart.shipping_address?.country_code,
province_code: cart.shipping_address?.province,
city: cart.shipping_address?.city,
postal_expression: cart.shipping_address?.postal_code,
},
},
calculated_price: { context: cart },
}
}
)
const shippingOptions = useRemoteQueryStep({