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, channelService: ChannelService, roleService: RoleService, customFieldRelationService: CustomFieldRelationService, requestCache: RequestContextCacheService, productPriceApplicator: ProductPriceApplicator)
  async findAll(ctx: RequestContext, options?: ListQueryOptions<ProductVariant>) => Promise<PaginatedList<Translated<ProductVariant>>>;
  findOne(ctx: RequestContext, productVariantId: ID) => Promise<Translated<ProductVariant> | undefined>;
  findByIds(ctx: RequestContext, ids: ID[]) => Promise<Array<Translated<ProductVariant>>>;
  getVariantsByProductId(ctx: RequestContext, productId: ID, options: ListQueryOptions<ProductVariant> = {}) => Promise<PaginatedList<Translated<ProductVariant>>>;
  getVariantsByCollectionId(ctx: RequestContext, collectionId: ID, options: ListQueryOptions<ProductVariant>) => Promise<PaginatedList<Translated<ProductVariant>>>;
  async getProductVariantChannels(ctx: RequestContext, productVariantId: ID) => Promise<Channel[]>;
  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) => 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, channelService: ChannelService, roleService: RoleService, customFieldRelationService: CustomFieldRelationService, requestCache: RequestContextCacheService, productPriceApplicator: ProductPriceApplicator) => ProductVariantService

findAll

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

findOne

method
type:
(ctx: RequestContext, productVariantId: ID) => 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> = {}) => Promise<PaginatedList<Translated<ProductVariant>>>

getVariantsByCollectionId

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

getProductVariantChannels

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

getVariantByOrderLineId

async 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

async 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

async 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

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

getFulfillableStockLevel

async 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

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

update

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

createOrUpdateProductVariantPrice

async method
type:
(ctx: RequestContext, productVariantId: ID, price: number, channelId: ID) => Promise<ProductVariantPrice>
Creates a ProductVariantPrice for the given ProductVariant/Channel combination.

softDelete

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

hydratePriceFields

async 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

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

assignProductVariantsToChannel

async 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

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