Class: ProductService
Hierarchy
TransactionBaseService
↳
ProductService
Constructors
constructor
• new ProductService(__namedParameters
)
Parameters
Name | Type |
---|---|
__namedParameters | InjectedDependencies |
Overrides
TransactionBaseService.constructor
Defined in
medusa/src/services/product.ts:79
Properties
__configModule__
• Protected
Optional
Readonly
__configModule__: Record
<string
, unknown
>
Inherited from
TransactionBaseService.__configModule__
Defined in
medusa/src/interfaces/transaction-base-service.ts:14
__container__
• Protected
Readonly
__container__: any
Inherited from
TransactionBaseService.__container__
Defined in
medusa/src/interfaces/transaction-base-service.ts:13
__moduleDeclaration__
• Protected
Optional
Readonly
__moduleDeclaration__: Record
<string
, unknown
>
Inherited from
TransactionBaseService.__moduleDeclaration__
Defined in
medusa/src/interfaces/transaction-base-service.ts:15
eventBus_
• Protected
Readonly
eventBus_: EventBusService
Defined in
medusa/src/services/product.ts:69
featureFlagRouter_
• Protected
Readonly
featureFlagRouter_: FlagRouter
Defined in
medusa/src/services/product.ts:70
imageRepository_
• Protected
Readonly
imageRepository_: Repository
<Image
> & { insertBulk
: (data
: _QueryDeepPartialEntity
<Image
>[]) => Promise
<Image
[]> ; upsertImages
: (imageUrls
: string
[]) => Promise
<Image
[]> }
Defined in
medusa/src/services/product.ts:64
manager_
• Protected
manager_: EntityManager
Inherited from
TransactionBaseService.manager_
Defined in
medusa/src/interfaces/transaction-base-service.ts:5
productCategoryRepository_
• Protected
Readonly
productCategoryRepository_: TreeRepository
<ProductCategory
> & { addProducts
: (productCategoryId
: string
, productIds
: string
[]) => Promise
<void
> ; findOneWithDescendants
: (query
: FindOneOptions
<ProductCategory
>, treeScope
: QuerySelector
<ProductCategory
>) => Promise
<null
| ProductCategory
> ; getFreeTextSearchResultsAndCount
: (options
: ExtendedFindConfig
<ProductCategory
>, q?
: string
, treeScope
: QuerySelector
<ProductCategory
>, includeTree
: boolean
) => Promise
<[ProductCategory
[], number
]> ; removeProducts
: (productCategoryId
: string
, productIds
: string
[]) => Promise
<DeleteResult
> }
Defined in
medusa/src/services/product.ts:66
productOptionRepository_
• Protected
Readonly
productOptionRepository_: Repository
<ProductOption
>
Defined in
medusa/src/services/product.ts:59
productRepository_
• Protected
Readonly
productRepository_: Repository
<Product
> & { _applyCategoriesQuery
: (qb
: SelectQueryBuilder
<Product
>, __namedParameters
: Object
) => SelectQueryBuilder
<Product
> ; _findWithRelations
: (__namedParameters
: { idsOrOptionsWithoutRelations
: string
[] | FindWithoutRelationsOptions
; relations
: string
[] ; shouldCount
: boolean
; withDeleted
: boolean
}) => Promise
<[Product
[], number
]> ; bulkAddToCollection
: (productIds
: string
[], collectionId
: string
) => Promise
<Product
[]> ; bulkRemoveFromCollection
: (productIds
: string
[], collectionId
: string
) => Promise
<Product
[]> ; findOneWithRelations
: (relations
: string
[], optionsWithoutRelations
: FindWithoutRelationsOptions
) => Promise
<Product
> ; findWithRelations
: (relations
: string
[], idsOrOptionsWithoutRelations
: string
[] | FindWithoutRelationsOptions
, withDeleted
: boolean
) => Promise
<Product
[]> ; findWithRelationsAndCount
: (relations
: string
[], idsOrOptionsWithoutRelations
: FindWithoutRelationsOptions
) => Promise
<[Product
[], number
]> ; getFreeTextSearchResultsAndCount
: (q
: string
, options
: FindWithoutRelationsOptions
, relations
: string
[]) => Promise
<[Product
[], number
]> ; isProductInSalesChannels
: (id
: string
, salesChannelIds
: string
[]) => Promise
<boolean
> ; queryProducts
: (optionsWithoutRelations
: FindWithoutRelationsOptions
, shouldCount
: boolean
) => Promise
<[Product
[], number
]> ; queryProductsWithIds
: (__namedParameters
: { entityIds
: string
[] ; groupedRelations
: { [toplevel: string]
: string
[]; } ; order?
: { [column: string]
: "ASC"
| "DESC"
; } ; select?
: keyof Product
[] ; where?
: FindOptionsWhere
<Product
> ; withDeleted?
: boolean
}) => Promise
<Product
[]> ; upsertShippingProfile
: (productIds
: string
[], shippingProfileId
: string
) => Promise
<Product
[]> }
Defined in
medusa/src/services/product.ts:60
productTagRepository_
• Protected
Readonly
productTagRepository_: Repository
<ProductTag
> & { findAndCountByDiscountConditionId
: (conditionId
: string
, query
: ExtendedFindConfig
<ProductTag
>) => Promise
<[ProductTag
[], number
]> ; insertBulk
: (data
: _QueryDeepPartialEntity
<ProductTag
>[]) => Promise
<ProductTag
[]> ; listTagsByUsage
: (take
: number
) => Promise
<ProductTag
[]> ; upsertTags
: (tags
: UpsertTagsInput
) => Promise
<ProductTag
[]> }
Defined in
medusa/src/services/product.ts:63
productTypeRepository_
• Protected
Readonly
productTypeRepository_: Repository
<ProductType
> & { findAndCountByDiscountConditionId
: (conditionId
: string
, query
: ExtendedFindConfig
<ProductType
>) => Promise
<[ProductType
[], number
]> ; upsertType
: (type?
: UpsertTypeInput
) => Promise
<null
| ProductType
> }
Defined in
medusa/src/services/product.ts:62
productVariantRepository_
• Protected
Readonly
productVariantRepository_: Repository
<ProductVariant
>
Defined in
medusa/src/services/product.ts:61
productVariantService_
• Protected
Readonly
productVariantService_: ProductVariantService
Defined in
medusa/src/services/product.ts:67
searchService_
• Protected
Readonly
searchService_: SearchService
Defined in
medusa/src/services/product.ts:68
transactionManager_
• Protected
transactionManager_: undefined
| EntityManager
Inherited from
TransactionBaseService.transactionManager_
Defined in
medusa/src/interfaces/transaction-base-service.ts:6
Events
▪ Static
Readonly
Events: Object
Type declaration
Name | Type |
---|---|
CREATED | string |
DELETED | string |
UPDATED | string |
Defined in
medusa/src/services/product.ts:73
IndexName
▪ Static
Readonly
IndexName: "products"
Defined in
medusa/src/services/product.ts:72
Accessors
activeManager_
• Protected
get
activeManager_(): EntityManager
Returns
EntityManager
Inherited from
TransactionBaseService.activeManager_
Defined in
medusa/src/interfaces/transaction-base-service.ts:8
Methods
addOption
▸ addOption(productId
, optionTitle
): Promise
<Product
>
Adds an option to a product. Options can, for example, be "Size", "Color", etc. Will update all the products variants with a dummy value for the newly created option. The same option cannot be added more than once.
Parameters
Name | Type | Description |
---|---|---|
productId | string | the product to apply the new option to |
optionTitle | string | the display title of the option, e.g. "Size" |
Returns
Promise
<Product
>
the result of the model update operation
Defined in
medusa/src/services/product.ts:690
atomicPhase_
▸ Protected
atomicPhase_<TResult
, TError
>(work
, isolationOrErrorHandler?
, maybeErrorHandlerOrDontFail?
): Promise
<TResult
>
Wraps some work within a transactional block. If the service already has a transaction manager attached this will be reused, otherwise a new transaction manager is created.
Type parameters
Name |
---|
TResult |
TError |
Parameters
Name | Type | Description |
---|---|---|
work | (transactionManager : EntityManager ) => Promise <TResult > | the transactional work to be done |
isolationOrErrorHandler? | IsolationLevel | (error : TError ) => Promise <void | TResult > | the isolation level to be used for the work. |
maybeErrorHandlerOrDontFail? | (error : TError ) => Promise <void | TResult > | Potential error handler |
Returns
Promise
<TResult
>
the result of the transactional work
Inherited from
TransactionBaseService.atomicPhase_
Defined in
medusa/src/interfaces/transaction-base-service.ts:56
count
▸ count(selector?
): Promise
<number
>
Return the total number of documents in database
Parameters
Name | Type | Description |
---|---|---|
selector | Selector <Product > | the selector to choose products by |
Returns
Promise
<number
>
the result of the count operation
Defined in
medusa/src/services/product.ts:185
create
▸ create(productObject
): Promise
<Product
>
Creates a product.
Parameters
Name | Type | Description |
---|---|---|
productObject | CreateProductInput | the product to create |
Returns
Promise
<Product
>
resolves to the creation result.
Defined in
medusa/src/services/product.ts:418
delete
▸ delete(productId
): Promise
<void
>
Deletes a product from a given product id. The product's associated variants will also be deleted.
Parameters
Name | Type | Description |
---|---|---|
productId | string | the id of the product to delete. Must be castable as an ObjectId |
Returns
Promise
<void
>
empty promise
Defined in
medusa/src/services/product.ts:651
deleteOption
▸ deleteOption(productId
, optionId
): Promise
<void
| Product
>
Delete an option from a product.
Parameters
Name | Type | Description |
---|---|---|
productId | string | the product to delete an option from |
optionId | string | the option to delete |
Returns
Promise
<void
| Product
>
the updated product
Defined in
medusa/src/services/product.ts:855
filterProductsBySalesChannel
▸ filterProductsBySalesChannel(productIds
, salesChannelId
, config?
): Promise
<Product
[]>
Parameters
Name | Type |
---|---|
productIds | string [] |
salesChannelId | string |
config | FindProductConfig |
Returns
Promise
<Product
[]>
Defined in
medusa/src/services/product.ts:343
isProductInSalesChannels
▸ isProductInSalesChannels(id
, salesChannelIds
): Promise
<boolean
>
Check if the product is assigned to at least one of the provided sales channels.
Parameters
Name | Type | Description |
---|---|---|
id | string | product id |
salesChannelIds | string [] | an array of sales channel ids |
Returns
Promise
<boolean
>
Defined in
medusa/src/services/product.ts:396
list
▸ list(selector
, config?
): Promise
<Product
[]>
Lists products based on the provided parameters.
Parameters
Name | Type | Description |
---|---|---|
selector | ProductSelector | an object that defines rules to filter products by |
config | FindProductConfig | object that defines the scope for what should be returned |
Returns
Promise
<Product
[]>
the result of the find operation
Defined in
medusa/src/services/product.ts:116
listAndCount
▸ listAndCount(selector
, config?
): Promise
<[Product
[], number
]>
Lists products based on the provided parameters and includes the count of products that match the query.
Parameters
Name | Type | Description |
---|---|---|
selector | ProductSelector | an object that defines rules to filter products by |
config | FindProductConfig | object that defines the scope for what should be returned |
Returns
Promise
<[Product
[], number
]>
an array containing the products as the first element and the total count of products that matches the query as the second element.
Defined in
medusa/src/services/product.ts:140
listTagsByUsage
▸ listTagsByUsage(take?
): Promise
<ProductTag
[]>
Parameters
Name | Type | Default value |
---|---|---|
take | number | 10 |
Returns
Promise
<ProductTag
[]>
Defined in
medusa/src/services/product.ts:382
listTypes
▸ listTypes(): Promise
<ProductType
[]>
Returns
Promise
<ProductType
[]>
Defined in
medusa/src/services/product.ts:374
prepareListQuery_
▸ Protected
prepareListQuery_(selector
, config
): Object
Temporary method to be used in place we need custom query strategy to prevent typeorm bug
Parameters
Name | Type |
---|---|
selector | FilterableProductProps | Selector <Product > |
config | FindProductConfig |
Returns
Object
Name | Type |
---|---|
q | string |
query | FindWithoutRelationsOptions |
relations | keyof Product [] |
Defined in
medusa/src/services/product.ts:951
reorderVariants
▸ reorderVariants(productId
, variantOrder
): Promise
<Product
>
Parameters
Name | Type |
---|---|
productId | string |
variantOrder | string [] |
Returns
Promise
<Product
>
Defined in
medusa/src/services/product.ts:733
retrieve
▸ retrieve(productId
, config?
): Promise
<Product
>
Gets a product by id. Throws in case of DB Error and if product was not found.
Parameters
Name | Type | Description |
---|---|---|
productId | string | id of the product to get. |
config | FindProductConfig | object that defines what should be included in the query response |
Returns
Promise
<Product
>
the result of the find one operation.
Defined in
medusa/src/services/product.ts:201
retrieveByExternalId
▸ retrieveByExternalId(externalId
, config?
): Promise
<Product
>
Gets a product by external id. Throws in case of DB Error and if product was not found.
Parameters
Name | Type | Description |
---|---|---|
externalId | string | handle of the product to get. |
config | FindProductConfig | details about what to get from the product |
Returns
Promise
<Product
>
the result of the find one operation.
Defined in
medusa/src/services/product.ts:245
retrieveByHandle
▸ retrieveByHandle(productHandle
, config?
): Promise
<Product
>
Gets a product by handle. Throws in case of DB Error and if product was not found.
Parameters
Name | Type | Description |
---|---|---|
productHandle | string | handle of the product to get. |
config | FindProductConfig | details about what to get from the product |
Returns
Promise
<Product
>
the result of the find one operation.
Defined in
medusa/src/services/product.ts:224
retrieveOptionByTitle
▸ retrieveOptionByTitle(title
, productId
): Promise
<null
| ProductOption
>
Retrieve product's option by title.
Parameters
Name | Type | Description |
---|---|---|
title | string | title of the option |
productId | string | id of a product |
Returns
Promise
<null
| ProductOption
>
product option
Defined in
medusa/src/services/product.ts:836
retrieveVariants
▸ retrieveVariants(productId
, config?
): Promise
<ProductVariant
[]>
Gets all variants belonging to a product.
Parameters
Name | Type | Description |
---|---|---|
productId | string | the id of the product to get variants from. |
config | FindProductConfig | The config to select and configure relations etc... |
Returns
Promise
<ProductVariant
[]>
an array of variants
Defined in
medusa/src/services/product.ts:325
retrieve_
▸ retrieve_(selector
, config?
): Promise
<Product
>
Gets a product by selector. Throws in case of DB Error and if product was not found.
Parameters
Name | Type | Description |
---|---|---|
selector | Selector <Product > | selector object |
config | FindProductConfig | object that defines what should be included in the query response |
Returns
Promise
<Product
>
the result of the find one operation.
Defined in
medusa/src/services/product.ts:267
shouldRetryTransaction_
▸ Protected
shouldRetryTransaction_(err
): boolean
Parameters
Name | Type |
---|---|
err | Record <string , unknown > | { code : string } |
Returns
boolean
Inherited from
TransactionBaseService.shouldRetryTransaction_
Defined in
medusa/src/interfaces/transaction-base-service.ts:37
update
▸ update(productId
, update
): Promise
<Product
>
Updates a product. Product variant updates should use dedicated methods,
e.g. addVariant
, etc. The function will throw errors if metadata or
product variant updates are attempted.
Parameters
Name | Type | Description |
---|---|---|
productId | string | the id of the product. Must be a string that can be casted to an ObjectId |
update | UpdateProductInput | an object with the update values. |
Returns
Promise
<Product
>
resolves to the update result.
Defined in
medusa/src/services/product.ts:523
updateOption
▸ updateOption(productId
, optionId
, data
): Promise
<Product
>
Updates a product's option. Throws if the call tries to update an option not associated with the product. Throws if the updated title already exists.
Parameters
Name | Type | Description |
---|---|---|
productId | string | the product whose option we are updating |
optionId | string | the id of the option we are updating |
data | ProductOptionInput | the data to update the option with |
Returns
Promise
<Product
>
the updated product
Defined in
medusa/src/services/product.ts:779
updateShippingProfile
▸ updateShippingProfile(productIds
, profileId
): Promise
<Product
[]>
Parameters
Name | Type | Description |
---|---|---|
productIds | string | string [] | ID or IDs of the products to update |
profileId | string | Shipping profile ID to update the shipping options with |
Returns
Promise
<Product
[]>
updated shipping options
Defined in
medusa/src/services/product.ts:926
withTransaction
▸ withTransaction(transactionManager?
): ProductService
Parameters
Name | Type |
---|---|
transactionManager? | EntityManager |
Returns
Inherited from
TransactionBaseService.withTransaction