Class: ProductCollectionService
Provides layer to manipulate product collections.
Hierarchy
TransactionBaseService↳
ProductCollectionService
Constructors
constructor
• new ProductCollectionService(__namedParameters)
Parameters
| Name | Type |
|---|---|
__namedParameters | InjectedDependencies |
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
| Name | Type |
|---|---|
CREATED | string |
DELETED | string |
PRODUCTS_ADDED | string |
PRODUCTS_REMOVED | string |
UPDATED | string |
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
| Name | Type |
|---|---|
collectionId | string |
productIds | string[] |
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
| 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
create
▸ create(collection): Promise<ProductCollection>
Creates a product collection
Parameters
| Name | Type | Description |
|---|---|---|
collection | CreateProductCollection | the 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
| Name | Type | Description |
|---|---|---|
collectionId | string | id 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
| Name | Type | Default value | Description |
|---|---|---|---|
selector | Selector<ProductCollection> & { discount_condition_id?: string ; q?: string } | {} | the query object for find |
config | Object | undefined | the config to be used for find |
config.skip | number | 0 | - |
config.take | number | 20 | - |
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
| Name | Type | Description |
|---|---|---|
selector | ListAndCountSelector | the query object for find |
config | FindConfig<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
| Name | Type |
|---|---|
collectionId | string |
productIds | string[] |
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
| Name | Type | Description |
|---|---|---|
collectionId | string | the id of the collection to retrieve. |
config | FindConfig<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
| Name | Type | Description |
|---|---|---|
collectionHandle | string | the handle of the collection to retrieve. |
config | FindConfig<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
| 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(collectionId, update): Promise<ProductCollection>
Updates a product collection
Parameters
| Name | Type | Description |
|---|---|---|
collectionId | string | id of collection to update |
update | UpdateProductCollection | update object |
Returns
Promise<ProductCollection>
update collection
Defined in
medusa/src/services/product-collection.ts:154
withTransaction
▸ withTransaction(transactionManager?): ProductCollectionService
Parameters
| Name | Type |
|---|---|
transactionManager? | EntityManager |
Returns
Inherited from
TransactionBaseService.withTransaction