Skip to main content

ProductService

ProductService​

Contains methods relating to Product entities.

Signature
class ProductService {
constructor(connection: TransactionalConnection, channelService: ChannelService, roleService: RoleService, assetService: AssetService, productVariantService: ProductVariantService, facetValueService: FacetValueService, taxRateService: TaxRateService, collectionService: CollectionService, listQueryBuilder: ListQueryBuilder, translatableSaver: TranslatableSaver, eventBus: EventBus, slugValidator: SlugValidator, customFieldRelationService: CustomFieldRelationService, translator: TranslatorService, productOptionGroupService: ProductOptionGroupService)
findAll(ctx: RequestContext, options?: ListQueryOptions<Product>, relations?: RelationPaths<Product>) => Promise<PaginatedList<Translated<Product>>>;
findOne(ctx: RequestContext, productId: ID, relations?: RelationPaths<Product>) => Promise<Translated<Product> | undefined>;
findByIds(ctx: RequestContext, productIds: ID[], relations?: RelationPaths<Product>) => Promise<Array<Translated<Product>>>;
getProductChannels(ctx: RequestContext, productId: ID) => Promise<Channel[]>;
getFacetValuesForProduct(ctx: RequestContext, productId: ID) => Promise<Array<Translated<FacetValue>>>;
findOneBySlug(ctx: RequestContext, slug: string, relations?: RelationPaths<Product>) => Promise<Translated<Product> | undefined>;
create(ctx: RequestContext, input: CreateProductInput) => Promise<Translated<Product>>;
update(ctx: RequestContext, input: UpdateProductInput) => Promise<Translated<Product>>;
softDelete(ctx: RequestContext, productId: ID) => Promise<DeletionResponse>;
assignProductsToChannel(ctx: RequestContext, input: AssignProductsToChannelInput) => Promise<Array<Translated<Product>>>;
removeProductsFromChannel(ctx: RequestContext, input: RemoveProductsFromChannelInput) => Promise<Array<Translated<Product>>>;
addOptionGroupToProduct(ctx: RequestContext, productId: ID, optionGroupId: ID) => Promise<Translated<Product>>;
removeOptionGroupFromProduct(ctx: RequestContext, productId: ID, optionGroupId: ID, force?: boolean) => Promise<ErrorResultUnion<RemoveOptionGroupFromProductResult, Translated<Product>>>;
}

constructor​

method
(connection: TransactionalConnection, channelService: ChannelService, roleService: RoleService, assetService: AssetService, productVariantService: ProductVariantService, facetValueService: FacetValueService, taxRateService: TaxRateService, collectionService: CollectionService, listQueryBuilder: ListQueryBuilder, translatableSaver: TranslatableSaver, eventBus: EventBus, slugValidator: SlugValidator, customFieldRelationService: CustomFieldRelationService, translator: TranslatorService, productOptionGroupService: ProductOptionGroupService) => ProductService

findAll​

method
(ctx: RequestContext, options?: ListQueryOptions<Product>, relations?: RelationPaths<Product>) => Promise<PaginatedList<Translated<Product>>>

findOne​

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

findByIds​

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

getProductChannels​

method
(ctx: RequestContext, productId: ID) => Promise<Channel[]>

Returns all Channels to which the Product is assigned.

getFacetValuesForProduct​

method
(ctx: RequestContext, productId: ID) => Promise<Array<Translated<FacetValue>>>

findOneBySlug​

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

create​

method
(ctx: RequestContext, input: CreateProductInput) => Promise<Translated<Product>>

update​

method
(ctx: RequestContext, input: UpdateProductInput) => Promise<Translated<Product>>

softDelete​

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

assignProductsToChannel​

method
(ctx: RequestContext, input: AssignProductsToChannelInput) => Promise<Array<Translated<Product>>>

Assigns a Product to the specified Channel, and optionally uses a priceFactor to set the ProductVariantPrices on the new Channel.

Internally, this method will also call ProductVariantService assignProductVariantsToChannel() for each of the Product's variants, and will assign the Product's Assets to the Channel too.

removeProductsFromChannel​

method
(ctx: RequestContext, input: RemoveProductsFromChannelInput) => Promise<Array<Translated<Product>>>

addOptionGroupToProduct​

method
(ctx: RequestContext, productId: ID, optionGroupId: ID) => Promise<Translated<Product>>

removeOptionGroupFromProduct​

method
(ctx: RequestContext, productId: ID, optionGroupId: ID, force?: boolean) => Promise<ErrorResultUnion<RemoveOptionGroupFromProductResult, Translated<Product>>>