ProductVariantService
Hierarchy
TransactionBaseService
↳
ProductVariantService
Constructors
constructor
new ProductVariantService(«destructured»
)
Parameters
Name |
---|
«destructured» |
Overrides
TransactionBaseService.constructor
Defined in
medusa/src/services/product-variant.ts:74
Properties
__configModule__
Protected
Optional
Readonly
__configModule__: Record<string
, unknown
>
Inherited from
TransactionBaseService.__configModule__
Defined in
medusa/src/interfaces/transaction-base-service.ts:14
__container__
Protected
Readonly
__container__: any
Inherited from
TransactionBaseService.__container__
Defined in
medusa/src/interfaces/transaction-base-service.ts:13
__moduleDeclaration__
Protected
Optional
Readonly
__moduleDeclaration__: Record<string
, unknown
>
Inherited from
TransactionBaseService.__moduleDeclaration__
Defined in
medusa/src/interfaces/transaction-base-service.ts:15
cartRepository_
Protected
Readonly
cartRepository_: Repository
<Cart
> & { findOneWithRelations
: Method findOneWithRelations ; findWithRelations
: Method findWithRelations }
Defined in
medusa/src/services/product-variant.ts:72
eventBus_
Protected
Readonly
eventBus_: EventBusService
Defined in
medusa/src/services/product-variant.ts:66
manager_
Protected
manager_: EntityManager
Inherited from
TransactionBaseService.manager_
Defined in
medusa/src/interfaces/transaction-base-service.ts:5
moneyAmountRepository_
Protected
Readonly
moneyAmountRepository_: 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 }
Defined in
medusa/src/services/product-variant.ts:69
priceSelectionStrategy_
Protected
Readonly
priceSelectionStrategy_: IPriceSelectionStrategy
Defined in
medusa/src/services/product-variant.ts:68
productOptionValueRepository_
Protected
Readonly
productOptionValueRepository_: Repository
<ProductOptionValue
>
Defined in
medusa/src/services/product-variant.ts:71
productRepository_
Protected
Readonly
productRepository_: 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 }
Defined in
medusa/src/services/product-variant.ts:65
productVariantRepository_
Protected
Readonly
productVariantRepository_: Repository
<ProductVariant
>
Defined in
medusa/src/services/product-variant.ts:64
regionService_
Protected
Readonly
regionService_: RegionService
Defined in
medusa/src/services/product-variant.ts:67
transactionManager_
Protected
transactionManager_: undefined
| EntityManager
Inherited from
TransactionBaseService.transactionManager_
Defined in
medusa/src/interfaces/transaction-base-service.ts:6
Events
Static
Events: Object
Type declaration
Name | Type |
---|---|
CREATED | string |
DELETED | string |
UPDATED | string |
Defined in
medusa/src/services/product-variant.ts:58
Accessors
activeManager_
Protected
get
activeManager_(): EntityManager
Returns
EntityManager
-EntityManager
:
Inherited from
TransactionBaseService.activeManager_
Defined in
medusa/src/interfaces/transaction-base-service.ts:8
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
Name | Description |
---|---|
variantId | string |
optionId | string |
optionValue | string |
Returns
Promise
<ProductOptionValue
>
-Promise
: the result of the update operation.
-ProductOptionValue
:
Defined in
medusa/src/services/product-variant.ts:843
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.
Name |
---|
TResult |
TError |
Parameters
Name | Description |
---|---|
work | (transactionManager : EntityManager ) => Promise <TResult > |
isolationOrErrorHandler? | IsolationLevel | (error : TError ) => Promise <void | TResult > |
maybeErrorHandlerOrDontFail? | (error : TError ) => Promise <void | TResult > |
Returns
Promise
<TResult
>
-Promise
: the result of the transactional work
Inherited from
TransactionBaseService.atomicPhase_
Defined in
medusa/src/interfaces/transaction-base-service.ts:56
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.
Name | Type |
---|---|
TVariants | CreateProductVariantInput | CreateProductVariantInput [] |
TOutput | object |
Parameters
Name | Description |
---|---|
productOrProductId | string | Product |
variants | CreateProductVariantInput | CreateProductVariantInput [] |
Returns
Promise
<TOutput
>
-Promise
: resolves to the creation result.
Defined in
medusa/src/services/product-variant.ts:167
delete
delete(variantIds
): Promise
<void
>
Deletes variant or variants. Will never fail due to delete being idempotent.
Parameters
Name | Description |
---|---|
variantIds | string | string [] |
Returns
Promise
<void
>
-Promise
: empty promise
Defined in
medusa/src/services/product-variant.ts:1013
deleteOptionValue
deleteOptionValue(variantId
, optionId
): Promise
<void
>
Deletes option value from given variant. Will never fail due to delete being idempotent.
Parameters
Name | Description |
---|---|
variantId | string |
optionId | string |
Returns
Promise
<void
>
-Promise
: empty promise
Defined in
medusa/src/services/product-variant.ts:870
getFreeTextQueryBuilder_
getFreeTextQueryBuilder_(variantRepo
, query
, q?
): SelectQueryBuilder
<ProductVariant
>
Lists variants based on the provided parameters and includes the count of variants that match the query.
Parameters
Name | Description |
---|---|
variantRepo | Repository <ProductVariant > |
query | FindWithRelationsOptions |
q? | string |
Returns
SelectQueryBuilder
<ProductVariant
>
-SelectQueryBuilder
: an array containing the products as the first element and the total
count of products that matches the query as the second element.
-ProductVariant
:
Defined in
medusa/src/services/product-variant.ts:1076
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
Name | Description |
---|---|
variantId | string |
context | GetRegionPriceContext |
Returns
Promise
<null
| number
>
-Promise
: the price specific to the region
-`null
| number`: (optional)
Defined in
medusa/src/services/product-variant.ts:708
isVariantInSalesChannels
isVariantInSalesChannels(id
, salesChannelIds
): Promise
<boolean
>
Check if the variant is assigned to at least one of the provided sales channels.
Parameters
Name | Description |
---|---|
id | string |
salesChannelIds | string [] |
Returns
Promise
<boolean
>
-Promise
:
-boolean
: (optional)
Defined in
medusa/src/services/product-variant.ts:1051
list
list(selector
, config?
): Promise
<ProductVariant
[]>
Parameters
Name | Description |
---|---|
selector | FilterableProductVariantProps |
config | FindConfig <ProductVariant > & PriceSelectionContext |
Returns
Promise
<ProductVariant
[]>
-Promise
: the result of the find operation
-ProductVariant[]
:
-ProductVariant
:
Defined in
medusa/src/services/product-variant.ts:959
listAndCount
listAndCount(selector
, config?
): Promise
<[ProductVariant
[], number
]>
Parameters
Name | Description |
---|---|
selector | FilterableProductVariantProps |
config | FindConfig <ProductVariant > & PriceSelectionContext |
Returns
Promise
<[ProductVariant
[], number
]>
-Promise
: the result of the find operation
-ProductVariant[]
:
-number
: (optional)
Defined in
medusa/src/services/product-variant.ts:898
retrieve
retrieve(variantId
, config?
): Promise
<ProductVariant
>
Gets a product variant by id.
Parameters
Name | Description |
---|---|
variantId | string |
config | FindConfig <ProductVariant > & PriceSelectionContext |
Returns
Promise
<ProductVariant
>
-Promise
: the product document.
-ProductVariant
:
Defined in
medusa/src/services/product-variant.ts:103
retrieveBySKU
retrieveBySKU(sku
, config?
): Promise
<ProductVariant
>
Gets a product variant by id.
Parameters
Name | Description |
---|---|
sku | string |
config | FindConfig <ProductVariant > & PriceSelectionContext |
Returns
Promise
<ProductVariant
>
-Promise
: the product document.
-ProductVariant
:
Defined in
medusa/src/services/product-variant.ts:131
setCurrencyPrice
setCurrencyPrice(variantId
, price
): Promise
<MoneyAmount
>
Parameters
Name | Description |
---|---|
variantId | string |
price | ProductVariantPrice |
Returns
Promise
<MoneyAmount
>
-Promise
: the result of the update operation
-MoneyAmount
:
Deprecated
use addOrUpdateCurrencyPrices instead Sets the default price for the given currency.
Defined in
medusa/src/services/product-variant.ts:784
setRegionPrice
setRegionPrice(variantId
, price
): Promise
<MoneyAmount
>
Parameters
Name | Description |
---|---|
variantId | string |
price | ProductVariantPrice |
Returns
Promise
<MoneyAmount
>
-Promise
: the result of the update operation
-MoneyAmount
:
Deprecated
use addOrUpdateRegionPrices instead Sets the default price of a specific region
Defined in
medusa/src/services/product-variant.ts:737
shouldRetryTransaction_
Protected
shouldRetryTransaction_(err
): boolean
Parameters
Name |
---|
err |
Returns
boolean
-boolean
: (optional)
Inherited from
TransactionBaseService.shouldRetryTransaction_
Defined in
medusa/src/interfaces/transaction-base-service.ts:37
update
update(variantData
): Promise
<ProductVariant
[]>
Updates a collection of variant.
Parameters
Name | Description |
---|---|
variantData | { updateData : UpdateProductVariantInput ; variant : ProductVariant }[] |
Returns
Promise
<ProductVariant
[]>
-Promise
: resolves to the update result.
-ProductVariant[]
:
-ProductVariant
:
Defined in
medusa/src/services/product-variant.ts:265
update(variantOrVariantId
, update
): Promise
<ProductVariant
>
Updates a variant. Price updates should use dedicated methods. The function will throw, if price updates are attempted.
Parameters
Name | Description |
---|---|
variantOrVariantId | string | Partial <ProductVariant > |
update | UpdateProductVariantInput |
Returns
Promise
<ProductVariant
>
-Promise
: resolves to the update result.
-ProductVariant
:
Defined in
medusa/src/services/product-variant.ts:280
update(variantOrVariantId
, update
): Promise
<ProductVariant
>
Parameters
Name |
---|
variantOrVariantId |
update |
Returns
Promise
<ProductVariant
>
-Promise
:
-ProductVariant
:
Defined in
medusa/src/services/product-variant.ts:285
updateBatch
Protected
updateBatch(variantData
): Promise
<ProductVariant
[]>
Parameters
Name |
---|
variantData |
Returns
Promise
<ProductVariant
[]>
-Promise
:
-ProductVariant[]
:
-ProductVariant
:
Defined in
medusa/src/services/product-variant.ts:339
updateOptionValue
updateOptionValue(variantId
, optionId
, optionValue
): Promise
<ProductOptionValue
>
Updates variant's option value. Option value must be of type string or number.
Parameters
Name | Description |
---|---|
variantId | string |
optionId | string |
optionValue | string |
Returns
Promise
<ProductOptionValue
>
-Promise
: the result of the update operation.
-ProductOptionValue
:
Defined in
medusa/src/services/product-variant.ts:805
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
Name |
---|
data |
Returns
Promise
<void
>
-Promise
: empty promise
Defined in
medusa/src/services/product-variant.ts:438
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
Name | Description |
---|---|
variantId | string |
prices | ProductVariantPrice [] |
Returns
Promise
<void
>
-Promise
: empty promise
Defined in
medusa/src/services/product-variant.ts:447
updateVariantPricesBatch
Protected
updateVariantPricesBatch(data
): Promise
<void
>
Parameters
Name |
---|
data |
Returns
Promise
<void
>
-Promise
:
Defined in
medusa/src/services/product-variant.ts:467
upsertCurrencyPrices
upsertCurrencyPrices(data
): Promise
<void
>
Parameters
Name |
---|
data |
Returns
Promise
<void
>
-Promise
:
Defined in
medusa/src/services/product-variant.ts:618
upsertRegionPrices
upsertRegionPrices(data
): Promise
<void
>
Parameters
Name |
---|
data |
Returns
Promise
<void
>
-Promise
:
Defined in
medusa/src/services/product-variant.ts:540
validateVariantsToCreate_
Protected
validateVariantsToCreate_(product
, variants
): void
Parameters
Name |
---|
product |
variants |
Returns
void
-void
: (optional)
Defined in
medusa/src/services/product-variant.ts:1111
withTransaction
withTransaction(transactionManager?
): ProductVariantService
Parameters
Name |
---|
transactionManager? |
Returns
-ProductVariantService
:
Inherited from
TransactionBaseService.withTransaction