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

medusa/src/services/product-collection.ts:49

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-collection.ts:36


manager_

Protected manager_: EntityManager

Inherited from

TransactionBaseService.manager_

Defined in

medusa/src/interfaces/transaction-base-service.ts:5


productCollectionRepository_

Protected Readonly productCollectionRepository_: Repository<ProductCollection> & { findAndCountByDiscountConditionId: (conditionId: string, query: ExtendedFindConfig<ProductCollection>) => Promise<[ProductCollection[], number]> }

Defined in

medusa/src/services/product-collection.ts:38


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-collection.ts:39


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

NameType
CREATEDstring
DELETEDstring
PRODUCTS_ADDEDstring
PRODUCTS_REMOVEDstring
UPDATEDstring

Defined in

medusa/src/services/product-collection.ts:41

Accessors

activeManager_

Protected get activeManager_(): EntityManager

Returns

EntityManager

Inherited from

TransactionBaseService.activeManager_

Defined in

medusa/src/interfaces/transaction-base-service.ts:8

Methods

addProducts

addProducts(collectionId, productIds): Promise<ProductCollection>

Parameters

NameType
collectionIdstring
productIdsstring[]

Returns

Promise<ProductCollection>

Defined in

medusa/src/services/product-collection.ts:216


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

medusa/src/interfaces/transaction-base-service.ts:56


create

create(collection): Promise<ProductCollection>

Creates a product collection

Parameters

NameTypeDescription
collectionCreateProductCollectionthe collection to create

Returns

Promise<ProductCollection>

created collection

Defined in

medusa/src/services/product-collection.ts:128


delete

delete(collectionId): Promise<void>

Deletes a product collection idempotently

Parameters

NameTypeDescription
collectionIdstringid of collection to delete

Returns

Promise<void>

empty promise

Defined in

medusa/src/services/product-collection.ts:192


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

medusa/src/services/product-collection.ts:274


listAndCount

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

Lists product collections and add count.

Parameters

NameTypeDescription
selectorListAndCountSelectorthe 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

medusa/src/services/product-collection.ts:291


removeProducts

removeProducts(collectionId, productIds): Promise<void>

Parameters

NameType
collectionIdstring
productIdsstring[]

Returns

Promise<void>

Defined in

medusa/src/services/product-collection.ts:242


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

medusa/src/services/product-collection.ts:68


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

medusa/src/services/product-collection.ts:102


shouldRetryTransaction_

Protected shouldRetryTransaction_(err): boolean

Parameters

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

Returns

boolean

Inherited from

TransactionBaseService.shouldRetryTransaction_

Defined in

medusa/src/interfaces/transaction-base-service.ts:37


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

medusa/src/services/product-collection.ts:154


withTransaction

withTransaction(transactionManager?): ProductCollectionService

Parameters

NameType
transactionManager?EntityManager

Returns

ProductCollectionService

Inherited from

TransactionBaseService.withTransaction

Defined in

medusa/src/interfaces/transaction-base-service.ts:20

Was this page helpful?