ProductVariantService

ProductVariantService

Contains methods relating to ProductVariant entities.

Signature

class ProductVariantService {
  constructor(connection: TransactionalConnection, configService: ConfigService, taxCategoryService: TaxCategoryService, facetValueService: FacetValueService, assetService: AssetService, translatableSaver: TranslatableSaver, eventBus: EventBus, listQueryBuilder: ListQueryBuilder, globalSettingsService: GlobalSettingsService, stockMovementService: StockMovementService, stockLevelService: StockLevelService, channelService: ChannelService, roleService: RoleService, customFieldRelationService: CustomFieldRelationService, requestCache: RequestContextCacheService, productPriceApplicator: ProductPriceApplicator, translator: TranslatorService)
  async findAll(ctx: RequestContext, options?: ListQueryOptions<ProductVariant>) => Promise<PaginatedList<Translated<ProductVariant>>>;
  findOne(ctx: RequestContext, productVariantId: ID, relations?: RelationPaths<ProductVariant>) => Promise<Translated<ProductVariant> | undefined>;
  findByIds(ctx: RequestContext, ids: ID[]) => Promise<Array<Translated<ProductVariant>>>;
  getVariantsByProductId(ctx: RequestContext, productId: ID, options: ListQueryOptions<ProductVariant> = {}, relations?: RelationPaths<ProductVariant>) => Promise<PaginatedList<Translated<ProductVariant>>>;
  getVariantsByCollectionId(ctx: RequestContext, collectionId: ID, options: ListQueryOptions<ProductVariant>, relations: RelationPaths<ProductVariant> = []) => Promise<PaginatedList<Translated<ProductVariant>>>;
  async getProductVariantChannels(ctx: RequestContext, productVariantId: ID) => Promise<Channel[]>;
  async getProductVariantPrices(ctx: RequestContext, productVariantId: ID) => Promise<ProductVariantPrice[]>;
  async getVariantByOrderLineId(ctx: RequestContext, orderLineId: ID) => Promise<Translated<ProductVariant>>;
  getOptionsForVariant(ctx: RequestContext, variantId: ID) => Promise<Array<Translated<ProductOption>>>;
  getFacetValuesForVariant(ctx: RequestContext, variantId: ID) => Promise<Array<Translated<FacetValue>>>;
  async getProductForVariant(ctx: RequestContext, variant: ProductVariant) => Promise<Translated<Product>>;
  async getSaleableStockLevel(ctx: RequestContext, variant: ProductVariant) => Promise<number>;
  async getDisplayStockLevel(ctx: RequestContext, variant: ProductVariant) => Promise<string>;
  async getFulfillableStockLevel(ctx: RequestContext, variant: ProductVariant) => Promise<number>;
  async create(ctx: RequestContext, input: CreateProductVariantInput[]) => Promise<Array<Translated<ProductVariant>>>;
  async update(ctx: RequestContext, input: UpdateProductVariantInput[]) => Promise<Array<Translated<ProductVariant>>>;
  async createOrUpdateProductVariantPrice(ctx: RequestContext, productVariantId: ID, price: number, channelId: ID, currencyCode?: CurrencyCode) => Promise<ProductVariantPrice>;
  async softDelete(ctx: RequestContext, id: ID | ID[]) => Promise<DeletionResponse>;
  async hydratePriceFields(ctx: RequestContext, variant: ProductVariant, priceField: F) => Promise<ProductVariant[F]>;
  async applyChannelPriceAndTax(variant: ProductVariant, ctx: RequestContext, order?: Order) => Promise<ProductVariant>;
  async assignProductVariantsToChannel(ctx: RequestContext, input: AssignProductVariantsToChannelInput) => Promise<Array<Translated<ProductVariant>>>;
  async removeProductVariantsFromChannel(ctx: RequestContext, input: RemoveProductVariantsFromChannelInput) => Promise<Array<Translated<ProductVariant>>>;
}

Members

constructor

method
type:
(connection: TransactionalConnection, configService: ConfigService, taxCategoryService: TaxCategoryService, facetValueService: FacetValueService, assetService: AssetService, translatableSaver: TranslatableSaver, eventBus: EventBus, listQueryBuilder: ListQueryBuilder, globalSettingsService: GlobalSettingsService, stockMovementService: StockMovementService, stockLevelService: StockLevelService, channelService: ChannelService, roleService: RoleService, customFieldRelationService: CustomFieldRelationService, requestCache: RequestContextCacheService, productPriceApplicator: ProductPriceApplicator, translator: TranslatorService) => ProductVariantService

findAll

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

findOne

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

findByIds

method
type:
(ctx: RequestContext, ids: ID[]) => Promise<Array<Translated<ProductVariant>>>

getVariantsByProductId

method
type:
(ctx: RequestContext, productId: ID, options: ListQueryOptions<ProductVariant> = {}, relations?: RelationPaths<ProductVariant>) => Promise<PaginatedList<Translated<ProductVariant>>>

getVariantsByCollectionId

method
type:
(ctx: RequestContext, collectionId: ID, options: ListQueryOptions<ProductVariant>, relations: RelationPaths<ProductVariant> = []) => Promise<PaginatedList<Translated<ProductVariant>>>
Returns a PaginatedList of all ProductVariants associated with the given Collection.

getProductVariantChannels

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

getProductVariantPrices

method
type:
(ctx: RequestContext, productVariantId: ID) => Promise<ProductVariantPrice[]>

getVariantByOrderLineId

method
type:
(ctx: RequestContext, orderLineId: ID) => Promise<Translated<ProductVariant>>
Returns the ProductVariant associated with the given OrderLine.

getOptionsForVariant

method
type:
(ctx: RequestContext, variantId: ID) => Promise<Array<Translated<ProductOption>>>
Returns the ProductOptions for the given ProductVariant.

getFacetValuesForVariant

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

getProductForVariant

method
type:
(ctx: RequestContext, variant: ProductVariant) => Promise<Translated<Product>>
Returns the Product associated with the ProductVariant. Whereas the ProductService.findOne() method performs a large multi-table join with all the typical data needed for a “product detail” page, this method returns only the Product itself.

getSaleableStockLevel

method
type:
(ctx: RequestContext, variant: ProductVariant) => Promise<number>
Returns the number of saleable units of the ProductVariant, i.e. how many are available for purchase by Customers. This is determined by the ProductVariant’s stockOnHand value, as well as the local and global outOfStockThreshold settings.

getDisplayStockLevel

method
type:
(ctx: RequestContext, variant: ProductVariant) => Promise<string>
Returns the stockLevel to display to the customer, as specified by the configured StockDisplayStrategy.

getFulfillableStockLevel

method
type:
(ctx: RequestContext, variant: ProductVariant) => Promise<number>
Returns the number of fulfillable units of the ProductVariant, equivalent to stockOnHand for those variants which are tracking inventory.

create

method
type:
(ctx: RequestContext, input: CreateProductVariantInput[]) => Promise<Array<Translated<ProductVariant>>>

update

method
type:
(ctx: RequestContext, input: UpdateProductVariantInput[]) => Promise<Array<Translated<ProductVariant>>>

createOrUpdateProductVariantPrice

method
type:
(ctx: RequestContext, productVariantId: ID, price: number, channelId: ID, currencyCode?: CurrencyCode) => Promise<ProductVariantPrice>
Creates a ProductVariantPrice for the given ProductVariant/Channel combination. If the currencyCode is not specified, the default currency of the Channel will be used.

softDelete

method
type:
(ctx: RequestContext, id: ID | ID[]) => Promise<DeletionResponse>

hydratePriceFields

method
type:
(ctx: RequestContext, variant: ProductVariant, priceField: F) => Promise<ProductVariant[F]>

This method is intended to be used by the ProductVariant GraphQL entity resolver to resolve the price-related fields which need to be populated at run-time using the applyChannelPriceAndTax method.

Is optimized to make as few DB calls as possible using caching based on the open request.

applyChannelPriceAndTax

method
type:
(variant: ProductVariant, ctx: RequestContext, order?: Order) => Promise<ProductVariant>
Populates the price field with the price for the specified channel.

assignProductVariantsToChannel

method
type:
(ctx: RequestContext, input: AssignProductVariantsToChannelInput) => Promise<Array<Translated<ProductVariant>>>
Assigns the specified ProductVariants to the specified Channel. In doing so, it will create a new ProductVariantPrice and also assign the associated Product and any Assets to the Channel too.

removeProductVariantsFromChannel

method
type:
(ctx: RequestContext, input: RemoveProductVariantsFromChannelInput) => Promise<Array<Translated<ProductVariant>>>