ProductVariantService
internal.internal.ProductVariantService
Properties
__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.CREATEDstringRequiredEvents.DELETEDstringRequiredEvents.UPDATEDstringRequiredAccessors
activeManager_
Protected get activeManager_(): EntityManager
Returns
EntityManager
EntityManagerEntityManagerRequiredInherited from
TransactionBaseService.activeManager_
Methods
addOptionValue
addOptionValue(variantId, optionId, optionValue): Promise<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>
the result of the update operation.
atomicPhase_
Protected atomicPhase_<TResult, 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>RequiredInherited from
TransactionBaseService.atomicPhase_
create
create<TVariants, 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>
Lists variants based on the provided parameters and includes the count of variants that match the query.
Parameters
qstringReturns
SelectQueryBuilder<ProductVariant>
an array containing the products as the first element and the total
count of products that matches the query as the second element.
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>Requiredthe price specific to the region
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>Required
PromisePromise<boolean>Requiredlist
list(selector, config?): Promise<ProductVariant[]>
Parameters
Returns
Promise<ProductVariant[]>
the result of the find operation
listAndCount
listAndCount(selector, config?): Promise<[ProductVariant[], number]>
Parameters
Returns
Promise<[ProductVariant[], number]>
the result of the find operation
retrieve
retrieve(variantId, config?): Promise<ProductVariant>
Gets a product variant by id.
Parameters
variantIdstringRequiredReturns
Promise<ProductVariant>
the product document.
retrieveBySKU
retrieveBySKU(sku, config?): Promise<ProductVariant>
Gets a product variant by id.
Parameters
skustringRequiredReturns
Promise<ProductVariant>
the product document.
setCurrencyPrice
setCurrencyPrice(variantId, price): Promise<MoneyAmount>
Parameters
variantIdstringRequiredReturns
Promise<MoneyAmount>
the result of the update operation
Deprecated
use addOrUpdateCurrencyPrices instead Sets the default price for the given currency.
setRegionPrice
setRegionPrice(variantId, price): Promise<MoneyAmount>
Parameters
variantIdstringRequiredReturns
Promise<MoneyAmount>
the result of the update operation
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
booleanbooleanInherited from
TransactionBaseService.shouldRetryTransaction_
update
update(variantData): Promise<ProductVariant[]>
Updates a collection of variant.
Parameters
Returns
Promise<ProductVariant[]>
resolves to the update result.
update(variantOrVariantId, update): Promise<ProductVariant>
Updates a variant. Price updates should use dedicated methods. The function will throw, if price updates are attempted.
Parameters
Returns
Promise<ProductVariant>
resolves to the update result.
update(variantOrVariantId, update): Promise<ProductVariant>
Parameters
Returns
Promise<ProductVariant>
updateBatch
Protected updateBatch(variantData): Promise<ProductVariant[]>
Parameters
Returns
Promise<ProductVariant[]>
updateOptionValue
updateOptionValue(variantId, optionId, optionValue): Promise<ProductOptionValue>
Updates variant's option value. Option value must be of type string or number.
Parameters
variantIdstringRequiredoptionIdstringRequiredoptionValuestringRequiredReturns
Promise<ProductOptionValue>
the result of the update operation.
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>RequiredupdateVariantPrices(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<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
Parameters
transactionManagerEntityManager