Skip to main content

Class: ProductCollectionService

Provides layer to manipulate product collections.

Hierarchy

  • TransactionBaseService

    ProductCollectionService

Constructors

constructor

new ProductCollectionService(__namedParameters)

Parameters

NameType
__namedParametersInjectedDependencies

Overrides

TransactionBaseService.constructor

Defined in

packages/medusa/src/services/product-collection.ts:34

Properties

__configModule__

Protected Optional Readonly __configModule__: Record<string, unknown>

Inherited from

TransactionBaseService.__configModule__

Defined in

packages/medusa/src/interfaces/transaction-base-service.ts:10


__container__

Protected Readonly __container__: any

Inherited from

TransactionBaseService.__container__

Defined in

packages/medusa/src/interfaces/transaction-base-service.ts:9


__moduleDeclaration__

Protected Optional Readonly __moduleDeclaration__: Record<string, unknown>

Inherited from

TransactionBaseService.__moduleDeclaration__

Defined in

packages/medusa/src/interfaces/transaction-base-service.ts:11


eventBus_

Protected Readonly eventBus_: EventBusService

Defined in

packages/medusa/src/services/product-collection.ts:29


manager_

Protected manager_: EntityManager

Overrides

TransactionBaseService.manager_

Defined in

packages/medusa/src/services/product-collection.ts:26


productCollectionRepository_

Protected Readonly productCollectionRepository_: typeof ProductCollectionRepository

Defined in

packages/medusa/src/services/product-collection.ts:31


productRepository_

Protected Readonly productRepository_: typeof ProductRepository

Defined in

packages/medusa/src/services/product-collection.ts:32


transactionManager_

Protected transactionManager_: undefined | EntityManager

Overrides

TransactionBaseService.transactionManager_

Defined in

packages/medusa/src/services/product-collection.ts:27

Methods

addProducts

addProducts(collectionId, productIds): Promise<ProductCollection>

Parameters

NameType
collectionIdstring
productIdsstring[]

Returns

Promise<ProductCollection>

Defined in

packages/medusa/src/services/product-collection.ts:181


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

NameTypeDescription
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

packages/medusa/src/interfaces/transaction-base-service.ts:50


create

create(collection): Promise<ProductCollection>

Creates a product collection

Parameters

NameTypeDescription
collectionCreateProductCollectionthe collection to create

Returns

Promise<ProductCollection>

created collection

Defined in

packages/medusa/src/services/product-collection.ts:114


delete

delete(collectionId): Promise<void>

Deletes a product collection idempotently

Parameters

NameTypeDescription
collectionIdstringid of collection to delete

Returns

Promise<void>

empty promise

Defined in

packages/medusa/src/services/product-collection.ts:163


list

list(selector?, config?): Promise<ProductCollection[]>

Lists product collections

Parameters

NameTypeDefault valueDescription
selectorSelector<ProductCollection> & { discount_condition_id?: string ; q?: string }{}the query object for find
configObjectundefinedthe config to be used for find
config.skipnumber0-
config.takenumber20-

Returns

Promise<ProductCollection[]>

the result of the find operation

Defined in

packages/medusa/src/services/product-collection.ts:219


listAndCount

listAndCount(selector?, config?): Promise<[ProductCollection[], number]>

Lists product collections and add count.

Parameters

NameTypeDescription
selectorSelector<ProductCollection> & { discount_condition_id?: string ; q?: string }the query object for find
configFindConfig<ProductCollection>the config to be used for find

Returns

Promise<[ProductCollection[], number]>

the result of the find operation

Defined in

packages/medusa/src/services/product-collection.ts:236


removeProducts

removeProducts(collectionId, productIds): Promise<void>

Parameters

NameType
collectionIdstring
productIdsstring[]

Returns

Promise<void>

Defined in

packages/medusa/src/services/product-collection.ts:198


retrieve

retrieve(collectionId, config?): Promise<ProductCollection>

Retrieves a product collection by id.

Parameters

NameTypeDescription
collectionIdstringthe id of the collection to retrieve.
configFindConfig<ProductCollection>the config of the collection to retrieve.

Returns

Promise<ProductCollection>

the collection.

Defined in

packages/medusa/src/services/product-collection.ts:54


retrieveByHandle

retrieveByHandle(collectionHandle, config?): Promise<ProductCollection>

Retrieves a product collection by id.

Parameters

NameTypeDescription
collectionHandlestringthe handle of the collection to retrieve.
configFindConfig<ProductCollection>query config for request

Returns

Promise<ProductCollection>

the collection.

Defined in

packages/medusa/src/services/product-collection.ts:88


shouldRetryTransaction_

Protected shouldRetryTransaction_(err): boolean

Parameters

NameType
errRecord<string, unknown> | { code: string }

Returns

boolean

Inherited from

TransactionBaseService.shouldRetryTransaction_

Defined in

packages/medusa/src/interfaces/transaction-base-service.ts:31


update

update(collectionId, update): Promise<ProductCollection>

Updates a product collection

Parameters

NameTypeDescription
collectionIdstringid of collection to update
updateUpdateProductCollectionupdate object

Returns

Promise<ProductCollection>

update collection

Defined in

packages/medusa/src/services/product-collection.ts:133


withTransaction

withTransaction(transactionManager?): ProductCollectionService

Parameters

NameType
transactionManager?EntityManager

Returns

ProductCollectionService

Inherited from

TransactionBaseService.withTransaction

Defined in

packages/medusa/src/interfaces/transaction-base-service.ts:14