Back to Medusa

ProductUtils

www/apps/resources/references/utils/utils.ProductUtils/page.mdx

2.14.26.9 KB
Original Source

import { TypeList } from "docs-ui"

ProductUtils

Classes

Enumerations

Functions

Namespaces

Type Aliases

Variables


Functions

getTotalVariantAvailability

Computes the total availability for a list of variants across all stock locations

Parameters

<TypeList types={[{"name":"query","type":"Omit<RemoteQueryFunction, symbol>","description":"The Query function","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"graph","type":"QueryGraphFunction","description":"Graph function uses the remoteQuery under the hood and\nreturns a result set","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"index","type":"QueryIndexFunction","description":"Index function uses the index module to query and remoteQuery to hydrate the data\nreturns a result set","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"gql","type":"(query: string, variables?: Record<string, unknown>, options?: RemoteJoinerOptions) => Promise<any>","description":"Query wrapper to provide specific GraphQL like API around remoteQuery.query","optional":false,"defaultValue":"","expandable":false,"children":[]}]},{"name":"data","type":"TotalVariantAvailabilityData","description":"An object containing the variant ids to compute the availability for","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"variant_ids","type":"string[]","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/learn/fundamentals/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="getTotalVariantAvailability"/>

Returns

<TypeList types={[{"name":"Promise","type":"Promise<object>","optional":false,"defaultValue":"","description":"the total availability for the given variants","expandable":false,"children":[]}]} expandUrl="https://docs.medusajs.com/learn/fundamentals/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="getTotalVariantAvailability"/>

getVariantAvailability

Computes the variant availability for a list of variants in a given sales channel

The availability algorithm works as follows:

  1. For each variant, we retrieve its inventory items.
  2. We calculate the available quantity for each inventory item, considering only the stock locations associated with the given sales channel.
  3. For each inventory item, we calculate the maximum deliverable quantity by dividing the available quantity by the quantity required for the variant.
  4. We take the minimum of these maximum deliverable quantities across all inventory items for the variant.
  5. This minimum value represents the overall availability of the variant in the given sales channel.

The algorithm takes into account:

  • Variant inventory items: The inventory records associated with each variant.
  • Required quantities: The quantity of each inventory item required to fulfill one unit of the variant.
  • Sales channels: The specific sales channel for which we're calculating availability.
  • Stock locations: The inventory locations associated with the sales channel.

Parameters

<TypeList types={[{"name":"query","type":"Omit<RemoteQueryFunction, symbol>","description":"The Query function","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"graph","type":"QueryGraphFunction","description":"Graph function uses the remoteQuery under the hood and\nreturns a result set","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"index","type":"QueryIndexFunction","description":"Index function uses the index module to query and remoteQuery to hydrate the data\nreturns a result set","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"gql","type":"(query: string, variables?: Record<string, unknown>, options?: RemoteJoinerOptions) => Promise<any>","description":"Query wrapper to provide specific GraphQL like API around remoteQuery.query","optional":false,"defaultValue":"","expandable":false,"children":[]}]},{"name":"data","type":"VariantAvailabilityData","description":"An object containing the variant ids and the sales channel id to compute the availability for","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"variant_ids","type":"string[]","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"sales_channel_id","type":"string","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/learn/fundamentals/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="getVariantAvailability"/>

Returns

<TypeList types={[{"name":"Promise","type":"Promise<VariantAvailabilityResult>","optional":false,"defaultValue":"","description":"an object containing the variant ids and their availability","expandable":false,"children":[{"name":"VariantAvailabilityResult","type":"object","description":"The computed inventory availability for variants in a given sales channel.\nThe object's keys are the variant IDs.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]} expandUrl="https://docs.medusajs.com/learn/fundamentals/data-models/manage-relationships#retrieve-records-of-relation" sectionTitle="getVariantAvailability"/>


Variables

ProductEvents

Const ProductEvents: ReturnType<["product", "productVariant", "productOption", "productOptionValue", "productType", "productTag", "productCategory", "productCollection", "productImage"], "product">