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
createVariants
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>RequireddeleteVariants
This method is used to delete ProductVariant. This method will completely remove the ProductVariant and they can no longer be accessed or retrieved.
Example
Parameters
productVariantIds
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
}