fix: expose beforeRefreshingPaymentCollection hook (#12232)
Fixes: FRMW-2942 Fixes: #12228
This commit is contained in:
5
.changeset/curvy-chicken-explode.md
Normal file
5
.changeset/curvy-chicken-explode.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@medusajs/core-flows": patch
|
||||
---
|
||||
|
||||
fix: expose beforeRefreshingPaymentCollection hook
|
||||
@@ -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,
|
||||
})
|
||||
}
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user