ProductVariantService
ProductVariantService
Contains methods relating to ProductVariant entities.
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)
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>>>;
getProductVariantChannels(ctx: RequestContext, productVariantId: ID) => Promise<Channel[]>;
getProductVariantPrices(ctx: RequestContext, productVariantId: ID) => Promise<ProductVariantPrice[]>;
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>>>;
getProductForVariant(ctx: RequestContext, variant: ProductVariant) => Promise<Translated<Product>>;
getSaleableStockLevel(ctx: RequestContext, variant: ProductVariant) => Promise<number>;
getDisplayStockLevel(ctx: RequestContext, variant: ProductVariant) => Promise<string>;
getFulfillableStockLevel(ctx: RequestContext, variant: ProductVariant) => Promise<number>;
create(ctx: RequestContext, input: CreateProductVariantInput[]) => Promise<Array<Translated<ProductVariant>>>;
update(ctx: RequestContext, input: UpdateProductVariantInput[]) => Promise<Array<Translated<ProductVariant>>>;
createOrUpdateProductVariantPrice(ctx: RequestContext, productVariantId: ID, price: number, channelId: ID, currencyCode?: CurrencyCode) => Promise<ProductVariantPrice>;
deleteProductVariantPrice(ctx: RequestContext, variantId: ID, channelId: ID, currencyCode: CurrencyCode) => ;
softDelete(ctx: RequestContext, id: ID | ID[]) => Promise<DeletionResponse>;
hydratePriceFields(ctx: RequestContext, variant: ProductVariant, priceField: F) => Promise<ProductVariant[F]>;
applyChannelPriceAndTax(variant: ProductVariant, ctx: RequestContext, order?: Order, throwIfNoPriceFound: = false) => Promise<ProductVariant>;
assignProductVariantsToChannel(ctx: RequestContext, input: AssignProductVariantsToChannelInput) => Promise<Array<Translated<ProductVariant>>>;
removeProductVariantsFromChannel(ctx: RequestContext, input: RemoveProductVariantsFromChannelInput) => Promise<Array<Translated<ProductVariant>>>;
}
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) => ProductVariantService
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>>>
Returns a PaginatedList of all ProductVariants associated with the given Collection.
getProductVariantChannels
(ctx: RequestContext, productVariantId: ID) => Promise<Channel[]>
Returns all Channels to which the ProductVariant is assigned.
getProductVariantPrices
(ctx: RequestContext, productVariantId: ID) => Promise<ProductVariantPrice[]>
getVariantByOrderLineId
(ctx: RequestContext, orderLineId: ID) => Promise<Translated<ProductVariant>>
Returns the ProductVariant associated with the given OrderLine.
getOptionsForVariant
(ctx: RequestContext, variantId: ID) => Promise<Array<Translated<ProductOption>>>
Returns the ProductOptions for the given ProductVariant.
getFacetValuesForVariant
(ctx: RequestContext, variantId: ID) => Promise<Array<Translated<FacetValue>>>
getProductForVariant
(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
(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
(ctx: RequestContext, variant: ProductVariant) => Promise<string>
Returns the stockLevel to display to the customer, as specified by the configured StockDisplayStrategy.
getFulfillableStockLevel
(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
(ctx: RequestContext, input: CreateProductVariantInput[]) => Promise<Array<Translated<ProductVariant>>>
update
(ctx: RequestContext, input: UpdateProductVariantInput[]) => Promise<Array<Translated<ProductVariant>>>
createOrUpdateProductVariantPrice
(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.
deleteProductVariantPrice
(ctx: RequestContext, variantId: ID, channelId: ID, currencyCode: CurrencyCode) =>
softDelete
(ctx: RequestContext, id: ID | ID[]) => Promise<DeletionResponse>
hydratePriceFields
(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
(variant: ProductVariant, ctx: RequestContext, order?: Order, throwIfNoPriceFound: = false) => Promise<ProductVariant>
Populates the price
field with the price for the specified channel.
assignProductVariantsToChannel
(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
(ctx: RequestContext, input: RemoveProductVariantsFromChannelInput) => Promise<Array<Translated<ProductVariant>>>