|
1
|
{"slug":"/references/utils/utils.ProductUtils","title":"ProductUtils","frontmatter":{},"toc":[{"title":"Classes","id":"classes","level":2},{"title":"Enumerations","id":"enumerations","level":2},{"title":"Functions","id":"functions","level":2},{"title":"Type Aliases","id":"type-aliases","level":2},{"title":"Variables","id":"variables","level":2},{"title":"Functions","id":"functions-1","level":2},{"title":"getTotalVariantAvailability","id":"gettotalvariantavailability","level":3},{"title":"Parameters","id":"gettotalvariantavailability-parameters","level":4},{"title":"Returns","id":"gettotalvariantavailability-returns","level":4},{"title":"getVariantAvailability","id":"getvariantavailability","level":3},{"title":"Parameters","id":"getvariantavailability-parameters","level":4},{"title":"Returns","id":"getvariantavailability-returns","level":4},{"title":"Variables","id":"variables-1","level":2},{"title":"ProductEvents","id":"productevents","level":3},{"title":"ProductsQueryContextKey","id":"productsquerycontextkey","level":3},{"title":"PublishedProductsContextKey","id":"publishedproductscontextkey","level":3}],"blocks":[{"kind":"heading","level":2,"text":"Classes","id":"classes"},{"kind":"linkList","items":[{"title":"CSVNormalizer","href":"/references/utils/ProductUtils/classes/utils.ProductUtils.CSVNormalizer"}]},{"kind":"heading","level":2,"text":"Enumerations","id":"enumerations"},{"kind":"linkList","items":[{"title":"ProductStatus","href":"/references/utils/ProductUtils/enums/utils.ProductUtils.ProductStatus"}]},{"kind":"heading","level":2,"text":"Functions","id":"functions"},{"kind":"linkList","items":[{"title":"getTotalVariantAvailability","href":"/references/utils/utils.ProductUtils#gettotalvariantavailability"},{"title":"getVariantAvailability","href":"/references/utils/utils.ProductUtils#getvariantavailability"}]},{"kind":"linkList","items":[{"title":"productValidators","href":"/references/utils/ProductUtils/utils.ProductUtils.productValidators"}]},{"kind":"heading","level":2,"text":"Type Aliases","id":"type-aliases"},{"kind":"linkList","items":[{"title":"VariantAvailabilityResult","href":"/references/utils/ProductUtils/types/utils.ProductUtils.VariantAvailabilityResult"}]},{"kind":"heading","level":2,"text":"Variables","id":"variables"},{"kind":"linkList","items":[{"title":"ProductEvents","href":"/references/utils/utils.ProductUtils#productevents"},{"title":"ProductsQueryContextKey","href":"/references/utils/utils.ProductUtils#productsquerycontextkey"},{"title":"PublishedProductsContextKey","href":"/references/utils/utils.ProductUtils#publishedproductscontextkey"}]},{"kind":"heading","level":2,"text":"Functions","id":"functions-1"},{"kind":"heading","level":3,"text":"getTotalVariantAvailability","id":"gettotalvariantavailability"},{"kind":"markdown","html":"Computes the total availability for a list of variants across all stock locations"},{"kind":"heading","level":4,"text":"Parameters","id":"gettotalvariantavailability-parameters"},{"kind":"typeList","sectionTitle":"getTotalVariantAvailability","types":[{"name":"query","type":"Omit<[RemoteQueryFunction](/references/types/ModulesSdkTypes/types/types.ModulesSdkTypes.RemoteQueryFunction), symbol>","description":"The Query function","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"graph","type":"[QueryGraphFunction](/references/types/ModulesSdkTypes/types/types.ModulesSdkTypes.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](/references/types/ModulesSdkTypes/types/types.ModulesSdkTypes.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":"search","type":"[QuerySearchFunction](/references/types/ModulesSdkTypes/types/types.ModulesSdkTypes.QuerySearchFunction)","description":"Search function uses the search module and hydrates the results through graph","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"gql","type":"(`query`: `string`, `variables?`: `Record<string, unknown>`, `options?`: [RemoteJoinerOptions](/references/types/interfaces/types.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](/references/utils/types/utils.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":[]}]}]},{"kind":"heading","level":4,"text":"Returns","id":"gettotalvariantavailability-returns"},{"kind":"typeList","sectionTitle":"getTotalVariantAvailability","types":[{"name":"Promise","type":"Promise<object>","optional":false,"defaultValue":"","description":"the total availability for the given variants","expandable":false,"children":[]}]},{"kind":"heading","level":3,"text":"getVariantAvailability","id":"getvariantavailability"},{"kind":"markdown","html":"Computes the variant availability for a list of variants in a given sales channel\n\nThe availability algorithm works as follows:\n1. For each variant, we retrieve its inventory items.\n2. We calculate the available quantity for each inventory item, considering only the stock locations associated with the given sales channel.\n3. For each inventory item, we calculate the maximum deliverable quantity by dividing the available quantity by the quantity required for the variant.\n4. We take the minimum of these maximum deliverable quantities across all inventory items for the variant.\n5. This minimum value represents the overall availability of the variant in the given sales channel.\n\nThe algorithm takes into account:\n- Variant inventory items: The inventory records associated with each variant.\n- Required quantities: The quantity of each inventory item required to fulfill one unit of the variant.\n- Sales channels: The specific sales channel for which we're calculating availability.\n- Stock locations: The inventory locations associated with the sales channel."},{"kind":"heading","level":4,"text":"Parameters","id":"getvariantavailability-parameters"},{"kind":"typeList","sectionTitle":"getVariantAvailability","types":[{"name":"query","type":"Omit<[RemoteQueryFunction](/references/types/ModulesSdkTypes/types/types.ModulesSdkTypes.RemoteQueryFunction), symbol>","description":"The Query function","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"graph","type":"[QueryGraphFunction](/references/types/ModulesSdkTypes/types/types.ModulesSdkTypes.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](/references/types/ModulesSdkTypes/types/types.ModulesSdkTypes.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":"search","type":"[QuerySearchFunction](/references/types/ModulesSdkTypes/types/types.ModulesSdkTypes.QuerySearchFunction)","description":"Search function uses the search module and hydrates the results through graph","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"gql","type":"(`query`: `string`, `variables?`: `Record<string, unknown>`, `options?`: [RemoteJoinerOptions](/references/types/interfaces/types.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](/references/utils/types/utils.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":[]}]}]},{"kind":"heading","level":4,"text":"Returns","id":"getvariantavailability-returns"},{"kind":"typeList","sectionTitle":"getVariantAvailability","types":[{"name":"Promise","type":"Promise<[VariantAvailabilityResult](/references/utils/ProductUtils/types/utils.ProductUtils.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":[]}]}]},{"kind":"heading","level":2,"text":"Variables","id":"variables-1"},{"kind":"heading","level":3,"text":"ProductEvents","id":"productevents"},{"kind":"markdown","html":"`Const` **ProductEvents**: ReturnType<[\"product\", \"productVariant\", \"productOption\", \"productProductOption\", \"productProductOptionValue\", \"productOptionValue\", \"productType\", \"productTag\", \"productCategory\", \"productCollection\", \"productImage\"], \"product\">"},{"kind":"heading","level":3,"text":"ProductsQueryContextKey","id":"productsquerycontextkey"},{"kind":"markdown","html":"`Const` **ProductsQueryContextKey**: `\"products\"`"},{"kind":"markdown","html":"Query context namespace for the Product module.\n\nContexts are namespaced by what they configure, so several can travel on the\nsame query without colliding:\n\n```ts\nQueryContext({\n [ProductsQueryContextKey]: { [PublishedProductsContextKey]: true },\n})\n```"},{"kind":"heading","level":3,"text":"PublishedProductsContextKey","id":"publishedproductscontextkey"},{"kind":"markdown","html":"`Const` **PublishedProductsContextKey**: `\"published\"`"},{"kind":"markdown","html":"Asks the Product module to resolve published products only.\n\nSet by the store API, so that traversing into `Product` from a product tag,\ntype, collection, or category hides unpublished products the same way a\ndirect product query does."}]} |