ProductVariantService
Constructors
constructor
**new ProductVariantService**(«destructured»)
Parameters
__namedParametersObjectRequiredProperties
__configModule__Record<string, unknown>__container__anyRequired__moduleDeclaration__Record<string, unknown>cartRepository_Repository<Cart> & { findOneWithRelations: Method findOneWithRelations ; findWithRelations: Method findWithRelations }Requiredmanager_EntityManagerRequiredmoneyAmountRepository_Repository<MoneyAmount> & { addPriceListPrices: Method addPriceListPrices ; createProductVariantMoneyAmounts: Method createProductVariantMoneyAmounts ; deletePriceListPrices: Method deletePriceListPrices ; deleteVariantPricesNotIn: Method deleteVariantPricesNotIn ; findCurrencyMoneyAmounts: Method findCurrencyMoneyAmounts ; findManyForVariantInPriceList: Method findManyForVariantInPriceList ; findManyForVariantInRegion: Method findManyForVariantInRegion ; findManyForVariantsInRegion: Method findManyForVariantsInRegion ; findRegionMoneyAmounts: Method findRegionMoneyAmounts ; findVariantPricesNotIn: Method findVariantPricesNotIn ; getPricesForVariantInRegion: Method getPricesForVariantInRegion ; insertBulk: Method insertBulk ; updatePriceListPrices: Method updatePriceListPrices ; upsertVariantCurrencyPrice: Method upsertVariantCurrencyPrice }RequiredproductRepository_Repository<Product> & { _applyCategoriesQuery: Method \_applyCategoriesQuery ; _findWithRelations: Method \_findWithRelations ; bulkAddToCollection: Method bulkAddToCollection ; bulkRemoveFromCollection: Method bulkRemoveFromCollection ; findOneWithRelations: Method findOneWithRelations ; findWithRelations: Method findWithRelations ; findWithRelationsAndCount: Method findWithRelationsAndCount ; getCategoryIdsFromInput: Method getCategoryIdsFromInput ; getCategoryIdsRecursively: Method getCategoryIdsRecursively ; getFreeTextSearchResultsAndCount: Method getFreeTextSearchResultsAndCount ; isProductInSalesChannels: Method isProductInSalesChannels ; queryProducts: Method queryProducts ; queryProductsWithIds: Method queryProductsWithIds }RequiredtransactionManager_undefined | EntityManagerRequiredEventsobjectRequiredEvents.CREATEDstringRequiredDefault: "product-variant.created"
Events.DELETEDstringRequiredDefault: "product-variant.deleted"
Events.UPDATEDstringRequiredDefault: "product-variant.updated"
Accessors
activeManager_
Protected get**activeManager_**(): EntityManager
Returns
EntityManager
EntityManagerEntityManagerRequiredMethods
addOptionValue
**addOptionValue**(variantId, optionId, optionValue): Promise<[ProductOptionValue](/references/services/classes/ProductOptionValue)>
Adds option value to a variant. Fails when product with variant does not exist or if that product does not have an option with the given option id. Fails if given variant is not found. Option value must be of type string or number.
Parameters
variantIdstringRequiredoptionIdstringRequiredoptionValuestringRequiredReturns
Promise<ProductOptionValue>
atomicPhase_
Protected **atomicPhase_**<TypeParameter TResult, TypeParameter TError>(work, isolationOrErrorHandler?, maybeErrorHandlerOrDontFail?): Promise<TResult>
Wraps some work within a transactional block. If the service already has a transaction manager attached this will be reused, otherwise a new transaction manager is created.
TResultobjectRequiredTErrorobjectRequiredParameters
work(transactionManager: EntityManager) => Promise<TResult>RequiredisolationOrErrorHandlerIsolationLevel | (error: TError) => Promise<void | TResult>maybeErrorHandlerOrDontFail(error: TError) => Promise<void | TResult>Returns
Promise<TResult>
PromisePromise<TResult>Requiredcreate
**create**<TypeParameter TVariants, TypeParameter TOutput>(productOrProductId, variants): Promise<TOutput>
Creates an unpublished product variant. Will validate against parent product to ensure that the variant can in fact be created.
TOutputobjectRequiredParameters
Returns
Promise<TOutput>
PromisePromise<TOutput>Requireddelete
**delete**(variantIds): Promise<void>
Deletes variant or variants. Will never fail due to delete being idempotent.
Parameters
variantIdsstring | string[]RequiredReturns
Promise<void>
PromisePromise<void>RequireddeleteOptionValue
**deleteOptionValue**(variantId, optionId): Promise<void>
Deletes option value from given variant. Will never fail due to delete being idempotent.
Parameters
variantIdstringRequiredoptionIdstringRequiredReturns
Promise<void>
PromisePromise<void>RequiredgetFreeTextQueryBuilder_
**getFreeTextQueryBuilder_**(variantRepo, query, q?): SelectQueryBuilder<[ProductVariant](/references/services/classes/ProductVariant)>
Lists variants based on the provided parameters and includes the count of variants that match the query.
Parameters
qstringReturns
SelectQueryBuilder<ProductVariant>
getRegionPrice
**getRegionPrice**(variantId, context): Promise<null \| number>
Gets the price specific to a region. If no region specific money amount exists the function will try to use a currency price. If no default currency price exists the function will throw an error.
Parameters
variantIdstringRequiredReturns
Promise<null | number>
PromisePromise<null | number>RequiredisVariantInSalesChannels
**isVariantInSalesChannels**(id, salesChannelIds): Promise<boolean>
Check if the variant is assigned to at least one of the provided sales channels.
Parameters
idstringRequiredsalesChannelIdsstring[]RequiredReturns
Promise<boolean>
PromisePromise<boolean>Requiredlist
**list**(selector, config?): Promise<[ProductVariant](/references/services/classes/ProductVariant)[]>
Parameters
Returns
Promise<ProductVariant[]>
listAndCount
**listAndCount**(selector, config?): Promise<[[ProductVariant](/references/services/classes/ProductVariant)[], number]>
Parameters
Returns
Promise<[ProductVariant[], number]>
retrieve
**retrieve**(variantId, config?): Promise<[ProductVariant](/references/services/classes/ProductVariant)>
Gets a product variant by id.
Parameters
variantIdstringRequiredReturns
Promise<ProductVariant>
retrieveBySKU
**retrieveBySKU**(sku, config?): Promise<[ProductVariant](/references/services/classes/ProductVariant)>
Gets a product variant by id.
Parameters
skustringRequiredReturns
Promise<ProductVariant>
setCurrencyPrice
**setCurrencyPrice**(variantId, price): Promise<[MoneyAmount](/references/services/classes/MoneyAmount)>
Parameters
variantIdstringRequiredReturns
Promise<MoneyAmount>
Deprecated
use addOrUpdateCurrencyPrices instead Sets the default price for the given currency.
setRegionPrice
**setRegionPrice**(variantId, price): Promise<[MoneyAmount](/references/services/classes/MoneyAmount)>
Parameters
variantIdstringRequiredReturns
Promise<MoneyAmount>
Deprecated
use addOrUpdateRegionPrices instead Sets the default price of a specific region
shouldRetryTransaction_
Protected **shouldRetryTransaction_**(err): boolean
Parameters
errRecord<string, unknown> | { code: string }RequiredReturns
boolean
booleanbooleanupdate
**update**(variantData): Promise<[ProductVariant](/references/services/classes/ProductVariant)[]>
Updates a collection of variant.
Parameters
variantData{ updateData: [UpdateProductVariantInput](/references/services/types/UpdateProductVariantInput) ; variant: [ProductVariant](/references/services/classes/ProductVariant) }[]RequiredReturns
Promise<ProductVariant[]>
**update**(variantOrVariantId, update): Promise<[ProductVariant](/references/services/classes/ProductVariant)>
Updates a variant. Price updates should use dedicated methods. The function will throw, if price updates are attempted.
Parameters
Returns
Promise<ProductVariant>
**update**(variantOrVariantId, update): Promise<[ProductVariant](/references/services/classes/ProductVariant)>
Parameters
Returns
Promise<ProductVariant>
updateBatch
Protected **updateBatch**(variantData): Promise<[ProductVariant](/references/services/classes/ProductVariant)[]>
Parameters
Returns
Promise<ProductVariant[]>
updateOptionValue
**updateOptionValue**(variantId, optionId, optionValue): Promise<[ProductOptionValue](/references/services/classes/ProductOptionValue)>
Updates variant's option value. Option value must be of type string or number.
Parameters
variantIdstringRequiredoptionIdstringRequiredoptionValuestringRequiredReturns
Promise<ProductOptionValue>
updateVariantPrices
**updateVariantPrices**(data): Promise<void>
Updates variant/prices collection. Deletes any prices that are not in the update object, and is not associated with a price list.
Parameters
Returns
Promise<void>
PromisePromise<void>Required**updateVariantPrices**(variantId, prices): Promise<void>
Updates a variant's prices. Deletes any prices that are not in the update object, and is not associated with a price list.
Parameters
variantIdstringRequiredReturns
Promise<void>
PromisePromise<void>RequiredupdateVariantPricesBatch
Protected **updateVariantPricesBatch**(data): Promise<void>
Parameters
Returns
Promise<void>
PromisePromise<void>RequiredupsertCurrencyPrices
**upsertCurrencyPrices**(data): Promise<void>
Parameters
data{ price: [WithRequiredProperty](/references/services/types/WithRequiredProperty)<[ProductVariantPrice](/references/services/types/ProductVariantPrice), "currency_code"> ; variantId: string }[]RequiredReturns
Promise<void>
PromisePromise<void>RequiredupsertRegionPrices
**upsertRegionPrices**(data): Promise<void>
Parameters
Returns
Promise<void>
PromisePromise<void>RequiredvalidateVariantsToCreate_
Protected **validateVariantsToCreate_**(product, variants): void
Parameters
Returns
void
voidvoidwithTransaction
**withTransaction**(transactionManager?): [ProductVariantService](/references/services/classes/ProductVariantService)
Parameters
transactionManagerEntityManager