---
displayed_sidebar: servicesSidebar
---

import ParameterTypes from "@site/src/components/ParameterTypes"

# ProductVariantInventoryService

## constructor

### Parameters

<ParameterTypes parameters={[
  {
    "name": "__namedParameters",
    "type": "`InjectedDependencies`",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

___

## Properties

<ParameterTypes parameters={[
  {
    "name": "__configModule__",
    "type": "`Record<string, unknown>`",
    "description": "",
    "optional": true,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "__container__",
    "type": "`any`",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "__moduleDeclaration__",
    "type": "`Record<string, unknown>`",
    "description": "",
    "optional": true,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "eventBusService_",
    "type": "`IEventBusService`",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "manager_",
    "type": "`EntityManager`",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "productVariantService_",
    "type": "[ProductVariantService](services.ProductVariantService.mdx)",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "salesChannelInventoryService_",
    "type": "[SalesChannelInventoryService](services.SalesChannelInventoryService.mdx)",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "salesChannelLocationService_",
    "type": "[SalesChannelLocationService](services.SalesChannelLocationService.mdx)",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "transactionManager_",
    "type": "`undefined` \\| `EntityManager`",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

___

## Accessors

### activeManager\_

#### Returns

<ParameterTypes parameters={[
  {
    "name": "EntityManager",
    "type": "`EntityManager`",
    "optional": false,
    "defaultValue": "",
    "description": "",
    "expandable": false,
    "children": []
  }
]} />

___

### inventoryService\_

#### Returns

<ParameterTypes parameters={[
  {
    "name": "IInventoryService",
    "type": "`object`",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

___

### stockLocationService\_

#### Returns

<ParameterTypes parameters={[
  {
    "name": "IStockLocationService",
    "type": "`object`",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

___

## Methods

### adjustInventory

Adjusts inventory of a variant on a location

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "variantId",
    "type": "`string`",
    "description": "variant id",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "locationId",
    "type": "`string`",
    "description": "location id",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "quantity",
    "type": "`number`",
    "description": "quantity to adjust",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;void&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "",
    "expandable": false,
    "children": []
  }
]} />

___

### adjustReservationsQuantityByLineItem

Adjusts the quantity of reservations for a line item by a given amount.

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "lineItemId",
    "type": "`string`",
    "description": "The ID of the line item",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "variantId",
    "type": "`string`",
    "description": "The ID of the variant",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "locationId",
    "type": "`string`",
    "description": "The ID of the location to prefer adjusting quantities at",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "quantity",
    "type": "`number`",
    "description": "The amount to adjust the quantity by",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;void&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "",
    "expandable": false,
    "children": []
  }
]} />

___

### atomicPhase\_

Wraps some work within a transactional block. If the service already has
a transaction manager attached this will be reused, otherwise a new
transaction manager is created.

#### Type Parameters

<ParameterTypes parameters={[
  {
    "name": "TResult",
    "type": "`object`",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "TError",
    "type": "`object`",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "work",
    "type": "(`transactionManager`: `EntityManager`) => Promise&#60;TResult&#62;",
    "description": "the transactional work to be done",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "isolationOrErrorHandler",
    "type": "`IsolationLevel` \\| (`error`: `TError`) => Promise&#60;void \\| TResult&#62;",
    "description": "the isolation level to be used for the work.",
    "optional": true,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "maybeErrorHandlerOrDontFail",
    "type": "(`error`: `TError`) => Promise&#60;void \\| TResult&#62;",
    "description": "Potential error handler",
    "optional": true,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;TResult&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "the result of the transactional work",
    "expandable": false,
    "children": []
  }
]} />

___

### attachInventoryItem

`**attachInventoryItem**(attachments): Promise&#60;[ProductVariantInventoryItem](../../entities/classes/entities.ProductVariantInventoryItem.mdx)[]&#62;`

Attach a variant to an inventory item

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "attachments",
    "type": "`object`[]",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;[ProductVariantInventoryItem](../../entities/classes/entities.ProductVariantInventoryItem.mdx)[]&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "the variant inventory item",
    "expandable": false,
    "children": []
  }
]} />

`**attachInventoryItem**(variantId, inventoryItemId, requiredQuantity?): Promise&#60;[ProductVariantInventoryItem](../../entities/classes/entities.ProductVariantInventoryItem.mdx)[]&#62;`

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "variantId",
    "type": "`string`",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "inventoryItemId",
    "type": "`string`",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "requiredQuantity",
    "type": "`number`",
    "description": "",
    "optional": true,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;[ProductVariantInventoryItem](../../entities/classes/entities.ProductVariantInventoryItem.mdx)[]&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "",
    "expandable": false,
    "children": []
  }
]} />

___

### confirmInventory

confirms if requested inventory is available

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "variantId",
    "type": "`string`",
    "description": "id of the variant to confirm inventory for",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "quantity",
    "type": "`number`",
    "description": "quantity of inventory to confirm is available",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "context",
    "type": "`object`",
    "description": "optionally include a sales channel if applicable",
    "optional": false,
    "defaultValue": "{}",
    "expandable": false,
    "children": []
  },
  {
    "name": "context.salesChannelId",
    "type": "`null` \\| `string`",
    "description": "",
    "optional": true,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;Boolean&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "boolean indicating if inventory is available",
    "expandable": false,
    "children": []
  }
]} />

___

### deleteReservationsByLineItem

delete a reservation of variant quantity

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "lineItemId",
    "type": "`string` \\| `string`[]",
    "description": "line item id",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "variantId",
    "type": "`string`",
    "description": "variant id",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "quantity",
    "type": "`number`",
    "description": "quantity to release",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;void&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "",
    "expandable": false,
    "children": []
  }
]} />

___

### detachInventoryItem

Remove a variant from an inventory item

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "inventoryItemId",
    "type": "`string`",
    "description": "inventory item id",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "variantId",
    "type": "`string`",
    "description": "variant id or undefined if all the variants will be affected",
    "optional": true,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;void&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "",
    "expandable": false,
    "children": []
  }
]} />

___

### getAvailabilityContext

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "variants",
    "type": "`string`[]",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "salesChannelId",
    "type": "`undefined` \\| `string` \\| `string`[]",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "existingContext",
    "type": "`AvailabilityContext`",
    "description": "",
    "optional": false,
    "defaultValue": "{}",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;Required&#60;AvailabilityContext&#62;&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "",
    "expandable": false,
    "children": []
  }
]} />

___

### getVariantQuantityFromVariantInventoryItems

Get the quantity of a variant from a list of variantInventoryItems
The inventory quantity of the variant should be equal to the inventory
item with the smallest stock, adjusted for quantity required to fulfill
the given variant.

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "variantInventoryItems",
    "type": "[ProductVariantInventoryItem](../../entities/classes/entities.ProductVariantInventoryItem.mdx)[]",
    "description": "List of inventoryItems for a given variant, These must all be for the same variant",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "channelId",
    "type": "`string`",
    "description": "Sales channel id to fetch availability for",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;number&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "The available quantity of the variant from the inventoryItems",
    "expandable": false,
    "children": []
  }
]} />

___

### listByItem

list registered inventory items

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "itemIds",
    "type": "`string`[]",
    "description": "list inventory item ids",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;[ProductVariantInventoryItem](../../entities/classes/entities.ProductVariantInventoryItem.mdx)[]&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "list of inventory items",
    "expandable": false,
    "children": []
  }
]} />

___

### listByVariant

List inventory items for a specific variant

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "variantId",
    "type": "`string` \\| `string`[]",
    "description": "variant id",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;[ProductVariantInventoryItem](../../entities/classes/entities.ProductVariantInventoryItem.mdx)[]&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "variant inventory items for the variant id",
    "expandable": false,
    "children": []
  }
]} />

___

### listInventoryItemsByVariant

lists inventory items for a given variant

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "variantId",
    "type": "`string`",
    "description": "variant id",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;[InventoryItemDTO](../../medusa/types/medusa.InventoryItemDTO.mdx)[]&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "lidt of inventory items for the variant",
    "expandable": false,
    "children": []
  }
]} />

___

### listVariantsByItem

lists variant by inventory item id

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "itemId",
    "type": "`string`",
    "description": "item id",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;[ProductVariant](../../entities/classes/entities.ProductVariant.mdx)[]&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "a list of product variants that are associated with the item id",
    "expandable": false,
    "children": []
  }
]} />

___

### reserveQuantity

Reserves a quantity of a variant

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "variantId",
    "type": "`string`",
    "description": "variant id",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "quantity",
    "type": "`number`",
    "description": "quantity to reserve",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "context",
    "type": "`ReserveQuantityContext`",
    "description": "optional parameters",
    "optional": false,
    "defaultValue": "{}",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;void \\| [ReservationItemDTO](../../medusa/types/medusa.ReservationItemDTO.mdx)[]&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "",
    "expandable": false,
    "children": []
  }
]} />

___

### retrieve

Retrieves a product variant inventory item by its inventory item ID and variant ID.

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "inventoryItemId",
    "type": "`string`",
    "description": "The ID of the inventory item to retrieve.",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "variantId",
    "type": "`string`",
    "description": "The ID of the variant to retrieve.",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;[ProductVariantInventoryItem](../../entities/classes/entities.ProductVariantInventoryItem.mdx)&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "A promise that resolves with the product variant inventory item.",
    "expandable": false,
    "children": []
  }
]} />

___

### setProductAvailability

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "products",
    "type": "([Product](../../entities/classes/entities.Product.mdx) \\| [PricedProduct](../../medusa/types/medusa.PricedProduct.mdx))[]",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "salesChannelId",
    "type": "`undefined` \\| `string` \\| `string`[]",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;([Product](../../entities/classes/entities.Product.mdx) \\| [PricedProduct](../../medusa/types/medusa.PricedProduct.mdx))[]&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "",
    "expandable": false,
    "children": []
  }
]} />

___

### setVariantAvailability

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "variants",
    "type": "[ProductVariant](../../entities/classes/entities.ProductVariant.mdx)[] \\| [PricedVariant](../../medusa/types/medusa.PricedVariant.mdx)[]",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "salesChannelId",
    "type": "`undefined` \\| `string` \\| `string`[]",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "availabilityContext",
    "type": "`AvailabilityContext`",
    "description": "",
    "optional": false,
    "defaultValue": "{}",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;[ProductVariant](../../entities/classes/entities.ProductVariant.mdx)[] \\| [PricedVariant](../../medusa/types/medusa.PricedVariant.mdx)[]&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "",
    "expandable": false,
    "children": []
  }
]} />

___

### shouldRetryTransaction\_

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "err",
    "type": "`Record<string, unknown>` \\| `object`",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

<ParameterTypes parameters={[
  {
    "name": "boolean",
    "type": "`boolean`",
    "optional": true,
    "defaultValue": "",
    "description": "",
    "expandable": false,
    "children": []
  }
]} />

___

### validateInventoryAtLocation

Validate stock at a location for fulfillment items

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "items",
    "type": "Omit&#60;[LineItem](../../entities/classes/entities.LineItem.mdx), \"beforeInsert\"&#62;[]",
    "description": "Fulfillment Line items to validate quantities for",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "locationId",
    "type": "`string`",
    "description": "Location to validate stock at",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;void&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "nothing if successful, throws error if not",
    "expandable": false,
    "children": []
  }
]} />

___

### withTransaction

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "transactionManager",
    "type": "`EntityManager`",
    "description": "",
    "optional": true,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

<ParameterTypes parameters={[
  {
    "name": "ProductVariantInventoryService",
    "type": "`object`",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />
