Skip to main content
Skip to main content

ProductCollectionService

Provides layer to manipulate product collections.

Constructors

constructor

**new ProductCollectionService**(«destructured»)

Parameters

__namedParametersInjectedDependenciesRequired

Properties

__configModule__Record<string, unknown>
__container__anyRequired
__moduleDeclaration__Record<string, unknown>
eventBus_EventBusServiceRequired
manager_EntityManagerRequired
productCollectionRepository_Repository<ProductCollection> & &#123; findAndCountByDiscountConditionId: Method findAndCountByDiscountConditionId &#125;Required
productRepository_Repository<Product> & &#123; _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 &#125;Required
transactionManager_undefined | EntityManagerRequired
EventsobjectRequired
Events.CREATEDstringRequired

Default: "product-collection.created"

Events.DELETEDstringRequired

Default: "product-collection.deleted"

Events.PRODUCTS_ADDEDstringRequired

Default: "product-collection.products_added"

Events.PRODUCTS_REMOVEDstringRequired

Default: "product-collection.products_removed"

Events.UPDATEDstringRequired

Default: "product-collection.updated"

Accessors

activeManager_

Protected get**activeManager_**(): EntityManager

Returns

EntityManager

EntityManagerEntityManagerRequired

Methods

addProducts

**addProducts**(collectionId, productIds): Promise&#60;[ProductCollection](/references/services/classes/ProductCollection)&#62;

Parameters

collectionIdstringRequired
productIdsstring[]Required

Returns

Promise<ProductCollection>

PromisePromise<ProductCollection>Required

atomicPhase_

Protected **atomicPhase_**<TypeParameter TResult, TypeParameter TError>(work, isolationOrErrorHandler?, maybeErrorHandlerOrDontFail?): Promise&#60;TResult&#62;

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.

TResultobjectRequired
TErrorobjectRequired

Parameters

work(transactionManager: EntityManager) => Promise<TResult>Required
the transactional work to be done
isolationOrErrorHandlerIsolationLevel | (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>

PromisePromise<TResult>Required
the result of the transactional work

create

**create**(collection): Promise&#60;[ProductCollection](/references/services/classes/ProductCollection)&#62;

Creates a product collection

Parameters

collectionCreateProductCollectionRequired
the collection to create

Returns

Promise<ProductCollection>

PromisePromise<ProductCollection>Required
created collection

delete

**delete**(collectionId): Promise&#60;void&#62;

Deletes a product collection idempotently

Parameters

collectionIdstringRequired
id of collection to delete

Returns

Promise<void>

PromisePromise<void>Required
empty promise

list

**list**(selector?, config?): Promise&#60;[ProductCollection](/references/services/classes/ProductCollection)[]&#62;

Lists product collections

Parameters

selectorSelector<ProductCollection> & &#123; discount_condition_id?: string ; q?: string &#125;Required
the query object for find

Default: {}

configobjectRequired
the config to be used for find
config.skipnumberRequired

Default: 0

config.takenumberRequired

Default: 20

Returns

Promise<ProductCollection[]>

PromisePromise<ProductCollection[]>Required
the result of the find operation

listAndCount

**listAndCount**(selector?, config?): Promise&#60;[[ProductCollection](/references/services/classes/ProductCollection)[], number]&#62;

Lists product collections and add count.

Parameters

selectorListAndCountSelectorRequired
the query object for find

Default: {}

the config to be used for find

Returns

Promise<[ProductCollection[], number]>

PromisePromise<[ProductCollection[], number]>Required
the result of the find operation

removeProducts

**removeProducts**(collectionId, productIds): Promise&#60;void&#62;

Parameters

collectionIdstringRequired
productIdsstring[]Required

Returns

Promise<void>

PromisePromise<void>Required

retrieve

**retrieve**(collectionId, config?): Promise&#60;[ProductCollection](/references/services/classes/ProductCollection)&#62;

Retrieves a product collection by id.

Parameters

collectionIdstringRequired
the id of the collection to retrieve.
the config of the collection to retrieve.

Default: {}

Returns

Promise<ProductCollection>

PromisePromise<ProductCollection>Required
the collection.

retrieveByHandle

**retrieveByHandle**(collectionHandle, config?): Promise&#60;[ProductCollection](/references/services/classes/ProductCollection)&#62;

Retrieves a product collection by id.

Parameters

collectionHandlestringRequired
the handle of the collection to retrieve.
query config for request

Default: {}

Returns

Promise<ProductCollection>

PromisePromise<ProductCollection>Required
the collection.

shouldRetryTransaction_

Protected **shouldRetryTransaction_**(err): boolean

Parameters

errRecord<string, unknown> | &#123; code: string &#125;Required

Returns

boolean

booleanboolean

update

**update**(collectionId, update): Promise&#60;[ProductCollection](/references/services/classes/ProductCollection)&#62;

Updates a product collection

Parameters

collectionIdstringRequired
id of collection to update
update object

Returns

Promise<ProductCollection>

PromisePromise<ProductCollection>Required
update collection

withTransaction

**withTransaction**(transactionManager?): [ProductCollectionService](/references/services/classes/ProductCollectionService)

Parameters

transactionManagerEntityManager

Returns

ProductCollectionService

ProductCollectionServiceProductCollectionServiceRequired
Was this section helpful?