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)
  async findAll(ctx: RequestContext, options?: ListQueryOptions<Product>, relations?: RelationPaths<Product>) => Promise<PaginatedList<Translated<Product>>>;
  async findOne(ctx: RequestContext, productId: ID, relations?: RelationPaths<Product>) => Promise<Translated<Product> | undefined>;
  async findByIds(ctx: RequestContext, productIds: ID[], relations?: RelationPaths<Product>) => Promise<Array<Translated<Product>>>;
  async getProductChannels(ctx: RequestContext, productId: ID) => Promise<Channel[]>;
  getFacetValuesForProduct(ctx: RequestContext, productId: ID) => Promise<Array<Translated<FacetValue>>>;
  async findOneBySlug(ctx: RequestContext, slug: string, relations?: RelationPaths<Product>) => Promise<Translated<Product> | undefined>;
  async create(ctx: RequestContext, input: CreateProductInput) => Promise<Translated<Product>>;
  async update(ctx: RequestContext, input: UpdateProductInput) => Promise<Translated<Product>>;
  async softDelete(ctx: RequestContext, productId: ID) => Promise<DeletionResponse>;
  async assignProductsToChannel(ctx: RequestContext, input: AssignProductsToChannelInput) => Promise<Array<Translated<Product>>>;
  async removeProductsFromChannel(ctx: RequestContext, input: RemoveProductsFromChannelInput) => Promise<Array<Translated<Product>>>;
  async addOptionGroupToProduct(ctx: RequestContext, productId: ID, optionGroupId: ID) => Promise<Translated<Product>>;
  async removeOptionGroupFromProduct(ctx: RequestContext, productId: ID, optionGroupId: ID, force?: boolean) => Promise<ErrorResultUnion<RemoveOptionGroupFromProductResult, Translated<Product>>>;
}

Members

constructor

method
type:
(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
type:
(ctx: RequestContext, options?: ListQueryOptions<Product>, relations?: RelationPaths<Product>) => Promise<PaginatedList<Translated<Product>>>

findOne

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

findByIds

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

getProductChannels

method
type:
(ctx: RequestContext, productId: ID) => Promise<Channel[]>
Returns all Channels to which the Product is assigned.

getFacetValuesForProduct

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

findOneBySlug

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

create

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

update

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

softDelete

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

assignProductsToChannel

method
type:
(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
type:
(ctx: RequestContext, input: RemoveProductsFromChannelInput) => Promise<Array<Translated<Product>>>

addOptionGroupToProduct

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

removeOptionGroupFromProduct

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