feat: Add payment + promotion refreshing to cart workflows (#6654)
Add payment collection refreshing to: - Add to cart - Create cart - Update line item in cart Add promotion creation to: - Create cart
This commit is contained in:
@@ -16,11 +16,11 @@ import {
|
||||
import { refreshCartPromotionsStep } from "../steps/refresh-cart-promotions"
|
||||
import { updateTaxLinesStep } from "../steps/update-tax-lines"
|
||||
import { prepareLineItemData } from "../utils/prepare-line-item-data"
|
||||
import { refreshPaymentCollectionForCartStep } from "./refresh-payment-collection"
|
||||
|
||||
// TODO: The AddToCartWorkflow are missing the following steps:
|
||||
// - Confirm inventory exists (inventory module)
|
||||
// - Refresh/delete shipping methods (fulfillment module)
|
||||
// - Update payment sessions (payment module)
|
||||
|
||||
export const addToCartWorkflowId = "add-to-cart"
|
||||
export const addToCartWorkflow = createWorkflow(
|
||||
@@ -96,6 +96,9 @@ export const addToCartWorkflow = createWorkflow(
|
||||
})
|
||||
|
||||
refreshCartPromotionsStep({ id: input.cart.id })
|
||||
refreshPaymentCollectionForCartStep({
|
||||
cart_id: input.cart.id,
|
||||
})
|
||||
|
||||
return items
|
||||
}
|
||||
|
||||
@@ -14,14 +14,14 @@ import {
|
||||
getVariantsStep,
|
||||
validateVariantsExistStep,
|
||||
} from "../steps"
|
||||
import { refreshCartPromotionsStep } from "../steps/refresh-cart-promotions"
|
||||
import { updateTaxLinesStep } from "../steps/update-tax-lines"
|
||||
import { prepareLineItemData } from "../utils/prepare-line-item-data"
|
||||
import { refreshPaymentCollectionForCartStep } from "./refresh-payment-collection"
|
||||
|
||||
// TODO: The UpdateLineItemsWorkflow are missing the following steps:
|
||||
// - Confirm inventory exists (inventory module)
|
||||
// - Refresh/delete shipping methods (fulfillment module)
|
||||
// - Refresh/create line item adjustments (promotion module)
|
||||
// - Update payment sessions (payment module)
|
||||
|
||||
export const createCartWorkflowId = "create-cart"
|
||||
export const createCartWorkflow = createWorkflow(
|
||||
@@ -134,7 +134,14 @@ export const createCartWorkflow = createWorkflow(
|
||||
const carts = createCartsStep([cartToCreate])
|
||||
const cart = transform({ carts }, (data) => data.carts?.[0])
|
||||
|
||||
refreshCartPromotionsStep({
|
||||
id: cart.id,
|
||||
promo_codes: input.promo_codes,
|
||||
})
|
||||
updateTaxLinesStep({ cart_or_cart_id: cart.id })
|
||||
refreshPaymentCollectionForCartStep({
|
||||
cart_id: cart.id,
|
||||
})
|
||||
|
||||
return cart
|
||||
}
|
||||
|
||||
@@ -4,15 +4,15 @@ import {
|
||||
createWorkflow,
|
||||
transform,
|
||||
} from "@medusajs/workflows-sdk"
|
||||
import { getVariantPriceSetsStep } from ".."
|
||||
import { updateLineItemsStep } from "../../line-item/steps"
|
||||
import { getVariantPriceSetsStep } from "../steps"
|
||||
import { refreshCartPromotionsStep } from "../steps/refresh-cart-promotions"
|
||||
import { refreshPaymentCollectionForCartStep } from "./refresh-payment-collection"
|
||||
|
||||
// TODO: The UpdateLineItemsWorkflow are missing the following steps:
|
||||
// - Confirm inventory exists (inventory module)
|
||||
// - Validate shipping methods for new items (fulfillment module)
|
||||
// - Refresh line item adjustments (promotion module)
|
||||
// - Update payment sessions (payment module)
|
||||
|
||||
export const updateLineItemInCartWorkflowId = "update-line-item-in-cart"
|
||||
export const updateLineItemInCartWorkflow = createWorkflow(
|
||||
@@ -57,6 +57,9 @@ export const updateLineItemInCartWorkflow = createWorkflow(
|
||||
})
|
||||
|
||||
refreshCartPromotionsStep({ id: input.cart.id })
|
||||
refreshPaymentCollectionForCartStep({
|
||||
cart_id: input.cart.id,
|
||||
})
|
||||
|
||||
const updatedItem = transform({ result }, (data) => data.result?.[0])
|
||||
|
||||
|
||||
@@ -68,6 +68,7 @@ export interface CreateCartWorkflowInputDTO {
|
||||
metadata?: Record<string, unknown>
|
||||
|
||||
items?: CreateCartCreateLineItemDTO[]
|
||||
promo_codes?: string[]
|
||||
}
|
||||
|
||||
export interface AddToCartWorkflowInputDTO {
|
||||
|
||||
Reference in New Issue
Block a user