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ć authored and GitHub committed 2025-01-23 16:32:25 +00:00
1 parent b418fb129a
commit 6e5912612c
3 files changed
+53 -46

No files matched your search

@@ -151,13 +151,13 @@ export function CreateShippingOptionsForm({
rules: [ rules: [
{ {
// eslint-disable-next-line // eslint-disable-next-line
value: isReturn ? '"true"' : '"false"', value: isReturn ? "true" : "false",
attribute: "is_return", attribute: "is_return",
operator: "eq", operator: "eq",
}, },
{ {
// eslint-disable-next-line // eslint-disable-next-line
value: data.enabled_in_store ? '"true"' : '"false"', value: data.enabled_in_store ? "true" : "false",
attribute: "enabled_in_store", attribute: "enabled_in_store",
operator: "eq", operator: "eq",
}, },
@@ -1,4 +1,4 @@
import { ShippingOptionPriceType } from "@medusajs/framework/utils" import { isDefined, ShippingOptionPriceType } from "@medusajs/framework/utils"
import { import {
createWorkflow, createWorkflow,
parallelize, parallelize,
@@ -6,8 +6,8 @@ import {
WorkflowData, WorkflowData,
WorkflowResponse, WorkflowResponse,
} from "@medusajs/framework/workflows-sdk" } from "@medusajs/framework/workflows-sdk"
import { import {
CalculateShippingOptionPriceDTO, CalculateShippingOptionPriceDTO,
ListShippingOptionsForCartWithPricingWorkflowInput, ListShippingOptionsForCartWithPricingWorkflowInput,
} from "@medusajs/types" } 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 * 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. * 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 * 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. * 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. * in your custom flows.
* *
* @example * @example
* const { result } = await listShippingOptionsForCartWithPricingWorkflow(container) * const { result } = await listShippingOptionsForCartWithPricingWorkflow(container)
* .run({ * .run({
@@ -66,16 +66,14 @@ export const listShippingOptionsForCartWithPricingWorkflowId =
* ] * ]
* } * }
* }) * })
* *
* @summary * @summary
* *
* List a cart's shipping options with prices. * List a cart's shipping options with prices.
*/ */
export const listShippingOptionsForCartWithPricingWorkflow = createWorkflow( export const listShippingOptionsForCartWithPricingWorkflow = createWorkflow(
listShippingOptionsForCartWithPricingWorkflowId, listShippingOptionsForCartWithPricingWorkflowId,
( (input: WorkflowData<ListShippingOptionsForCartWithPricingWorkflowInput>) => {
input: WorkflowData<ListShippingOptionsForCartWithPricingWorkflowInput>
) => {
const optionIds = transform({ input }, ({ input }) => const optionIds = transform({ input }, ({ input }) =>
(input.options ?? []).map(({ id }) => id) (input.options ?? []).map(({ id }) => id)
) )
@@ -141,8 +139,12 @@ export const listShippingOptionsForCartWithPricingWorkflow = createWorkflow(
{ input, cart, fulfillmentSetIds }, { input, cart, fulfillmentSetIds },
({ input, cart, fulfillmentSetIds }) => ({ ({ input, cart, fulfillmentSetIds }) => ({
context: { context: {
is_return: input.is_return ?? false, is_return: input.is_return ? "true" : "false",
enabled_in_store: input.enabled_in_store ?? true, enabled_in_store: !isDefined(input.enabled_in_store)
? "true"
: input.enabled_in_store
? "true"
: "false",
}, },
filters: { filters: {
@@ -8,23 +8,24 @@ import { useQueryGraphStep, validatePresenceOfStep } from "../../common"
import { useRemoteQueryStep } from "../../common/steps/use-remote-query" import { useRemoteQueryStep } from "../../common/steps/use-remote-query"
import { cartFieldsForPricingContext } from "../utils/fields" import { cartFieldsForPricingContext } from "../utils/fields"
import { ListShippingOptionsForCartWorkflowInput } from "@medusajs/types" import { ListShippingOptionsForCartWorkflowInput } from "@medusajs/types"
import { isDefined } from "@medusajs/framework/utils"
export const listShippingOptionsForCartWorkflowId = export const listShippingOptionsForCartWorkflowId =
"list-shipping-options-for-cart" "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). * [List Shipping Options Store API Route](https://docs.medusajs.com/api/store#shipping-options_getshippingoptions).
* *
* :::note * :::note
* *
* This workflow doesn't retrieve the calculated prices of the shipping options. If you need to retrieve the prices of the shipping options, * 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. * 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. * in your custom flows.
* *
* @example * @example
* const { result } = await listShippingOptionsForCartWorkflow(container) * const { result } = await listShippingOptionsForCartWorkflow(container)
* .run({ * .run({
@@ -33,16 +34,14 @@ export const listShippingOptionsForCartWorkflowId =
* option_ids: ["so_123"] * option_ids: ["so_123"]
* } * }
* }) * })
* *
* @summary * @summary
* *
* List a cart's shipping options. * List a cart's shipping options.
*/ */
export const listShippingOptionsForCartWorkflow = createWorkflow( export const listShippingOptionsForCartWorkflow = createWorkflow(
listShippingOptionsForCartWorkflowId, listShippingOptionsForCartWorkflowId,
( (input: WorkflowData<ListShippingOptionsForCartWorkflowInput>) => {
input: WorkflowData<ListShippingOptionsForCartWorkflowInput>
) => {
const cartQuery = useQueryGraphStep({ const cartQuery = useQueryGraphStep({
entity: "cart", entity: "cart",
filters: { id: input.cart_id }, filters: { id: input.cart_id },
@@ -92,27 +91,33 @@ export const listShippingOptionsForCartWorkflow = createWorkflow(
const queryVariables = transform( const queryVariables = transform(
{ input, fulfillmentSetIds, cart }, { input, fulfillmentSetIds, cart },
({ input, fulfillmentSetIds, cart }) => ({ ({ input, fulfillmentSetIds, cart }) => {
id: input.option_ids, return {
id: input.option_ids,
context: { context: {
is_return: input.is_return ?? false, is_return: input.is_return ? "true" : "false",
enabled_in_store: input.enabled_in_store ?? true, enabled_in_store: !isDefined(input.enabled_in_store)
}, ? "true"
: input.enabled_in_store
filters: { ? "true"
fulfillment_set_id: fulfillmentSetIds, : "false",
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 }, 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({ const shippingOptions = useRemoteQueryStep({