IProductModuleService
internal.ProductTypes.IProductModuleService
Methods
create
create(data
, sharedContext?
): Promise
<ProductDTO
[]>
This method is used to create a product.
Example
Parameters
sharedContext
ContextReturns
Promise
<ProductDTO
[]>
The list of created products.
createCategory
createCategory(data
, sharedContext?
): Promise
<ProductCategoryDTO
>
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
Promise
<ProductCategoryDTO
>
The created product category.
createCollections
createCollections(data
, sharedContext?
): Promise
<ProductCollectionDTO
[]>
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
Promise
<ProductCollectionDTO
[]>
The list of created product collections.
createOptions
createOptions(data
, sharedContext?
): Promise
<ProductOptionDTO
[]>
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
Promise
<ProductOptionDTO
[]>
The list of created product options.
createTags
createTags(data
, sharedContext?
): Promise
<ProductTagDTO
[]>
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
Promise
<ProductTagDTO
[]>
The list of product tags.
createTypes
createTypes(data
, sharedContext?
): Promise
<ProductTypeDTO
[]>
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
Promise
<ProductTypeDTO
[]>
The list of created product types.
delete
delete(productIds
, sharedContext?
): Promise
<void
>
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
<void
>
Promise
Promise<void>RequireddeleteCategory
deleteCategory(categoryId
, sharedContext?
): Promise
<void
>
This method is used to delete a product category by its ID.
Example
Parameters
categoryId
stringRequiredsharedContext
ContextReturns
Promise
<void
>
Promise
Promise<void>RequireddeleteCollections
deleteCollections(productCollectionIds
, sharedContext?
): Promise
<void
>
This method is used to delete collections by their ID.
Example
Parameters
productCollectionIds
string[]RequiredsharedContext
ContextReturns
Promise
<void
>
Promise
Promise<void>RequireddeleteOptions
deleteOptions(productOptionIds
, sharedContext?
): Promise
<void
>
This method is used to delete a product option.
Example
Parameters
productOptionIds
string[]RequiredsharedContext
ContextReturns
Promise
<void
>
Promise
Promise<void>RequireddeleteTags
deleteTags(productTagIds
, sharedContext?
): Promise
<void
>
This method is used to delete product tags by their ID.
Example
Parameters
productTagIds
string[]RequiredsharedContext
ContextReturns
Promise
<void
>
Promise
Promise<void>RequireddeleteTypes
deleteTypes(productTypeIds
, sharedContext?
): Promise
<void
>
This method is used to delete a product type.
Example
Parameters
productTypeIds
string[]RequiredsharedContext
ContextReturns
Promise
<void
>
Promise
Promise<void>Requiredlist
list(filters?
, config?
, sharedContext?
): Promise
<ProductDTO
[]>
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
Promise
<ProductDTO
[]>
The list of products.
listAndCount
listAndCount(filters?
, config?
, sharedContext?
): Promise
<[ProductDTO
[], number
]>
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
Promise
<[ProductDTO
[], number
]>
The list of products along with the total count.
listAndCountCategories
listAndCountCategories(filters?
, config?
, sharedContext?
): Promise
<[ProductCategoryDTO
[], number
]>
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
Promise
<[ProductCategoryDTO
[], number
]>
The list of product categories along with their total count.
listAndCountCollections
listAndCountCollections(filters?
, config?
, sharedContext?
): Promise
<[ProductCollectionDTO
[], number
]>
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
Promise
<[ProductCollectionDTO
[], number
]>
The list of product collections along with the total count.
listAndCountOptions
listAndCountOptions(filters?
, config?
, sharedContext?
): Promise
<[ProductOptionDTO
[], number
]>
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
Promise
<[ProductOptionDTO
[], number
]>
The list of product options along with the total count.
listAndCountTags
listAndCountTags(filters?
, config?
, sharedContext?
): Promise
<[ProductTagDTO
[], number
]>
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
Promise
<[ProductTagDTO
[], number
]>
The list of product tags along with the total count.
listAndCountTypes
listAndCountTypes(filters?
, config?
, sharedContext?
): Promise
<[ProductTypeDTO
[], number
]>
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
Promise
<[ProductTypeDTO
[], number
]>
The list of product types along with their total count.
listAndCountVariants
listAndCountVariants(filters?
, config?
, sharedContext?
): Promise
<[ProductVariantDTO
[], number
]>
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
Promise
<[ProductVariantDTO
[], number
]>
The list of product variants along with their total count.
listCategories
listCategories(filters?
, config?
, sharedContext?
): Promise
<ProductCategoryDTO
[]>
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
Promise
<ProductCategoryDTO
[]>
The list of product categories.
listCollections
listCollections(filters?
, config?
, sharedContext?
): Promise
<ProductCollectionDTO
[]>
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
Promise
<ProductCollectionDTO
[]>
The list of product collections.
listOptions
listOptions(filters?
, config?
, sharedContext?
): Promise
<ProductOptionDTO
[]>
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
Promise
<ProductOptionDTO
[]>
The list of product options.
listTags
listTags(filters?
, config?
, sharedContext?
): Promise
<ProductTagDTO
[]>
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
Promise
<ProductTagDTO
[]>
The list of product tags.
listTypes
listTypes(filters?
, config?
, sharedContext?
): Promise
<ProductTypeDTO
[]>
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
Promise
<ProductTypeDTO
[]>
The list of product types.
listVariants
listVariants(filters?
, config?
, sharedContext?
): Promise
<ProductVariantDTO
[]>
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
Promise
<ProductVariantDTO
[]>
The list of product variants.
restore
restore<TReturnableLinkableKeys
>(productIds
, config?
, sharedContext?
): Promise
<void
| Record<string
, string
[]>>
This method is used to restore products which were deleted using the softDelete method.
TReturnableLinkableKeys
stringRequiredExample
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
<void
| Record<string
, string
[]>>
Promise
Promise<void | Record<string, string[]>>RequiredAn object that includes the IDs of related records that were restored, such as the ID of associated product variants. The object's keys are the ID attribute names of the product entity's relations, such as variant_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
.
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
restoreVariants<TReturnableLinkableKeys
>(variantIds
, config?
, sharedContext?
): Promise
<void
| Record<string
, string
[]>>
TReturnableLinkableKeys
stringRequiredParameters
Returns
Promise
<void
| Record<string
, string
[]>>
Promise
Promise<void | Record<string, string[]>>Required
Promise
Promise<void | Record<string, string[]>>Requiredretrieve
retrieve(productId
, config?
, sharedContext?
): Promise
<ProductDTO
>
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:
import {
initialize as initializePricingModule,
} from "@medusajs/pricing"
async function retrievePriceSet (priceSetId: string) {
const pricingService = await initializePricingModule()
const priceSet = await pricingService.retrieve(
priceSetId,
{
relations: ["money_amounts"]
}
)
// do something with the price set or return it
}
Parameters
productId
stringRequiredconfig
FindConfig<ProductDTO>select
or relations
, accept the attributes or relations associated with a product.sharedContext
ContextReturns
Promise
<ProductDTO
>
The retrieved product.
retrieveCategory
retrieveCategory(productCategoryId
, config?
, sharedContext?
): Promise
<ProductCategoryDTO
>
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
Promise
<ProductCategoryDTO
>
The retrieved product category.
retrieveCollection
retrieveCollection(productCollectionId
, config?
, sharedContext?
): Promise
<ProductCollectionDTO
>
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
Promise
<ProductCollectionDTO
>
The retrieved product collection.
retrieveOption
retrieveOption(optionId
, config?
, sharedContext?
): Promise
<ProductOptionDTO
>
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
Promise
<ProductOptionDTO
>
The retrieved product option.
retrieveTag
retrieveTag(tagId
, config?
, sharedContext?
): Promise
<ProductTagDTO
>
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
Promise
<ProductTagDTO
>
The retrieved product tag.
retrieveType
retrieveType(typeId
, config?
, sharedContext?
): Promise
<ProductTypeDTO
>
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
Promise
<ProductTypeDTO
>
The retrieved product type.
retrieveVariant
retrieveVariant(productVariantId
, config?
, sharedContext?
): Promise
<ProductVariantDTO
>
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
Promise
<ProductVariantDTO
>
The retrieved product variant.
softDelete
softDelete<TReturnableLinkableKeys
>(productIds
, config?
, sharedContext?
): Promise
<void
| Record<string
, string
[]>>
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.
TReturnableLinkableKeys
stringRequiredExample
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
<void
| Record<string
, string
[]>>
Promise
Promise<void | Record<string, string[]>>RequiredAn object that includes the IDs of related records that were also soft deleted, such as the ID of associated product variants. The object's keys are the ID attribute names of the product entity's relations, such as variant_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
.
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
update(data
, sharedContext?
): Promise
<ProductDTO
[]>
This method is used to update a product.
Example
Parameters
sharedContext
ContextReturns
Promise
<ProductDTO
[]>
The list of updated products.
updateCategory
updateCategory(categoryId
, data
, sharedContext?
): Promise
<ProductCategoryDTO
>
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
Promise
<ProductCategoryDTO
>
The updated product category.
updateCollections
updateCollections(data
, sharedContext?
): Promise
<ProductCollectionDTO
[]>
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
Promise
<ProductCollectionDTO
[]>
The list of updated product collections.
updateOptions
updateOptions(data
, sharedContext?
): Promise
<ProductOptionDTO
[]>
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
Promise
<ProductOptionDTO
[]>
The list of updated product options.
updateTags
updateTags(data
, sharedContext?
): Promise
<ProductTagDTO
[]>
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
Promise
<ProductTagDTO
[]>
The list of updated product tags.
updateTypes
updateTypes(data
, sharedContext?
): Promise
<ProductTypeDTO
[]>
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
ContextReturns
Promise
<ProductTypeDTO
[]>