ProductVariantService
Constructors
constructor
new ProductVariantService(«destructured»
)
Parameters
__namedParameters
ObjectRequiredProperties
__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 | EntityManagerRequiredEvents
objectRequiredEvents.CREATED
stringRequiredDefault: "product-variant.created"
Events.DELETED
stringRequiredDefault: "product-variant.deleted"
Events.UPDATED
stringRequiredDefault: "product-variant.updated"
Accessors
activeManager_
Protected
get
activeManager_(): EntityManager
Returns
EntityManager
EntityManager
EntityManagerRequiredMethods
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
variantId
stringRequiredoptionId
stringRequiredoptionValue
stringRequiredReturns
Promise
<ProductOptionValue
>
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.
TResult
objectRequiredTError
objectRequiredParameters
work
(transactionManager: EntityManager) => Promise<TResult>RequiredisolationOrErrorHandler
IsolationLevel | (error: TError) => Promise<void | TResult>maybeErrorHandlerOrDontFail
(error: TError) => Promise<void | TResult>Returns
Promise
<TResult
>
Promise
Promise<TResult>Requiredcreate
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.
TOutput
objectRequiredParameters
Returns
Promise
<TOutput
>
Promise
Promise<TOutput>Requireddelete
delete(variantIds
): Promise
<void
>
Deletes variant or variants. Will never fail due to delete being idempotent.
Parameters
variantIds
string | string[]RequiredReturns
Promise
<void
>
Promise
Promise<void>RequireddeleteOptionValue
deleteOptionValue(variantId
, optionId
): Promise
<void
>
Deletes option value from given variant. Will never fail due to delete being idempotent.
Parameters
variantId
stringRequiredoptionId
stringRequiredReturns
Promise
<void
>
Promise
Promise<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
q
stringReturns
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
variantId
stringRequiredReturns
Promise
<null
| number
>
Promise
Promise<null | number>RequiredisVariantInSalesChannels
isVariantInSalesChannels(id
, salesChannelIds
): Promise
<boolean
>
Check if the variant is assigned to at least one of the provided sales channels.
Parameters
id
stringRequiredsalesChannelIds
string[]RequiredReturns
Promise
<boolean
>
Promise
Promise<boolean>Requiredlist
list(selector
, config?
): Promise
<ProductVariant
[]>
Parameters
Returns
Promise
<ProductVariant
[]>
listAndCount
listAndCount(selector
, config?
): Promise
<[ProductVariant
[], number
]>
Parameters
Returns
Promise
<[ProductVariant
[], number
]>
retrieve
retrieve(variantId
, config?
): Promise
<ProductVariant
>
Gets a product variant by id.
Parameters
variantId
stringRequiredReturns
Promise
<ProductVariant
>
retrieveBySKU
retrieveBySKU(sku
, config?
): Promise
<ProductVariant
>
Gets a product variant by id.
Parameters
sku
stringRequiredReturns
Promise
<ProductVariant
>
setCurrencyPrice
setCurrencyPrice(variantId
, price
): Promise
<MoneyAmount
>
Parameters
variantId
stringRequiredReturns
Promise
<MoneyAmount
>
Deprecated
use addOrUpdateCurrencyPrices instead Sets the default price for the given currency.
setRegionPrice
setRegionPrice(variantId
, price
): Promise
<MoneyAmount
>
Parameters
variantId
stringRequiredReturns
Promise
<MoneyAmount
>
Deprecated
use addOrUpdateRegionPrices instead Sets the default price of a specific region
shouldRetryTransaction_
Protected
shouldRetryTransaction_(err
): boolean
Parameters
err
Record<string, unknown> | { code: string }RequiredReturns
boolean
boolean
booleanupdate
update(variantData
): Promise
<ProductVariant
[]>
Updates a collection of variant.
Parameters
Returns
Promise
<ProductVariant
[]>
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
>
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
variantId
stringRequiredoptionId
stringRequiredoptionValue
stringRequiredReturns
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
>
Promise
Promise<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
variantId
stringRequiredReturns
Promise
<void
>
Promise
Promise<void>RequiredupdateVariantPricesBatch
Protected
updateVariantPricesBatch(data
): Promise
<void
>
Parameters
Returns
Promise
<void
>
Promise
Promise<void>RequiredupsertCurrencyPrices
upsertCurrencyPrices(data
): Promise
<void
>
Parameters
data
{ price: WithRequiredProperty<ProductVariantPrice, "currency_code"> ; variantId: string }[]RequiredReturns
Promise
<void
>
Promise
Promise<void>RequiredupsertRegionPrices
upsertRegionPrices(data
): Promise
<void
>
Parameters
Returns
Promise
<void
>
Promise
Promise<void>RequiredvalidateVariantsToCreate_
Protected
validateVariantsToCreate_(product
, variants
): void
Parameters
Returns
void
void
voidwithTransaction
withTransaction(transactionManager?
): ProductVariantService
Parameters
transactionManager
EntityManager