Feat: draft order api (#6797)
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
import { CreateShippingMethodDTO, ICartModuleService } from "@medusajs/types"
|
||||
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||
import { ModuleRegistrationName } from "../../../../../modules-sdk/dist"
|
||||
|
||||
interface StepInput {
|
||||
shipping_methods: CreateShippingMethodDTO[]
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
import { CreateLineItemForCartDTO, ICartModuleService } from "@medusajs/types"
|
||||
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||
import { ModuleRegistrationName } from "../../../../../modules-sdk/dist"
|
||||
|
||||
interface StepInput {
|
||||
items: CreateLineItemForCartDTO[]
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
import { IInventoryService } from "@medusajs/types"
|
||||
import { promiseAll } from "@medusajs/utils"
|
||||
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||
import { MedusaError } from "medusa-core-utils"
|
||||
import { ModuleRegistrationName } from "../../../../../modules-sdk/dist"
|
||||
|
||||
interface StepInput {
|
||||
items: {
|
||||
@@ -22,10 +22,10 @@ export const confirmInventoryStep = createStep(
|
||||
)
|
||||
|
||||
// TODO: Should be bulk
|
||||
const promises = data.items.map((item) => {
|
||||
const promises = data.items.map(async (item) => {
|
||||
const itemQuantity = item.required_quantity * item.quantity
|
||||
|
||||
return inventoryService.confirmInventory(
|
||||
return await inventoryService.confirmInventory(
|
||||
item.inventory_item_id,
|
||||
item.location_ids,
|
||||
itemQuantity
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
import {
|
||||
CartLineItemDTO,
|
||||
CartShippingMethodDTO,
|
||||
@@ -11,7 +12,6 @@ import {
|
||||
} from "@medusajs/types"
|
||||
import { MedusaError } from "@medusajs/utils"
|
||||
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||
import { ModuleRegistrationName } from "../../../../../modules-sdk/dist"
|
||||
|
||||
interface StepInput {
|
||||
cart: CartWorkflowDTO
|
||||
@@ -42,7 +42,7 @@ function normalizeTaxModuleContext(
|
||||
return null
|
||||
}
|
||||
|
||||
let customer = cart.customer
|
||||
const customer = cart.customer
|
||||
? {
|
||||
id: cart.customer.id,
|
||||
email: cart.customer.email,
|
||||
@@ -104,6 +104,7 @@ export const getItemTaxLinesStep = createStep(
|
||||
shipping_methods: shippingMethods,
|
||||
force_tax_calculation: forceTaxCalculation = false,
|
||||
} = data
|
||||
|
||||
const taxService = container.resolve<ITaxModuleService>(
|
||||
ModuleRegistrationName.TAX
|
||||
)
|
||||
|
||||
@@ -16,7 +16,7 @@ interface StepInput {
|
||||
export const updateTaxLinesStepId = "update-tax-lines-step"
|
||||
export const updateTaxLinesStep = createStep(
|
||||
updateTaxLinesStepId,
|
||||
async (input: StepInput, { container, idempotencyKey }) => {
|
||||
async (input: StepInput, { container }) => {
|
||||
const { transaction } = await updateTaxLinesWorkflow(container).run({
|
||||
input,
|
||||
})
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { BigNumberInput } from "@medusajs/types"
|
||||
import { MedusaError } from "medusa-core-utils"
|
||||
|
||||
interface ConfirmInventoryPreparationInput {
|
||||
@@ -6,7 +7,7 @@ interface ConfirmInventoryPreparationInput {
|
||||
inventory_item_id: string
|
||||
required_quantity: number
|
||||
}[]
|
||||
items: { variant_id?: string; quantity: number }[]
|
||||
items: { variant_id?: string; quantity: BigNumberInput }[]
|
||||
variants: { id: string; manage_inventory?: boolean }[]
|
||||
location_ids: string[]
|
||||
}
|
||||
@@ -36,6 +37,12 @@ export const prepareConfirmInventoryInput = ({
|
||||
const itemsToConfirm: ConfirmInventoryItem[] = []
|
||||
|
||||
items.forEach((item) => {
|
||||
const variant = variantsMap.get(item.variant_id!)
|
||||
|
||||
if (!variant?.manage_inventory) {
|
||||
return
|
||||
}
|
||||
|
||||
const variantInventoryItem = product_variant_inventory_items.find(
|
||||
(i) => i.variant_id === item.variant_id
|
||||
)
|
||||
@@ -47,16 +54,12 @@ export const prepareConfirmInventoryInput = ({
|
||||
)
|
||||
}
|
||||
|
||||
const variant = variantsMap.get(item.variant_id!)
|
||||
|
||||
if (variant?.manage_inventory) {
|
||||
itemsToConfirm.push({
|
||||
inventory_item_id: variantInventoryItem.inventory_item_id,
|
||||
required_quantity: variantInventoryItem.required_quantity,
|
||||
quantity: item.quantity,
|
||||
location_ids: location_ids,
|
||||
})
|
||||
}
|
||||
itemsToConfirm.push({
|
||||
inventory_item_id: variantInventoryItem.inventory_item_id,
|
||||
required_quantity: variantInventoryItem.required_quantity,
|
||||
quantity: item.quantity as number, // TODO: update type to BigNumberInput
|
||||
location_ids: location_ids,
|
||||
})
|
||||
})
|
||||
|
||||
return itemsToConfirm
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { ProductVariantDTO } from "@medusajs/types"
|
||||
import { BigNumberInput, ProductVariantDTO } from "@medusajs/types"
|
||||
|
||||
interface Input {
|
||||
quantity: number
|
||||
quantity: BigNumberInput
|
||||
metadata?: Record<string, any>
|
||||
unitPrice: number
|
||||
unitPrice: BigNumberInput
|
||||
variant: ProductVariantDTO
|
||||
cartId?: string
|
||||
}
|
||||
@@ -27,7 +27,7 @@ export function prepareLineItemData(data: Input) {
|
||||
product_description: variant.product.description,
|
||||
product_subtitle: variant.product.subtitle,
|
||||
product_type: variant.product.type?.[0].value ?? null,
|
||||
product_collection: variant.product.collection?.[0].value ?? null,
|
||||
product_collection: variant.product.collection?.[0]?.value ?? null,
|
||||
product_handle: variant.product.handle,
|
||||
|
||||
variant_id: variant.id,
|
||||
|
||||
Reference in New Issue
Block a user