From 24af8f2d8e27d0f842e6e596bc4c695882f67737 Mon Sep 17 00:00:00 2001 From: Harminder Virk Date: Fri, 18 Apr 2025 15:01:19 +0530 Subject: [PATCH] fix: expose beforeRefreshingPaymentCollection hook (#12232) Fixes: FRMW-2942 Fixes: #12228 --- .changeset/curvy-chicken-explode.md | 5 ++++ .../src/cart/workflows/refresh-cart-items.ts | 27 ++++++++++--------- 2 files changed, 20 insertions(+), 12 deletions(-) create mode 100644 .changeset/curvy-chicken-explode.md diff --git a/.changeset/curvy-chicken-explode.md b/.changeset/curvy-chicken-explode.md new file mode 100644 index 0000000000..ebd2a32236 --- /dev/null +++ b/.changeset/curvy-chicken-explode.md @@ -0,0 +1,5 @@ +--- +"@medusajs/core-flows": patch +--- + +fix: expose beforeRefreshingPaymentCollection hook diff --git a/packages/core/core-flows/src/cart/workflows/refresh-cart-items.ts b/packages/core/core-flows/src/cart/workflows/refresh-cart-items.ts index ea6029e4a1..c770b8761d 100644 --- a/packages/core/core-flows/src/cart/workflows/refresh-cart-items.ts +++ b/packages/core/core-flows/src/cart/workflows/refresh-cart-items.ts @@ -89,11 +89,11 @@ export const refreshCartItemsWorkflowId = "refresh-cart-items" * @summary * * Refresh a cart's details after an update. - * + * * @property hooks.setPricingContext - This hook is executed before the cart is refreshed. You can consume this hook to return any custom context useful for the prices retrieval of the variants in the cart. - * + * * For example, assuming you have the following custom pricing rule: - * + * * ```json * { * "attribute": "location_id", @@ -101,13 +101,13 @@ export const refreshCartItemsWorkflowId = "refresh-cart-items" * "value": "sloc_123", * } * ``` - * + * * You can consume the `setPricingContext` hook to add the `location_id` context to the prices calculation: - * + * * ```ts * import { refreshCartItemsWorkflow } from "@medusajs/medusa/core-flows"; * import { StepResponse } from "@medusajs/workflows-sdk"; - * + * * refreshCartItemsWorkflow.hooks.setPricingContext(( * { cart, items, additional_data }, { container } * ) => { @@ -116,13 +116,13 @@ export const refreshCartItemsWorkflowId = "refresh-cart-items" * }); * }); * ``` - * + * * The variants' prices will now be retrieved using the context you return. - * + * * :::note - * + * * Learn more about prices calculation context in the [Prices Calculation](https://docs.medusajs.com/resources/commerce-modules/pricing/price-calculation) documentation. - * + * * ::: * */ @@ -292,14 +292,17 @@ export const refreshCartItemsWorkflow = createWorkflow( }, }) - createHook("beforeRefreshingPaymentCollection", { input }) + const beforeRefreshingPaymentCollection = createHook( + "beforeRefreshingPaymentCollection", + { input } + ) refreshPaymentCollectionForCartWorkflow.runAsStep({ input: { cart_id: input.cart_id }, }) return new WorkflowResponse(refetchedCart, { - hooks: [setPricingContext] as const, + hooks: [setPricingContext, beforeRefreshingPaymentCollection] as const, }) } )