Skip to main content

CollectionService

CollectionService

Contains methods relating to Collection entities.

Signature
class CollectionService implements OnModuleInit {
constructor(connection: TransactionalConnection, channelService: ChannelService, assetService: AssetService, listQueryBuilder: ListQueryBuilder, translatableSaver: TranslatableSaver, eventBus: EventBus, jobQueueService: JobQueueService, configService: ConfigService, slugValidator: SlugValidator, configArgService: ConfigArgService, customFieldRelationService: CustomFieldRelationService, translator: TranslatorService, roleService: RoleService)
findAll(ctx: RequestContext, options?: ListQueryOptions<Collection> & { topLevelOnly?: boolean }, relations?: RelationPaths<Collection>) => Promise<PaginatedList<Translated<Collection>>>;
findOne(ctx: RequestContext, collectionId: ID, relations?: RelationPaths<Collection>) => Promise<Translated<Collection> | undefined>;
findByIds(ctx: RequestContext, ids: ID[], relations?: RelationPaths<Collection>) => Promise<Array<Translated<Collection>>>;
findOneBySlug(ctx: RequestContext, slug: string, relations?: RelationPaths<Collection>) => Promise<Translated<Collection> | undefined>;
getAvailableFilters(ctx: RequestContext) => ConfigurableOperationDefinition[];
getParent(ctx: RequestContext, collectionId: ID) => Promise<Collection | undefined>;
getChildren(ctx: RequestContext, collectionId: ID) => Promise<Collection[]>;
getBreadcrumbs(ctx: RequestContext, collection: Collection) => Promise<Array<{ name: string; id: ID }>>;
getCollectionsByProductId(ctx: RequestContext, productId: ID, publicOnly: boolean) => Promise<Array<Translated<Collection>>>;
getDescendants(ctx: RequestContext, rootId: ID, maxDepth: number = Number.MAX_SAFE_INTEGER) => Promise<Array<Translated<Collection>>>;
getAncestors(collectionId: ID) => Promise<Collection[]>;
getAncestors(collectionId: ID, ctx: RequestContext) => Promise<Array<Translated<Collection>>>;
getAncestors(collectionId: ID, ctx?: RequestContext) => Promise<Array<Translated<Collection> | Collection>>;
previewCollectionVariants(ctx: RequestContext, input: PreviewCollectionVariantsInput, options?: ListQueryOptions<ProductVariant>, relations?: RelationPaths<Collection>) => Promise<PaginatedList<ProductVariant>>;
create(ctx: RequestContext, input: CreateCollectionInput) => Promise<Translated<Collection>>;
update(ctx: RequestContext, input: UpdateCollectionInput) => Promise<Translated<Collection>>;
delete(ctx: RequestContext, id: ID) => Promise<DeletionResponse>;
move(ctx: RequestContext, input: MoveCollectionInput) => Promise<Translated<Collection>>;
getCollectionProductVariantIds(collection: Collection, ctx?: RequestContext) => Promise<ID[]>;
assignCollectionsToChannel(ctx: RequestContext, input: AssignCollectionsToChannelInput) => Promise<Array<Translated<Collection>>>;
removeCollectionsFromChannel(ctx: RequestContext, input: RemoveCollectionsFromChannelInput) => Promise<Array<Translated<Collection>>>;
}
  • Implements: OnModuleInit

constructor

method
(connection: TransactionalConnection, channelService: ChannelService, assetService: AssetService, listQueryBuilder: ListQueryBuilder, translatableSaver: TranslatableSaver, eventBus: EventBus, jobQueueService: JobQueueService, configService: ConfigService, slugValidator: SlugValidator, configArgService: ConfigArgService, customFieldRelationService: CustomFieldRelationService, translator: TranslatorService, roleService: RoleService) => CollectionService

findAll

method
(ctx: RequestContext, options?: ListQueryOptions<Collection> & { topLevelOnly?: boolean }, relations?: RelationPaths<Collection>) => Promise<PaginatedList<Translated<Collection>>>

findOne

method
(ctx: RequestContext, collectionId: ID, relations?: RelationPaths<Collection>) => Promise<Translated<Collection> | undefined>

findByIds

method
(ctx: RequestContext, ids: ID[], relations?: RelationPaths<Collection>) => Promise<Array<Translated<Collection>>>

findOneBySlug

method
(ctx: RequestContext, slug: string, relations?: RelationPaths<Collection>) => Promise<Translated<Collection> | undefined>

getAvailableFilters

method
(ctx: RequestContext) => ConfigurableOperationDefinition[]

Returns all configured CollectionFilters, as specified by the CatalogOptions.

getParent

method
(ctx: RequestContext, collectionId: ID) => Promise<Collection | undefined>

getChildren

method
(ctx: RequestContext, collectionId: ID) => Promise<Collection[]>

Returns all child Collections of the Collection with the given id.

getBreadcrumbs

method
(ctx: RequestContext, collection: Collection) => Promise<Array<{ name: string; id: ID }>>

Returns an array of name/id pairs representing all ancestor Collections up to the Root Collection.

getCollectionsByProductId

method
(ctx: RequestContext, productId: ID, publicOnly: boolean) => Promise<Array<Translated<Collection>>>

Returns all Collections which are associated with the given Product ID.

getDescendants

method
(ctx: RequestContext, rootId: ID, maxDepth: number = Number.MAX_SAFE_INTEGER) => Promise<Array<Translated<Collection>>>

Returns the descendants of a Collection as a flat array. The depth of the traversal can be limited with the maxDepth argument. So to get only the immediate children, set maxDepth = 1.

getAncestors

method
(collectionId: ID) => Promise<Collection[]>

Gets the ancestors of a given collection. Note that since ProductCategories are implemented as an adjacency list, this method will produce more queries the deeper the collection is in the tree.

getAncestors

method
(collectionId: ID, ctx: RequestContext) => Promise<Array<Translated<Collection>>>

getAncestors

method
(collectionId: ID, ctx?: RequestContext) => Promise<Array<Translated<Collection> | Collection>>

previewCollectionVariants

method
(ctx: RequestContext, input: PreviewCollectionVariantsInput, options?: ListQueryOptions<ProductVariant>, relations?: RelationPaths<Collection>) => Promise<PaginatedList<ProductVariant>>

create

method
(ctx: RequestContext, input: CreateCollectionInput) => Promise<Translated<Collection>>

update

method
(ctx: RequestContext, input: UpdateCollectionInput) => Promise<Translated<Collection>>

delete

method
(ctx: RequestContext, id: ID) => Promise<DeletionResponse>

move

method
(ctx: RequestContext, input: MoveCollectionInput) => Promise<Translated<Collection>>

Moves a Collection by specifying the parent Collection ID, and an index representing the order amongst its siblings.

getCollectionProductVariantIds

method
(collection: Collection, ctx?: RequestContext) => Promise<ID[]>

assignCollectionsToChannel

method
(ctx: RequestContext, input: AssignCollectionsToChannelInput) => Promise<Array<Translated<Collection>>>

Assigns Collections to the specified Channel

removeCollectionsFromChannel

method
(ctx: RequestContext, input: RemoveCollectionsFromChannelInput) => Promise<Array<Translated<Collection>>>

Remove Collections from the specified Channel