diff --git a/.changeset/sour-jobs-decide.md b/.changeset/sour-jobs-decide.md new file mode 100644 index 0000000000..1192bd376f --- /dev/null +++ b/.changeset/sour-jobs-decide.md @@ -0,0 +1,7 @@ +--- +"@medusajs/admin-ui": patch +"@medusajs/admin": patch +"@medusajs/medusa": patch +--- + +fix(inventory): Minor fixes to upserting inventory items diff --git a/packages/admin-ui/ui/src/components/organisms/product-variants-section/edit-variant-inventory-modal.tsx b/packages/admin-ui/ui/src/components/organisms/product-variants-section/edit-variant-inventory-modal.tsx index 254bbfe42d..28a903bc46 100644 --- a/packages/admin-ui/ui/src/components/organisms/product-variants-section/edit-variant-inventory-modal.tsx +++ b/packages/admin-ui/ui/src/components/organisms/product-variants-section/edit-variant-inventory-modal.tsx @@ -57,6 +57,7 @@ const EditVariantInventoryModal = ({ onClose, product, variant }: Props) => { delete data.ean delete data.barcode delete data.upc + delete data.allow_backorder return removeNullish({ ...updateDimensions, @@ -78,7 +79,7 @@ const EditVariantInventoryModal = ({ onClose, product, variant }: Props) => { let inventoryItemId: string | undefined = itemId - const { ean, barcode, upc } = data + const { ean, barcode, upc, allow_backorder } = data const upsertPayload = createUpdateInventoryItemPayload(data) let shouldInvalidateCache = false @@ -170,6 +171,7 @@ const EditVariantInventoryModal = ({ onClose, product, variant }: Props) => { ean, barcode, upc, + allow_backorder, }), () => { refetch() diff --git a/packages/medusa/src/api/routes/admin/inventory-items/transaction/create-inventory-item.ts b/packages/medusa/src/api/routes/admin/inventory-items/transaction/create-inventory-item.ts index 00a84bec97..38e770f4b4 100644 --- a/packages/medusa/src/api/routes/admin/inventory-items/transaction/create-inventory-item.ts +++ b/packages/medusa/src/api/routes/admin/inventory-items/transaction/create-inventory-item.ts @@ -2,7 +2,6 @@ import { IInventoryService, InventoryItemDTO } from "@medusajs/types" import { MedusaError } from "@medusajs/utils" import { EntityManager } from "typeorm" import { ulid } from "ulid" -import { ProductVariant } from "../../../../../models" import { ProductVariantInventoryService, ProductVariantService, @@ -74,19 +73,17 @@ export const createInventoryItemTransaction = async ( const productVariantServiceTx = productVariantService.withTransaction(manager) - const variant = await productVariantServiceTx.retrieve(variantId) - async function createInventoryItem(input: CreateInventoryItemInput) { return await inventoryService!.createInventoryItem({ - sku: variant.sku, - origin_country: variant.origin_country, - hs_code: variant.hs_code, - mid_code: variant.mid_code, - material: variant.material, - weight: variant.weight, - length: variant.length, - height: variant.height, - width: variant.width, + sku: input.sku, + origin_country: input.origin_country, + hs_code: input.hs_code, + mid_code: input.mid_code, + material: input.material, + weight: input.weight, + length: input.length, + height: input.height, + width: input.width, }) } @@ -96,10 +93,9 @@ export const createInventoryItemTransaction = async ( } } - async function attachInventoryItem( - variant: ProductVariant, - inventoryItem: InventoryItemDTO - ) { + async function attachInventoryItem(inventoryItem: InventoryItemDTO) { + const variant = await productVariantServiceTx.retrieve(variantId) + if (!variant.manage_inventory) { return } @@ -136,7 +132,7 @@ export const createInventoryItemTransaction = async ( ) => { const { [actions.createInventoryItem]: inventoryItem } = invoke - return await attachInventoryItem(variant, inventoryItem) + return await attachInventoryItem(inventoryItem) }, }, }