10 KiB
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
packages/medusa/src/services/product-collection.ts:35
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
eventBus_
• Protected Readonly eventBus_: EventBusService
Defined in
packages/medusa/src/services/product-collection.ts:30
manager_
• Protected manager_: EntityManager
Overrides
TransactionBaseService.manager_
Defined in
packages/medusa/src/services/product-collection.ts:27
productCollectionRepository_
• Protected Readonly productCollectionRepository_: typeof ProductCollectionRepository
Defined in
packages/medusa/src/services/product-collection.ts:32
productRepository_
• Protected Readonly productRepository_: typeof ProductRepository
Defined in
packages/medusa/src/services/product-collection.ts:33
transactionManager_
• Protected transactionManager_: undefined | EntityManager
Overrides
TransactionBaseService.transactionManager_
Defined in
packages/medusa/src/services/product-collection.ts:28
Methods
addProducts
▸ addProducts(collectionId, productIds): Promise<ProductCollection>
Parameters
| Name | Type |
|---|---|
collectionId |
string |
productIds |
string[] |
Returns
Promise<ProductCollection>
Defined in
packages/medusa/src/services/product-collection.ts:184
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
packages/medusa/src/interfaces/transaction-base-service.ts:50
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
packages/medusa/src/services/product-collection.ts:113
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
packages/medusa/src/services/product-collection.ts:166
list
▸ list(selector?, config?): Promise<ProductCollection[]>
Lists product collections
Parameters
| Name | Type | Default value | Description |
|---|---|---|---|
selector |
Object |
{} |
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
packages/medusa/src/services/product-collection.ts:226
listAndCount
▸ listAndCount(selector?, config?): Promise<[ProductCollection[], number]>
Lists product collections and add count.
Parameters
| Name | Type | Description |
|---|---|---|
selector |
QuerySelector<ProductCollection> |
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
packages/medusa/src/services/product-collection.ts:244
removeProducts
▸ removeProducts(collectionId, productIds): Promise<void>
Parameters
| Name | Type |
|---|---|
collectionId |
string |
productIds |
string[] |
Returns
Promise<void>
Defined in
packages/medusa/src/services/product-collection.ts:205
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
packages/medusa/src/services/product-collection.ts:60
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
packages/medusa/src/services/product-collection.ts:87
shouldRetryTransaction_
▸ Protected shouldRetryTransaction_(err): boolean
Parameters
| Name | Type |
|---|---|
err |
Record<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
| Name | Type | Description |
|---|---|---|
collectionId |
string |
id of collection to update |
update |
UpdateProductCollection |
update object |
Returns
Promise<ProductCollection>
update collection
Defined in
packages/medusa/src/services/product-collection.ts:136
withTransaction
▸ withTransaction(transactionManager?): ProductCollectionService
Parameters
| Name | Type |
|---|---|
transactionManager? |
EntityManager |
Returns
Inherited from
TransactionBaseService.withTransaction
Defined in
packages/medusa/src/interfaces/transaction-base-service.ts:13