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)
  async findAll(ctx: RequestContext, options?: ListQueryOptions<Product>) => Promise<PaginatedList<Translated<Product>>>;
  async findOne(ctx: RequestContext, productId: ID) => Promise<Translated<Product> | undefined>;
  async findByIds(ctx: RequestContext, productIds: ID[]) => 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) => 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) => 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) => ProductService

findAll

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

findOne

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

findByIds

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

getProductChannels

async 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

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

create

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

update

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

softDelete

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

assignProductsToChannel

async 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 assignassignProductVariantsToChannel() for each of the Product’s variants, and will assign the Product’s Assets to the Channel too.

removeProductsFromChannel

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

addOptionGroupToProduct

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

removeOptionGroupFromProduct

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