fix(core-flows): fulfillment reservation check (#11735)
This commit is contained in:
@@ -42,16 +42,16 @@ export type OrderClaimAddNewItemValidationStepInput = {
|
||||
}
|
||||
|
||||
/**
|
||||
* This step validates that new items can be added to the claim. If the
|
||||
* This step validates that new items can be added to the claim. If the
|
||||
* order or claim is canceled, or the order change is not active, the step will throw an error.
|
||||
*
|
||||
*
|
||||
* :::note
|
||||
*
|
||||
*
|
||||
* You can retrieve an order, order claim, and order change details using [Query](https://docs.medusajs.com/learn/fundamentals/module-links/query),
|
||||
* or [useQueryGraphStep](https://docs.medusajs.com/resources/references/medusa-workflows/steps/useQueryGraphStep).
|
||||
*
|
||||
*
|
||||
* :::
|
||||
*
|
||||
*
|
||||
* @example
|
||||
* const data = orderClaimAddNewItemValidationStep({
|
||||
* order: {
|
||||
@@ -85,10 +85,10 @@ export const orderClaimAddNewItemWorkflowId = "claim-add-new-item"
|
||||
/**
|
||||
* This workflow adds outbound (or new) items to a claim. It's used by the
|
||||
* [Add Outbound Items Admin API Route](https://docs.medusajs.com/api/admin#claims_postclaimsidoutbounditems).
|
||||
*
|
||||
*
|
||||
* You can use this workflow within your customizations or your own custom workflows, allowing you to add outbound items to a claim
|
||||
* in your custom flows.
|
||||
*
|
||||
*
|
||||
* @example
|
||||
* const { result } = await orderClaimAddNewItemWorkflow(container)
|
||||
* .run({
|
||||
@@ -102,9 +102,9 @@ export const orderClaimAddNewItemWorkflowId = "claim-add-new-item"
|
||||
* ]
|
||||
* }
|
||||
* })
|
||||
*
|
||||
*
|
||||
* @summary
|
||||
*
|
||||
*
|
||||
* Add outbound or new items to a claim.
|
||||
*/
|
||||
export const orderClaimAddNewItemWorkflow = createWorkflow(
|
||||
|
||||
@@ -239,7 +239,7 @@ function extractShippingOption({ orderPreview, orderClaim, returnId }) {
|
||||
|
||||
for (const action of modifiedShippingMethod_.actions) {
|
||||
if (action.action === ChangeActionType.SHIPPING_ADD) {
|
||||
if (action.return?.id === returnId) {
|
||||
if (!!action.return_id && action.return_id === returnId) {
|
||||
returnShippingMethod = shippingMethod
|
||||
} else if (action.claim_id === orderClaim.id) {
|
||||
claimShippingMethod = shippingMethod
|
||||
|
||||
@@ -241,10 +241,14 @@ function prepareInventoryUpdate({
|
||||
}[] = []
|
||||
|
||||
const allItems = itemsList ?? order.items
|
||||
for (const item of allItems) {
|
||||
const itemsToFulfill = allItems.filter((i) => i.id in inputItemsMap)
|
||||
|
||||
// iterate over items that are being fulfilled
|
||||
for (const item of itemsToFulfill) {
|
||||
const reservation = reservationMap[item.id]
|
||||
|
||||
if (!reservation) {
|
||||
if (item.manage_inventory) {
|
||||
if (item.variant?.manage_inventory) {
|
||||
throw new Error(
|
||||
`No stock reservation found for item ${item.id} - ${item.title} (${item.variant_title})`
|
||||
)
|
||||
@@ -345,6 +349,7 @@ export const createOrderFulfillmentWorkflow = createWorkflow(
|
||||
"items.variant.height",
|
||||
"items.variant.width",
|
||||
"items.variant.material",
|
||||
"items.variant_title",
|
||||
"shipping_address.*",
|
||||
"shipping_methods.id",
|
||||
"shipping_methods.shipping_option_id",
|
||||
@@ -394,9 +399,11 @@ export const createOrderFulfillmentWorkflow = createWorkflow(
|
||||
}).config({ name: "get-shipping-option" })
|
||||
|
||||
const lineItemIds = transform(
|
||||
{ order, itemsList: input.items_list },
|
||||
({ order, itemsList }) => {
|
||||
return (itemsList ?? order.items)!.map((i) => i.id)
|
||||
{ order, itemsList: input.items_list, inputItemsMap },
|
||||
({ order, itemsList, inputItemsMap }) => {
|
||||
return (itemsList ?? order.items)!
|
||||
.map((i) => i.id)
|
||||
.filter((i) => i in inputItemsMap)
|
||||
}
|
||||
)
|
||||
const reservations = useRemoteQueryStep({
|
||||
|
||||
Reference in New Issue
Block a user