fix: expose beforeRefreshingPaymentCollection hook (#12232)
Fixes: FRMW-2942 Fixes: #12228
This commit is contained in:
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@medusajs/core-flows": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix: expose beforeRefreshingPaymentCollection hook
|
||||||
@@ -89,11 +89,11 @@ export const refreshCartItemsWorkflowId = "refresh-cart-items"
|
|||||||
* @summary
|
* @summary
|
||||||
*
|
*
|
||||||
* Refresh a cart's details after an update.
|
* 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.
|
* @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:
|
* For example, assuming you have the following custom pricing rule:
|
||||||
*
|
*
|
||||||
* ```json
|
* ```json
|
||||||
* {
|
* {
|
||||||
* "attribute": "location_id",
|
* "attribute": "location_id",
|
||||||
@@ -101,13 +101,13 @@ export const refreshCartItemsWorkflowId = "refresh-cart-items"
|
|||||||
* "value": "sloc_123",
|
* "value": "sloc_123",
|
||||||
* }
|
* }
|
||||||
* ```
|
* ```
|
||||||
*
|
*
|
||||||
* You can consume the `setPricingContext` hook to add the `location_id` context to the prices calculation:
|
* You can consume the `setPricingContext` hook to add the `location_id` context to the prices calculation:
|
||||||
*
|
*
|
||||||
* ```ts
|
* ```ts
|
||||||
* import { refreshCartItemsWorkflow } from "@medusajs/medusa/core-flows";
|
* import { refreshCartItemsWorkflow } from "@medusajs/medusa/core-flows";
|
||||||
* import { StepResponse } from "@medusajs/workflows-sdk";
|
* import { StepResponse } from "@medusajs/workflows-sdk";
|
||||||
*
|
*
|
||||||
* refreshCartItemsWorkflow.hooks.setPricingContext((
|
* refreshCartItemsWorkflow.hooks.setPricingContext((
|
||||||
* { cart, items, additional_data }, { container }
|
* { 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.
|
* The variants' prices will now be retrieved using the context you return.
|
||||||
*
|
*
|
||||||
* :::note
|
* :::note
|
||||||
*
|
*
|
||||||
* Learn more about prices calculation context in the [Prices Calculation](https://docs.medusajs.com/resources/commerce-modules/pricing/price-calculation) documentation.
|
* 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({
|
refreshPaymentCollectionForCartWorkflow.runAsStep({
|
||||||
input: { cart_id: input.cart_id },
|
input: { cart_id: input.cart_id },
|
||||||
})
|
})
|
||||||
|
|
||||||
return new WorkflowResponse(refetchedCart, {
|
return new WorkflowResponse(refetchedCart, {
|
||||||
hooks: [setPricingContext] as const,
|
hooks: [setPricingContext, beforeRefreshingPaymentCollection] as const,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user