IProductModuleService
Methods
create
This method is used to create a product.
Example
Parameters
sharedContext
ContextReturns
createCategory
This method is used to create a product category.
Example
import {
initialize as initializeProductModule,
} from "@medusajs/product"
async function createCategory (name: string, parent_category_id: string | null) {
const productModule = await initializeProductModule()
const category = await productModule.createCategory({
name,
parent_category_id
})
// do something with the product category or return it
}
Parameters
sharedContext
ContextReturns
createCollections
This method is used to create product collections.
Example
import {
initialize as initializeProductModule,
} from "@medusajs/product"
async function createCollection (title: string) {
const productModule = await initializeProductModule()
const collections = await productModule.createCollections([
{
title
}
])
// do something with the product collections or return them
}
Parameters
sharedContext
ContextReturns
createOptions
This method is used to create product options.
Example
import {
initialize as initializeProductModule,
} from "@medusajs/product"
async function createProductOption (title: string, productId: string) {
const productModule = await initializeProductModule()
const productOptions = await productModule.createOptions([
{
title,
product_id: productId
}
])
// do something with the product options or return them
}
Parameters
sharedContext
ContextReturns
createTags
This method is used to create product tags.
Example
import {
initialize as initializeProductModule,
} from "@medusajs/product"
async function createProductTags (values: string[]) {
const productModule = await initializeProductModule()
const productTags = await productModule.createTags(
values.map((value) => ({
value
}))
)
// do something with the product tags or return them
}
Parameters
sharedContext
ContextReturns
createTypes
This method is used to create a product type.
Example
import {
initialize as initializeProductModule,
} from "@medusajs/product"
async function createProductType (value: string) {
const productModule = await initializeProductModule()
const productTypes = await productModule.createTypes([
{
value
}
])
// do something with the product types or return them
}
Parameters
sharedContext
ContextReturns
delete
This method is used to delete products. Unlike the softDelete method, this method will completely remove the products and they can no longer be accessed or retrieved.
Example
Parameters
productIds
string[]RequiredsharedContext
ContextReturns
Promise
Promise<void>RequireddeleteCategory
This method is used to delete a product category by its ID.
Example
Parameters
categoryId
stringRequiredsharedContext
ContextReturns
Promise
Promise<void>RequireddeleteCollections
This method is used to delete collections by their ID.
Example
Parameters
productCollectionIds
string[]RequiredsharedContext
ContextReturns
Promise
Promise<void>RequireddeleteOptions
This method is used to delete a product option.
Example
Parameters
productOptionIds
string[]RequiredsharedContext
ContextReturns
Promise
Promise<void>RequireddeleteTags
This method is used to delete product tags by their ID.
Example
Parameters
productTagIds
string[]RequiredsharedContext
ContextReturns
Promise
Promise<void>RequireddeleteTypes
This method is used to delete a product type.
Example
Parameters
productTypeIds
string[]RequiredsharedContext
ContextReturns
Promise
Promise<void>Requiredlist
This method is used to retrieve a paginated list of price sets based on optional filters and configuration.
Example
To retrieve a list of products using their IDs:
To specify relations that should be retrieved within the products:
import {
initialize as initializeProductModule,
} from "@medusajs/product"
async function retrieveProducts (ids: string[]) {
const productModule = await initializeProductModule()
const products = await productModule.list({
id: ids
}, {
relations: ["categories"]
})
// do something with the products or return them
}
By default, only the first 15
records are retrieved. You can control pagination by specifying the skip
and take
properties of the config
parameter:
import {
initialize as initializeProductModule,
} from "@medusajs/product"
async function retrieveProducts (ids: string[], skip: number, take: number) {
const productModule = await initializeProductModule()
const products = await productModule.list({
id: ids
}, {
relations: ["categories"],
skip,
take
})
// do something with the products or return them
}
You can also use the $and
or $or
properties of the filter
parameter to use and/or conditions in your filters. For example:
import {
initialize as initializeProductModule,
} from "@medusajs/product"
async function retrieveProducts (ids: string[], title: string, skip: number, take: number) {
const productModule = await initializeProductModule()
const products = await productModule.list({
$and: [
{
id: ids
},
{
q: title
}
]
}, {
relations: ["categories"],
skip,
take
})
// do something with the products or return them
}
Parameters
filters
FilterableProductPropsconfig
FindConfig<ProductDTO>select
or relations
, accept the attributes or relations associated with a product.sharedContext
ContextReturns
listAndCount
This method is used to retrieve a paginated list of products along with the total count of available products satisfying the provided filters.
Example
To retrieve a list of products using their IDs:
To specify relations that should be retrieved within the products:
import {
initialize as initializeProductModule,
} from "@medusajs/product"
async function retrieveProducts (ids: string[]) {
const productModule = await initializeProductModule()
const [products, count] = await productModule.listAndCount({
id: ids
}, {
relations: ["categories"]
})
// do something with the products or return them
}
By default, only the first 15
records are retrieved. You can control pagination by specifying the skip
and take
properties of the config
parameter:
import {
initialize as initializeProductModule,
} from "@medusajs/product"
async function retrieveProducts (ids: string[], skip: number, take: number) {
const productModule = await initializeProductModule()
const [products, count] = await productModule.listAndCount({
id: ids
}, {
relations: ["categories"],
skip,
take
})
// do something with the products or return them
}
You can also use the $and
or $or
properties of the filter
parameter to use and/or conditions in your filters. For example:
import {
initialize as initializeProductModule,
} from "@medusajs/product"
async function retrieveProducts (ids: string[], title: string, skip: number, take: number) {
const productModule = await initializeProductModule()
const [products, count] = await productModule.listAndCount({
$and: [
{
id: ids
},
{
q: title
}
]
}, {
relations: ["categories"],
skip,
take
})
// do something with the products or return them
}
Parameters
filters
FilterableProductPropsconfig
FindConfig<ProductDTO>select
or relations
, accept the attributes or relations associated with a product.sharedContext
ContextReturns
listAndCountCategories
This method is used to retrieve a paginated list of product categories along with the total count of available product categories satisfying the provided filters.
Example
To retrieve a list of product categories using their IDs:
import {
initialize as initializeProductModule,
} from "@medusajs/product"
async function retrieveCategories (ids: string[]) {
const productModule = await initializeProductModule()
const [categories, count] = await productModule.listAndCountCategories({
id: ids
})
// do something with the product category or return it
}
To specify relations that should be retrieved within the product categories:
import {
initialize as initializeProductModule,
} from "@medusajs/product"
async function retrieveCategories (ids: string[]) {
const productModule = await initializeProductModule()
const [categories, count] = await productModule.listAndCountCategories({
id: ids
}, {
relations: ["parent_category"]
})
// do something with the product category or return it
}
By default, only the first 15
records are retrieved. You can control pagination by specifying the skip
and take
properties of the config
parameter:
import {
initialize as initializeProductModule,
} from "@medusajs/product"
async function retrieveCategories (ids: string[], skip: number, take: number) {
const productModule = await initializeProductModule()
const [categories, count] = await productModule.listAndCountCategories({
id: ids
}, {
relations: ["parent_category"],
skip,
take
})
// do something with the product category or return it
}
You can also use the $and
or $or
properties of the filter
parameter to use and/or conditions in your filters. For example:
import {
initialize as initializeProductModule,
} from "@medusajs/product"
async function retrieveCategories (ids: string[], name: string, skip: number, take: number) {
const productModule = await initializeProductModule()
const [categories, count] = await productModule.listAndCountCategories({
$or: [
{
id: ids
},
{
name
}
]
}, {
relations: ["parent_category"],
skip,
take
})
// do something with the product category or return it
}
Parameters
config
FindConfig<ProductCategoryDTO>select
or relations
, accept the attributes or relations associated with a product category.sharedContext
ContextReturns
listAndCountCollections
This method is used to retrieve a paginated list of product collections along with the total count of available product collections satisfying the provided filters.
Example
To retrieve a list of product collections using their IDs:
import {
initialize as initializeProductModule,
} from "@medusajs/product"
async function retrieveCollections (ids: string[]) {
const productModule = await initializeProductModule()
const [collections, count] = await productModule.listAndCountCollections({
id: ids
})
// do something with the product collections or return them
}
To specify relations that should be retrieved within the product collections:
import {
initialize as initializeProductModule,
} from "@medusajs/product"
async function retrieveCollections (ids: string[]) {
const productModule = await initializeProductModule()
const [collections, count] = await productModule.listAndCountCollections({
id: ids
}, {
relations: ["products"]
})
// do something with the product collections or return them
}
By default, only the first 15
records are retrieved. You can control pagination by specifying the skip
and take
properties of the config
parameter:
import {
initialize as initializeProductModule,
} from "@medusajs/product"
async function retrieveCollections (ids: string[], skip: number, take: number) {
const productModule = await initializeProductModule()
const [collections, count] = await productModule.listAndCountCollections({
id: ids
}, {
relations: ["products"],
skip,
take
})
// do something with the product collections or return them
}
You can also use the $and
or $or
properties of the filter
parameter to use and/or conditions in your filters. For example:
import {
initialize as initializeProductModule,
} from "@medusajs/product"
async function retrieveCollections (ids: string[], title: string, skip: number, take: number) {
const productModule = await initializeProductModule()
const [collections, count] = await productModule.listAndCountCollections({
$and: [
{
id: ids
},
{
title
}
]
}, {
relations: ["products"],
skip,
take
})
// do something with the product collections or return them
}
Parameters
config
FindConfig<ProductCollectionDTO>select
or relations
, accept the attributes or relations associated with a product collection.sharedContext
ContextReturns
listAndCountOptions
This method is used to retrieve a paginated list of product options along with the total count of available product options satisfying the provided filters.
Example
To retrieve a list of product options using their IDs:
import {
initialize as initializeProductModule,
} from "@medusajs/product"
async function retrieveProductOptions (ids: string[]) {
const productModule = await initializeProductModule()
const [productOptions, count] = await productModule.listAndCountOptions({
id: ids
})
// do something with the product options or return them
}
To specify relations that should be retrieved within the product types:
import {
initialize as initializeProductModule,
} from "@medusajs/product"
async function retrieveProductOptions (ids: string[]) {
const productModule = await initializeProductModule()
const [productOptions, count] = await productModule.listAndCountOptions({
id: ids
}, {
relations: ["product"]
})
// do something with the product options or return them
}
By default, only the first 15
records are retrieved. You can control pagination by specifying the skip
and take
properties of the config
parameter:
import {
initialize as initializeProductModule,
} from "@medusajs/product"
async function retrieveProductOptions (ids: string[], skip: number, take: number) {
const productModule = await initializeProductModule()
const [productOptions, count] = await productModule.listAndCountOptions({
id: ids
}, {
relations: ["product"],
skip,
take
})
// do something with the product options or return them
}
You can also use the $and
or $or
properties of the filter
parameter to use and/or conditions in your filters. For example:
import {
initialize as initializeProductModule,
} from "@medusajs/product"
async function retrieveProductOptions (ids: string[], title: string, skip: number, take: number) {
const productModule = await initializeProductModule()
const [productOptions, count] = await productModule.listAndCountOptions({
$and: [
{
id: ids
},
{
title
}
]
}, {
relations: ["product"],
skip,
take
})
// do something with the product options or return them
}
Parameters
filters
FilterableProductOptionPropsconfig
FindConfig<ProductOptionDTO>select
or relations
, accept the attributes or relations associated with a product option.sharedContext
ContextReturns
listAndCountTags
This method is used to retrieve a paginated list of product tags along with the total count of available product tags satisfying the provided filters.
Example
To retrieve a list of product tags using their IDs:
import {
initialize as initializeProductModule,
} from "@medusajs/product"
async function retrieveProductTag (tagIds: string[]) {
const productModule = await initializeProductModule()
const [productTags, count] = await productModule.listAndCountTags({
id: tagIds
})
// do something with the product tags or return them
}
To specify relations that should be retrieved within the product tags:
import {
initialize as initializeProductModule,
} from "@medusajs/product"
async function retrieveProductTag (tagIds: string[]) {
const productModule = await initializeProductModule()
const [productTags, count] = await productModule.listAndCountTags({
id: tagIds
}, {
relations: ["products"]
})
// do something with the product tags or return them
}
By default, only the first 15
records are retrieved. You can control pagination by specifying the skip
and take
properties of the config
parameter:
import {
initialize as initializeProductModule,
} from "@medusajs/product"
async function retrieveProductTag (tagIds: string[], skip: number, take: number) {
const productModule = await initializeProductModule()
const [productTags, count] = await productModule.listAndCountTags({
id: tagIds
}, {
relations: ["products"],
skip,
take
})
// do something with the product tags or return them
}
You can also use the $and
or $or
properties of the filter
parameter to use and/or conditions in your filters. For example:
import {
initialize as initializeProductModule,
} from "@medusajs/product"
async function retrieveProductTag (tagIds: string[], value: string, skip: number, take: number) {
const productModule = await initializeProductModule()
const [productTags, count] = await productModule.listAndCountTags({
$and: [
{
id: tagIds
},
{
value
}
]
}, {
relations: ["products"],
skip,
take
})
// do something with the product tags or return them
}
Parameters
filters
FilterableProductTagPropsconfig
FindConfig<ProductTagDTO>select
or relations
, accept the attributes or relations associated with a product tag.sharedContext
ContextReturns
listAndCountTypes
This method is used to retrieve a paginated list of product types along with the total count of available product types satisfying the provided filters.
Example
To retrieve a list of product types using their IDs:
import {
initialize as initializeProductModule,
} from "@medusajs/product"
async function retrieveProductTypes (ids: string[]) {
const productModule = await initializeProductModule()
const [productTypes, count] = await productModule.listAndCountTypes({
id: ids
})
// do something with the product types or return them
}
To specify attributes that should be retrieved within the product types:
import {
initialize as initializeProductModule,
} from "@medusajs/product"
async function retrieveProductTypes (ids: string[]) {
const productModule = await initializeProductModule()
const [productTypes, count] = await productModule.listAndCountTypes({
id: ids
}, {
select: ["value"]
})
// do something with the product types or return them
}
By default, only the first 15
records are retrieved. You can control pagination by specifying the skip
and take
properties of the config
parameter:
import {
initialize as initializeProductModule,
} from "@medusajs/product"
async function retrieveProductTypes (ids: string[], skip: number, take: number) {
const productModule = await initializeProductModule()
const [productTypes, count] = await productModule.listAndCountTypes({
id: ids
}, {
select: ["value"],
skip,
take
})
// do something with the product types or return them
}
You can also use the $and
or $or
properties of the filter
parameter to use and/or conditions in your filters. For example:
import {
initialize as initializeProductModule,
} from "@medusajs/product"
async function retrieveProductTypes (ids: string[], value: string, skip: number, take: number) {
const productModule = await initializeProductModule()
const [productTypes, count] = await productModule.listAndCountTypes({
$and: [
{
id: ids
},
{
value
}
]
}, {
select: ["value"],
skip,
take
})
// do something with the product types or return them
}
Parameters
filters
FilterableProductTypePropsconfig
FindConfig<ProductTypeDTO>select
or relations
, accept the attributes or relations associated with a product type.sharedContext
ContextReturns
listAndCountVariants
This method is used to retrieve a paginated list of product variants along with the total count of available product variants satisfying the provided filters.
Example
To retrieve a list of product variants using their IDs:
import {
initialize as initializeProductModule,
} from "@medusajs/product"
async function retrieveProductVariants (ids: string[]) {
const productModule = await initializeProductModule()
const [variants, count] = await productModule.listAndCountVariants({
id: ids
})
// do something with the product variants or return them
}
To specify relations that should be retrieved within the product variants:
import {
initialize as initializeProductModule,
} from "@medusajs/product"
async function retrieveProductVariants (ids: string[]) {
const productModule = await initializeProductModule()
const [variants, count] = await productModule.listAndCountVariants({
id: ids
}, {
relations: ["options"]
})
// do something with the product variants or return them
}
By default, only the first 15
records are retrieved. You can control pagination by specifying the skip
and take
properties of the config
parameter:
import {
initialize as initializeProductModule,
} from "@medusajs/product"
async function retrieveProductVariants (ids: string[], skip: number, take: number) {
const productModule = await initializeProductModule()
const [variants, count] = await productModule.listAndCountVariants({
id: ids
}, {
relations: ["options"],
skip,
take
})
// do something with the product variants or return them
}
You can also use the $and
or $or
properties of the filter
parameter to use and/or conditions in your filters. For example:
import {
initialize as initializeProductModule,
} from "@medusajs/product"
async function retrieveProductVariants (ids: string[], sku: string, skip: number, take: number) {
const productModule = await initializeProductModule()
const [variants, count] = await productModule.listAndCountVariants({
$and: [
{
id: ids
},
{
sku
}
]
}, {
relations: ["options"],
skip,
take
})
// do something with the product variants or return them
}
Parameters
config
FindConfig<ProductVariantDTO>select
or relations
, accept the attributes or relations associated with a product variant.sharedContext
ContextReturns
listCategories
This method is used to retrieve a paginated list of product categories based on optional filters and configuration.
Example
To retrieve a list of product categories using their IDs:
import {
initialize as initializeProductModule,
} from "@medusajs/product"
async function retrieveCategories (ids: string[]) {
const productModule = await initializeProductModule()
const categories = await productModule.listCategories({
id: ids
})
// do something with the product category or return it
}
To specify relations that should be retrieved within the product categories:
import {
initialize as initializeProductModule,
} from "@medusajs/product"
async function retrieveCategories (ids: string[]) {
const productModule = await initializeProductModule()
const categories = await productModule.listCategories({
id: ids
}, {
relations: ["parent_category"]
})
// do something with the product category or return it
}
By default, only the first 15
records are retrieved. You can control pagination by specifying the skip
and take
properties of the config
parameter:
import {
initialize as initializeProductModule,
} from "@medusajs/product"
async function retrieveCategories (ids: string[], skip: number, take: number) {
const productModule = await initializeProductModule()
const categories = await productModule.listCategories({
id: ids
}, {
relations: ["parent_category"],
skip,
take
})
// do something with the product category or return it
}
You can also use the $and
or $or
properties of the filter
parameter to use and/or conditions in your filters. For example:
import {
initialize as initializeProductModule,
} from "@medusajs/product"
async function retrieveCategories (ids: string[], name: string, skip: number, take: number) {
const productModule = await initializeProductModule()
const categories = await productModule.listCategories({
$or: [
{
id: ids
},
{
name
}
]
}, {
relations: ["parent_category"],
skip,
take
})
// do something with the product category or return it
}
Parameters
config
FindConfig<ProductCategoryDTO>select
or relations
, accept the attributes or relations associated with a product category.sharedContext
ContextReturns
listCollections
This method is used to retrieve a paginated list of product collections based on optional filters and configuration.
Example
To retrieve a list of product collections using their IDs:
import {
initialize as initializeProductModule,
} from "@medusajs/product"
async function retrieveCollections (ids: string[]) {
const productModule = await initializeProductModule()
const collections = await productModule.listCollections({
id: ids
})
// do something with the product collections or return them
}
To specify relations that should be retrieved within the product collections:
import {
initialize as initializeProductModule,
} from "@medusajs/product"
async function retrieveCollections (ids: string[]) {
const productModule = await initializeProductModule()
const collections = await productModule.listCollections({
id: ids
}, {
relations: ["products"]
})
// do something with the product collections or return them
}
By default, only the first 15
records are retrieved. You can control pagination by specifying the skip
and take
properties of the config
parameter:
import {
initialize as initializeProductModule,
} from "@medusajs/product"
async function retrieveCollections (ids: string[], skip: number, take: number) {
const productModule = await initializeProductModule()
const collections = await productModule.listCollections({
id: ids
}, {
relations: ["products"],
skip,
take
})
// do something with the product collections or return them
}
You can also use the $and
or $or
properties of the filter
parameter to use and/or conditions in your filters. For example:
import {
initialize as initializeProductModule,
} from "@medusajs/product"
async function retrieveCollections (ids: string[], title: string, skip: number, take: number) {
const productModule = await initializeProductModule()
const collections = await productModule.listCollections({
$and: [
{
id: ids
},
{
title
}
]
}, {
relations: ["products"],
skip,
take
})
// do something with the product collections or return them
}
Parameters
config
FindConfig<ProductCollectionDTO>select
or relations
, accept the attributes or relations associated with a product collection.sharedContext
ContextReturns
listOptions
This method is used to retrieve a paginated list of product options based on optional filters and configuration.
Example
To retrieve a list of product options using their IDs:
import {
initialize as initializeProductModule,
} from "@medusajs/product"
async function retrieveProductOptions (ids: string[]) {
const productModule = await initializeProductModule()
const productOptions = await productModule.listOptions({
id: ids
})
// do something with the product options or return them
}
To specify relations that should be retrieved within the product types:
import {
initialize as initializeProductModule,
} from "@medusajs/product"
async function retrieveProductOptions (ids: string[]) {
const productModule = await initializeProductModule()
const productOptions = await productModule.listOptions({
id: ids
}, {
relations: ["product"]
})
// do something with the product options or return them
}
By default, only the first 15
records are retrieved. You can control pagination by specifying the skip
and take
properties of the config
parameter:
import {
initialize as initializeProductModule,
} from "@medusajs/product"
async function retrieveProductOptions (ids: string[], skip: number, take: number) {
const productModule = await initializeProductModule()
const productOptions = await productModule.listOptions({
id: ids
}, {
relations: ["product"],
skip,
take
})
// do something with the product options or return them
}
You can also use the $and
or $or
properties of the filter
parameter to use and/or conditions in your filters. For example:
import {
initialize as initializeProductModule,
} from "@medusajs/product"
async function retrieveProductOptions (ids: string[], title: string, skip: number, take: number) {
const productModule = await initializeProductModule()
const productOptions = await productModule.listOptions({
$and: [
{
id: ids
},
{
title
}
]
}, {
relations: ["product"],
skip,
take
})
// do something with the product options or return them
}
Parameters
filters
FilterableProductOptionPropsconfig
FindConfig<ProductOptionDTO>select
or relations
, accept the attributes or relations associated with a product option.sharedContext
ContextReturns
listTags
This method is used to retrieve a paginated list of tags based on optional filters and configuration.
Example
To retrieve a list of product tags using their IDs:
import {
initialize as initializeProductModule,
} from "@medusajs/product"
async function retrieveProductTag (tagIds: string[]) {
const productModule = await initializeProductModule()
const productTags = await productModule.listTags({
id: tagIds
})
// do something with the product tags or return them
}
To specify relations that should be retrieved within the product tags:
import {
initialize as initializeProductModule,
} from "@medusajs/product"
async function retrieveProductTag (tagIds: string[]) {
const productModule = await initializeProductModule()
const productTags = await productModule.listTags({
id: tagIds
}, {
relations: ["products"]
})
// do something with the product tags or return them
}
By default, only the first 15
records are retrieved. You can control pagination by specifying the skip
and take
properties of the config
parameter:
import {
initialize as initializeProductModule,
} from "@medusajs/product"
async function retrieveProductTag (tagIds: string[], skip: number, take: number) {
const productModule = await initializeProductModule()
const productTags = await productModule.listTags({
id: tagIds
}, {
relations: ["products"],
skip,
take
})
// do something with the product tags or return them
}
You can also use the $and
or $or
properties of the filter
parameter to use and/or conditions in your filters. For example:
import {
initialize as initializeProductModule,
} from "@medusajs/product"
async function retrieveProductTag (tagIds: string[], value: string, skip: number, take: number) {
const productModule = await initializeProductModule()
const productTags = await productModule.listTags({
$and: [
{
id: tagIds
},
{
value
}
]
}, {
relations: ["products"],
skip,
take
})
// do something with the product tags or return them
}
Parameters
filters
FilterableProductTagPropsconfig
FindConfig<ProductTagDTO>select
or relations
, accept the attributes or relations associated with a product tag.sharedContext
ContextReturns
listTypes
This method is used to retrieve a paginated list of product types based on optional filters and configuration.
Example
To retrieve a list of product types using their IDs:
To specify attributes that should be retrieved within the product types:
import {
initialize as initializeProductModule,
} from "@medusajs/product"
async function retrieveProductTypes (ids: string[]) {
const productModule = await initializeProductModule()
const productTypes = await productModule.listTypes({
id: ids
}, {
select: ["value"]
})
// do something with the product types or return them
}
By default, only the first 15
records are retrieved. You can control pagination by specifying the skip
and take
properties of the config
parameter:
import {
initialize as initializeProductModule,
} from "@medusajs/product"
async function retrieveProductTypes (ids: string[], skip: number, take: number) {
const productModule = await initializeProductModule()
const productTypes = await productModule.listTypes({
id: ids
}, {
select: ["value"],
skip,
take
})
// do something with the product types or return them
}
You can also use the $and
or $or
properties of the filter
parameter to use and/or conditions in your filters. For example:
import {
initialize as initializeProductModule,
} from "@medusajs/product"
async function retrieveProductTypes (ids: string[], value: string, skip: number, take: number) {
const productModule = await initializeProductModule()
const productTypes = await productModule.listTypes({
$and: [
{
id: ids
},
{
value
}
]
}, {
select: ["value"],
skip,
take
})
// do something with the product types or return them
}
Parameters
filters
FilterableProductTypePropsconfig
FindConfig<ProductTypeDTO>select
or relations
, accept the attributes or relations associated with a product type.sharedContext
ContextReturns
listVariants
This method is used to retrieve a paginated list of product variants based on optional filters and configuration.
Example
To retrieve a list of product variants using their IDs:
import {
initialize as initializeProductModule,
} from "@medusajs/product"
async function retrieveProductVariants (ids: string[]) {
const productModule = await initializeProductModule()
const variants = await productModule.listVariants({
id: ids
})
// do something with the product variants or return them
}
To specify relations that should be retrieved within the product variants:
import {
initialize as initializeProductModule,
} from "@medusajs/product"
async function retrieveProductVariants (ids: string[]) {
const productModule = await initializeProductModule()
const variants = await productModule.listVariants({
id: ids
}, {
relations: ["options"]
})
// do something with the product variants or return them
}
By default, only the first 15
records are retrieved. You can control pagination by specifying the skip
and take
properties of the config
parameter:
import {
initialize as initializeProductModule,
} from "@medusajs/product"
async function retrieveProductVariants (ids: string[], skip: number, take: number) {
const productModule = await initializeProductModule()
const variants = await productModule.listVariants({
id: ids
}, {
relations: ["options"],
skip,
take
})
// do something with the product variants or return them
}
You can also use the $and
or $or
properties of the filter
parameter to use and/or conditions in your filters. For example:
import {
initialize as initializeProductModule,
} from "@medusajs/product"
async function retrieveProductVariants (ids: string[], sku: string, skip: number, take: number) {
const productModule = await initializeProductModule()
const variants = await productModule.listVariants({
$and: [
{
id: ids
},
{
sku
}
]
}, {
relations: ["options"],
skip,
take
})
// do something with the product variants or return them
}
Parameters
config
FindConfig<ProductVariantDTO>select
or relations
, accept the attributes or relations associated with a product variant.sharedContext
ContextReturns
restore
This method is used to restore products which were deleted using the softDelete method.
Example
import {
initialize as initializeProductModule,
} from "@medusajs/product"
async function restoreProducts (ids: string[]) {
const productModule = await initializeProductModule()
const cascadedEntities = await productModule.restore(ids, {
returnLinkableKeys: ["variant_id"]
})
// do something with the returned cascaded entity IDs or return them
}
Parameters
productIds
string[]Requiredconfig
RestoreReturn<TReturnableLinkableKeys>returnLinkableKeys
property any of the product's relation attribute names, such as variant_id
.sharedContext
ContextReturns
Promise
Promise<void | Record<string, string[]>>Requiredvariant_id
, and its value is an array of strings, each being the ID of the record associated with the product through this relation, such as the IDs of associated product variants.
If there are no related records that were restored, the promise resolved to void
.restoreVariants
Parameters
Returns
Promise
Promise<void | Record<string, string[]>>Requiredretrieve
This method is used to retrieve a product by its ID
Example
A simple example that retrieves a product by its ID:
To specify relations that should be retrieved:
Parameters
productId
stringRequiredconfig
FindConfig<ProductDTO>select
or relations
, accept the attributes or relations associated with a product.sharedContext
ContextReturns
retrieveCategory
This method is used to retrieve a product category by its ID.
Example
A simple example that retrieves a product category by its ID:
To specify relations that should be retrieved:
import {
initialize as initializeProductModule,
} from "@medusajs/product"
async function retrieveCategory (id: string) {
const productModule = await initializeProductModule()
const category = await productModule.retrieveCategory(id, {
relations: ["parent_category"]
})
// do something with the product category or return it
}
Parameters
productCategoryId
stringRequiredconfig
FindConfig<ProductCategoryDTO>select
or relations
, accept the attributes or relations associated with a product category.sharedContext
ContextReturns
retrieveCollection
This method is used to retrieve a product collection by its ID.
Example
A simple example that retrieves a product collection by its ID:
To specify relations that should be retrieved:
import {
initialize as initializeProductModule,
} from "@medusajs/product"
async function retrieveCollection (id: string) {
const productModule = await initializeProductModule()
const collection = await productModule.retrieveCollection(id, {
relations: ["products"]
})
// do something with the product collection or return it
}
Parameters
productCollectionId
stringRequiredconfig
FindConfig<ProductCollectionDTO>select
or relations
, accept the attributes or relations associated with a product collection.sharedContext
ContextReturns
retrieveOption
This method is used to retrieve a product option by its ID.
Example
A simple example that retrieves a product option by its ID:
To specify relations that should be retrieved:
import {
initialize as initializeProductModule,
} from "@medusajs/product"
async function retrieveProductOption (id: string) {
const productModule = await initializeProductModule()
const productOption = await productModule.retrieveOption(id, {
relations: ["product"]
})
// do something with the product option or return it
}
Parameters
optionId
stringRequiredconfig
FindConfig<ProductOptionDTO>select
or relations
, accept the attributes or relations associated with a product option.sharedContext
ContextReturns
retrieveTag
This method is used to retrieve a tag by its ID.
Example
A simple example that retrieves a product tag by its ID:
To specify relations that should be retrieved:
import {
initialize as initializeProductModule,
} from "@medusajs/product"
async function retrieveProductTag (tagId: string) {
const productModule = await initializeProductModule()
const productTag = await productModule.retrieveTag(tagId, {
relations: ["products"]
})
// do something with the product tag or return it
}
Parameters
tagId
stringRequiredconfig
FindConfig<ProductTagDTO>select
or relations
, accept the attributes or relations associated with a product tag.sharedContext
ContextReturns
retrieveType
This method is used to retrieve a product type by its ID.
Example
A simple example that retrieves a product type by its ID:
To specify attributes that should be retrieved:
import {
initialize as initializeProductModule,
} from "@medusajs/product"
async function retrieveProductType (id: string) {
const productModule = await initializeProductModule()
const productType = await productModule.retrieveType(id, {
select: ["value"]
})
// do something with the product type or return it
}
Parameters
typeId
stringRequiredconfig
FindConfig<ProductTypeDTO>select
or relations
, accept the attributes or relations associated with a product type.sharedContext
ContextReturns
retrieveVariant
This method is used to retrieve a product variant by its ID.
Example
A simple example that retrieves a product variant by its ID:
To specify relations that should be retrieved:
import {
initialize as initializeProductModule,
} from "@medusajs/product"
async function retrieveProductVariant (id: string) {
const productModule = await initializeProductModule()
const variant = await productModule.retrieveVariant(id, {
relations: ["options"]
})
// do something with the product variant or return it
}
Parameters
productVariantId
stringRequiredconfig
FindConfig<ProductVariantDTO>select
or relations
, accept the attributes or relations associated with a product variant.sharedContext
ContextReturns
softDelete
This method is used to delete products. Unlike the delete method, this method won't completely remove the product. It can still be accessed or retrieved using methods like retrieve if you pass the withDeleted
property to the config
object parameter.
The soft-deleted products can be restored using the restore method.
Example
import {
initialize as initializeProductModule,
} from "@medusajs/product"
async function deleteProducts (ids: string[]) {
const productModule = await initializeProductModule()
const cascadedEntities = await productModule.softDelete(ids)
// do something with the returned cascaded entity IDs or return them
}
Parameters
productIds
string[]Requiredconfig
SoftDeleteReturn<TReturnableLinkableKeys>returnLinkableKeys
property any of the product's relation attribute names, such as variant_id
.sharedContext
ContextReturns
Promise
Promise<void | Record<string, string[]>>Requiredvariant_id
, and its value is an array of strings, each being the ID of a record associated with the product through this relation, such as the IDs of associated product variants.
If there are no related records, the promise resolved to void
.update
This method is used to update a product.
Example
Parameters
sharedContext
ContextReturns
updateCategory
This method is used to update a product category by its ID.
Example
import {
initialize as initializeProductModule,
} from "@medusajs/product"
async function updateCategory (id: string, name: string) {
const productModule = await initializeProductModule()
const category = await productModule.updateCategory(id, {
name,
})
// do something with the product category or return it
}
Parameters
categoryId
stringRequiredsharedContext
ContextReturns
updateCollections
This method is used to update existing product collections.
Example
import {
initialize as initializeProductModule,
} from "@medusajs/product"
async function updateCollection (id: string, title: string) {
const productModule = await initializeProductModule()
const collections = await productModule.updateCollections([
{
id,
title
}
])
// do something with the product collections or return them
}
Parameters
sharedContext
ContextReturns
updateOptions
This method is used to update existing product options.
Example
import {
initialize as initializeProductModule,
} from "@medusajs/product"
async function updateProductOption (id: string, title: string) {
const productModule = await initializeProductModule()
const productOptions = await productModule.updateOptions([
{
id,
title
}
])
// do something with the product options or return them
}
Parameters
sharedContext
ContextReturns
updateTags
This method is used to update existing product tags.
Example
import {
initialize as initializeProductModule,
} from "@medusajs/product"
async function updateProductTag (id: string, value: string) {
const productModule = await initializeProductModule()
const productTags = await productModule.updateTags([
{
id,
value
}
])
// do something with the product tags or return them
}
Parameters
sharedContext
ContextReturns
updateTypes
This method is used to update a product type
Example
import {
initialize as initializeProductModule,
} from "@medusajs/product"
async function updateProductType (id: string, value: string) {
const productModule = await initializeProductModule()
const productTypes = await productModule.updateTypes([
{
id,
value
}
])
// do something with the product types or return them
}
Parameters
sharedContext
Context