ProductService
Hierarchy
TransactionBaseService
↳
ProductService
Constructors
constructor
new ProductService(«destructured»
)
Parameters
Name |
---|
«destructured» |
Overrides
TransactionBaseService.constructor
Defined in
medusa/src/services/product.ts:81
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:71
featureFlagRouter_
Protected
Readonly
featureFlagRouter_: FlagRouter
Defined in
medusa/src/services/product.ts:72
imageRepository_
Protected
Readonly
imageRepository_: Repository
<Image
> & { insertBulk
: Method insertBulk ; upsertImages
: Method upsertImages }
Defined in
medusa/src/services/product.ts:66
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
: Method addProducts ; findOneWithDescendants
: Method findOneWithDescendants ; getFreeTextSearchResultsAndCount
: Method getFreeTextSearchResultsAndCount ; removeProducts
: Method removeProducts }
Defined in
medusa/src/services/product.ts:68
productOptionRepository_
Protected
Readonly
productOptionRepository_: Repository
<ProductOption
>
Defined in
medusa/src/services/product.ts:61
productRepository_
Protected
Readonly
productRepository_: Repository
<Product
> & { _applyCategoriesQuery
: Method _applyCategoriesQuery ; _findWithRelations
: Method _findWithRelations ; bulkAddToCollection
: Method bulkAddToCollection ; bulkRemoveFromCollection
: Method bulkRemoveFromCollection ; findOneWithRelations
: Method findOneWithRelations ; findWithRelations
: Method findWithRelations ; findWithRelationsAndCount
: Method findWithRelationsAndCount ; getCategoryIdsFromInput
: Method getCategoryIdsFromInput ; getCategoryIdsRecursively
: Method getCategoryIdsRecursively ; getFreeTextSearchResultsAndCount
: Method getFreeTextSearchResultsAndCount ; isProductInSalesChannels
: Method isProductInSalesChannels ; queryProducts
: Method queryProducts ; queryProductsWithIds
: Method queryProductsWithIds }
Defined in
medusa/src/services/product.ts:62
productTagRepository_
Protected
Readonly
productTagRepository_: Repository
<ProductTag
> & { findAndCountByDiscountConditionId
: Method findAndCountByDiscountConditionId ; insertBulk
: Method insertBulk ; listTagsByUsage
: Method listTagsByUsage ; upsertTags
: Method upsertTags }
Defined in
medusa/src/services/product.ts:65
productTypeRepository_
Protected
Readonly
productTypeRepository_: Repository
<ProductType
> & { findAndCountByDiscountConditionId
: Method findAndCountByDiscountConditionId ; upsertType
: Method upsertType }
Defined in
medusa/src/services/product.ts:64
productVariantRepository_
Protected
Readonly
productVariantRepository_: Repository
<ProductVariant
>
Defined in
medusa/src/services/product.ts:63
productVariantService_
Protected
Readonly
productVariantService_: ProductVariantService
Defined in
medusa/src/services/product.ts:69
searchService_
Protected
Readonly
searchService_: SearchService
Defined in
medusa/src/services/product.ts:70
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:75
IndexName
Static
Readonly
IndexName: "products"
Defined in
medusa/src/services/product.ts:74
Accessors
activeManager_
Protected
get
activeManager_(): EntityManager
Returns
EntityManager
-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 | Description |
---|---|
productId | string |
optionTitle | string |
Returns
Promise
<Product
>
-Promise
: the result of the model update operation
-Product
:
Defined in
medusa/src/services/product.ts:722
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.
Name |
---|
TResult |
TError |
Parameters
Name | Description |
---|---|
work | (transactionManager : EntityManager ) => Promise <TResult > |
isolationOrErrorHandler? | IsolationLevel | (error : TError ) => Promise <void | TResult > |
maybeErrorHandlerOrDontFail? | (error : TError ) => Promise <void | TResult > |
Returns
Promise
<TResult
>
-Promise
: 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 | Description |
---|---|
selector | Selector <Product > |
Returns
Promise
<number
>
-Promise
: the result of the count operation
-number
: (optional)
Defined in
medusa/src/services/product.ts:187
create
create(productObject
): Promise
<Product
>
Creates a product.
Parameters
Name | Description |
---|---|
productObject | CreateProductInput |
Returns
Promise
<Product
>
-Promise
: resolves to the creation result.
-Product
:
Defined in
medusa/src/services/product.ts:420
delete
delete(productId
): Promise
<void
>
Deletes a product from a given product id. The product's associated variants will also be deleted.
Parameters
Name | Description |
---|---|
productId | string |
Returns
Promise
<void
>
-Promise
: empty promise
Defined in
medusa/src/services/product.ts:683
deleteOption
deleteOption(productId
, optionId
): Promise
<void
| Product
>
Delete an option from a product.
Parameters
Name | Description |
---|---|
productId | string |
optionId | string |
Returns
Promise
<void
| Product
>
-Promise
: the updated product
-void \| Product
: (optional)
Defined in
medusa/src/services/product.ts:887
filterProductsBySalesChannel
filterProductsBySalesChannel(productIds
, salesChannelId
, config?
): Promise
<Product
[]>
Parameters
Name |
---|
productIds |
salesChannelId |
config |
Returns
Promise
<Product
[]>
-Promise
:
-Product[]
:
-Product
:
Defined in
medusa/src/services/product.ts:345
isProductInSalesChannels
isProductInSalesChannels(id
, salesChannelIds
): Promise
<boolean
>
Check if the product is assigned to at least one of the provided sales channels.
Parameters
Name | Description |
---|---|
id | string |
salesChannelIds | string [] |
Returns
Promise
<boolean
>
-Promise
:
-boolean
: (optional)
Defined in
medusa/src/services/product.ts:398
list
list(selector
, config?
): Promise
<Product
[]>
Lists products based on the provided parameters.
Parameters
Name | Description |
---|---|
selector | ProductSelector |
config | FindProductConfig |
Returns
Promise
<Product
[]>
-Promise
: the result of the find operation
-Product[]
:
-Product
:
Defined in
medusa/src/services/product.ts:118
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 | Description |
---|---|
selector | ProductSelector |
config | FindProductConfig |
Returns
Promise
<[Product
[], number
]>
-Promise
: an array containing the products as
the first element and the total count of products that matches the query
as the second element.
-Product[]
:
-number
: (optional)
Defined in
medusa/src/services/product.ts:142
listTagsByUsage
listTagsByUsage(take?
): Promise
<ProductTag
[]>
Parameters
Name | Default value |
---|---|
take | number |
Returns
Promise
<ProductTag
[]>
-Promise
:
-ProductTag[]
:
-ProductTag
:
Defined in
medusa/src/services/product.ts:384
listTypes
listTypes(): Promise
<ProductType
[]>
Returns
Promise
<ProductType
[]>
-Promise
:
-ProductType[]
:
-ProductType
:
Defined in
medusa/src/services/product.ts:376
prepareListQuery_
Protected
prepareListQuery_(selector
, config
): { q
: string
; query
: FindWithoutRelationsOptions
; relations
: keyof Product
[] }
Temporary method to be used in place we need custom query strategy to prevent typeorm bug
Parameters
Name |
---|
selector |
config |
Returns
object
-object
: (optional)
Name | Type |
---|---|
q | string |
query | FindWithoutRelationsOptions |
relations | keyof Product [] |
Defined in
medusa/src/services/product.ts:995
reorderVariants
reorderVariants(productId
, variantOrder
): Promise
<Product
>
Parameters
Name |
---|
productId |
variantOrder |
Returns
Promise
<Product
>
-Promise
:
-Product
:
Defined in
medusa/src/services/product.ts:765
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 | Description |
---|---|
productId | string |
config | FindProductConfig |
Returns
Promise
<Product
>
-Promise
: the result of the find one operation.
-Product
:
Defined in
medusa/src/services/product.ts:203
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 | Description |
---|---|
externalId | string |
config | FindProductConfig |
Returns
Promise
<Product
>
-Promise
: the result of the find one operation.
-Product
:
Defined in
medusa/src/services/product.ts:247
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 | Description |
---|---|
productHandle | string |
config | FindProductConfig |
Returns
Promise
<Product
>
-Promise
: the result of the find one operation.
-Product
:
Defined in
medusa/src/services/product.ts:226
retrieveOptionByTitle
retrieveOptionByTitle(title
, productId
): Promise
<null
| ProductOption
>
Retrieve product's option by title.
Parameters
Name | Description |
---|---|
title | string |
productId | string |
Returns
Promise
<null
| ProductOption
>
-Promise
: product option
-`null
| ProductOption`: (optional)
Defined in
medusa/src/services/product.ts:868
retrieveVariants
retrieveVariants(productId
, config?
): Promise
<ProductVariant
[]>
Gets all variants belonging to a product.
Parameters
Name | Description |
---|---|
productId | string |
config | FindProductConfig |
Returns
Promise
<ProductVariant
[]>
-Promise
: an array of variants
-ProductVariant[]
:
-ProductVariant
:
Defined in
medusa/src/services/product.ts:327
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 | Description |
---|---|
selector | Selector <Product > |
config | FindProductConfig |
Returns
Promise
<Product
>
-Promise
: the result of the find one operation.
-Product
:
Defined in
medusa/src/services/product.ts:269
shouldRetryTransaction_
Protected
shouldRetryTransaction_(err
): boolean
Parameters
Name |
---|
err |
Returns
boolean
-boolean
: (optional)
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 | Description |
---|---|
productId | string |
update | UpdateProductInput |
Returns
Promise
<Product
>
-Promise
: resolves to the update result.
-Product
:
Defined in
medusa/src/services/product.ts:551
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 | Description |
---|---|
productId | string |
optionId | string |
data | ProductOptionInput |
Returns
Promise
<Product
>
-Promise
: the updated product
-Product
:
Defined in
medusa/src/services/product.ts:811
updateShippingProfile
updateShippingProfile(productIds
, profileId
): Promise
<Product
[]>
Assign a product to a profile, if a profile id null is provided then detach the product from the profile
Parameters
Name | Description |
---|---|
productIds | string | string [] |
profileId | null | string |
Returns
Promise
<Product
[]>
-Promise
: updated products
-Product[]
:
-Product
:
Defined in
medusa/src/services/product.ts:958
withTransaction
withTransaction(transactionManager?
): ProductService
Parameters
Name |
---|
transactionManager? |
Returns
-ProductService
:
Inherited from
TransactionBaseService.withTransaction