Skip to main content

Class: ProductVariantService

Hierarchy

  • TransactionBaseServiceCopy to Clipboard

    ProductVariantServiceCopy to Clipboard

Constructors

constructor

new ProductVariantService(__namedParametersCopy to Clipboard)

Parameters

NameType
__namedParametersCopy to ClipboardObjectCopy to Clipboard

Overrides

TransactionBaseService.constructor

Defined in

packages/medusa/src/services/product-variant.ts:54

Properties

__configModule__

ProtectedCopy to Clipboard OptionalCopy to Clipboard ReadonlyCopy to Clipboard __configModule__: RecordCopy to Clipboard<stringCopy to Clipboard, unknownCopy to Clipboard>

Inherited from

TransactionBaseService.__configModule__

Defined in

packages/medusa/src/interfaces/transaction-base-service.ts:10


__container__

ProtectedCopy to Clipboard ReadonlyCopy to Clipboard __container__: anyCopy to Clipboard

Inherited from

TransactionBaseService.__container__

Defined in

packages/medusa/src/interfaces/transaction-base-service.ts:9


__moduleDeclaration__

ProtectedCopy to Clipboard OptionalCopy to Clipboard ReadonlyCopy to Clipboard __moduleDeclaration__: RecordCopy to Clipboard<stringCopy to Clipboard, unknownCopy to Clipboard>

Inherited from

TransactionBaseService.__moduleDeclaration__

Defined in

packages/medusa/src/interfaces/transaction-base-service.ts:11


cartRepository_

ProtectedCopy to Clipboard ReadonlyCopy to Clipboard cartRepository_: typeof CartRepositoryCopy to Clipboard

Defined in

packages/medusa/src/services/product-variant.ts:52


eventBus_

ProtectedCopy to Clipboard ReadonlyCopy to Clipboard eventBus_: EventBusServiceCopy to Clipboard

Defined in

packages/medusa/src/services/product-variant.ts:46


manager_

ProtectedCopy to Clipboard manager_: EntityManagerCopy to Clipboard

Overrides

TransactionBaseService.manager_

Defined in

packages/medusa/src/services/product-variant.ts:41


moneyAmountRepository_

ProtectedCopy to Clipboard ReadonlyCopy to Clipboard moneyAmountRepository_: typeof MoneyAmountRepositoryCopy to Clipboard

Defined in

packages/medusa/src/services/product-variant.ts:49


priceSelectionStrategy_

ProtectedCopy to Clipboard ReadonlyCopy to Clipboard priceSelectionStrategy_: IPriceSelectionStrategyCopy to Clipboard

Defined in

packages/medusa/src/services/product-variant.ts:48


productOptionValueRepository_

ProtectedCopy to Clipboard ReadonlyCopy to Clipboard productOptionValueRepository_: typeof ProductOptionValueRepositoryCopy to Clipboard

Defined in

packages/medusa/src/services/product-variant.ts:51


productRepository_

ProtectedCopy to Clipboard ReadonlyCopy to Clipboard productRepository_: typeof ProductRepositoryCopy to Clipboard

Defined in

packages/medusa/src/services/product-variant.ts:45


productVariantRepository_

ProtectedCopy to Clipboard ReadonlyCopy to Clipboard productVariantRepository_: typeof ProductVariantRepositoryCopy to Clipboard

Defined in

packages/medusa/src/services/product-variant.ts:44


regionService_

ProtectedCopy to Clipboard ReadonlyCopy to Clipboard regionService_: RegionServiceCopy to Clipboard

Defined in

packages/medusa/src/services/product-variant.ts:47


transactionManager_

ProtectedCopy to Clipboard transactionManager_: undefinedCopy to Clipboard | EntityManagerCopy to Clipboard

Overrides

TransactionBaseService.transactionManager_

Defined in

packages/medusa/src/services/product-variant.ts:42


Events

StaticCopy to Clipboard Events: ObjectCopy to Clipboard

Type declaration

NameType
CREATEDCopy to ClipboardstringCopy to Clipboard
DELETEDCopy to ClipboardstringCopy to Clipboard
UPDATEDCopy to ClipboardstringCopy to Clipboard

Defined in

packages/medusa/src/services/product-variant.ts:35

Methods

addOptionValue

addOptionValue(variantIdCopy to Clipboard, optionIdCopy to Clipboard, optionValueCopy to Clipboard): PromiseCopy to Clipboard<ProductOptionValueCopy to Clipboard>

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

NameTypeDescription
variantIdCopy to ClipboardstringCopy to Clipboardthe variant to decorate.
optionIdCopy to ClipboardstringCopy to Clipboardthe option from product.
optionValueCopy to ClipboardstringCopy to Clipboardoption value to add.

Returns

PromiseCopy to Clipboard<ProductOptionValueCopy to Clipboard>

the result of the update operation.

Defined in

packages/medusa/src/services/product-variant.ts:497


atomicPhase_

ProtectedCopy to Clipboard atomicPhase_<TResultCopy to Clipboard, TErrorCopy to Clipboard>(workCopy to Clipboard, isolationOrErrorHandler?Copy to Clipboard, maybeErrorHandlerOrDontFail?Copy to Clipboard): PromiseCopy to Clipboard<TResultCopy to Clipboard>

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.

Type parameters

Name
TResultCopy to Clipboard
TErrorCopy to Clipboard

Parameters

NameTypeDescription
workCopy to Clipboard(transactionManagerCopy to Clipboard: EntityManagerCopy to Clipboard) => PromiseCopy to Clipboard<TResultCopy to Clipboard>the transactional work to be done
isolationOrErrorHandler?Copy to ClipboardIsolationLevelCopy to Clipboard | (errorCopy to Clipboard: TErrorCopy to Clipboard) => PromiseCopy to Clipboard<voidCopy to Clipboard | TResultCopy to Clipboard>the isolation level to be used for the work.
maybeErrorHandlerOrDontFail?Copy to Clipboard(errorCopy to Clipboard: TErrorCopy to Clipboard) => PromiseCopy to Clipboard<voidCopy to Clipboard | TResultCopy to Clipboard>Potential error handler

Returns

PromiseCopy to Clipboard<TResultCopy to Clipboard>

the result of the transactional work

Inherited from

TransactionBaseService.atomicPhase_

Defined in

packages/medusa/src/interfaces/transaction-base-service.ts:50


create

create(productOrProductIdCopy to Clipboard, variantCopy to Clipboard): PromiseCopy to Clipboard<ProductVariantCopy to Clipboard>

Creates an unpublished product variant. Will validate against parent product to ensure that the variant can in fact be created.

Parameters

NameTypeDescription
productOrProductIdCopy to ClipboardstringCopy to Clipboard | ProductCopy to Clipboardthe product the variant will be added to
variantCopy to ClipboardCreateProductVariantInputCopy to Clipboardthe variant to create

Returns

PromiseCopy to Clipboard<ProductVariantCopy to Clipboard>

resolves to the creation result.

Defined in

packages/medusa/src/services/product-variant.ts:149


delete

delete(variantIdCopy to Clipboard): PromiseCopy to Clipboard<voidCopy to Clipboard>

Deletes variant. Will never fail due to delete being idempotent.

Parameters

NameTypeDescription
variantIdCopy to ClipboardstringCopy to Clipboardthe id of the variant to delete. Must be castable as an ObjectId

Returns

PromiseCopy to Clipboard<voidCopy to Clipboard>

empty promise

Defined in

packages/medusa/src/services/product-variant.ts:650


deleteOptionValue

deleteOptionValue(variantIdCopy to Clipboard, optionIdCopy to Clipboard): PromiseCopy to Clipboard<voidCopy to Clipboard>

Deletes option value from given variant. Will never fail due to delete being idempotent.

Parameters

NameTypeDescription
variantIdCopy to ClipboardstringCopy to Clipboardthe variant to decorate.
optionIdCopy to ClipboardstringCopy to Clipboardthe option from product.

Returns

PromiseCopy to Clipboard<voidCopy to Clipboard>

empty promise

Defined in

packages/medusa/src/services/product-variant.ts:524


getFreeTextQueryBuilder_

getFreeTextQueryBuilder_(variantRepoCopy to Clipboard, queryCopy to Clipboard, q?Copy to Clipboard): SelectQueryBuilderCopy to Clipboard<ProductVariantCopy to Clipboard>

Lists variants based on the provided parameters and includes the count of variants that match the query.

Parameters

NameTypeDescription
variantRepoCopy to ClipboardProductVariantRepositoryCopy to Clipboardthe variant repository
queryCopy to ClipboardFindWithRelationsOptionsCopy to Clipboardobject that defines the scope for what should be returned
q?Copy to ClipboardstringCopy to Clipboardfree text query

Returns

SelectQueryBuilderCopy to Clipboard<ProductVariantCopy to Clipboard>

an array containing the products as the first element and the total count of products that matches the query as the second element.

Defined in

packages/medusa/src/services/product-variant.ts:745


getRegionPrice

getRegionPrice(variantIdCopy to Clipboard, contextCopy to Clipboard): PromiseCopy to Clipboard<nullCopy to Clipboard | numberCopy to Clipboard>

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

NameTypeDescription
variantIdCopy to ClipboardstringCopy to Clipboardthe id of the variant to get price from
contextCopy to ClipboardGetRegionPriceContextCopy to Clipboardcontext for getting region price

Returns

PromiseCopy to Clipboard<nullCopy to Clipboard | numberCopy to Clipboard>

the price specific to the region

Defined in

packages/medusa/src/services/product-variant.ts:373


isVariantInSalesChannels

isVariantInSalesChannels(idCopy to Clipboard, salesChannelIdsCopy to Clipboard): PromiseCopy to Clipboard<booleanCopy to Clipboard>

Check if the variant is assigned to at least one of the provided sales channels.

Parameters

NameTypeDescription
idCopy to ClipboardstringCopy to Clipboardproduct variant id
salesChannelIdsCopy to ClipboardstringCopy to Clipboard[]an array of sales channel ids

Returns

PromiseCopy to Clipboard<booleanCopy to Clipboard>

Defined in

packages/medusa/src/services/product-variant.ts:683


list

list(selectorCopy to Clipboard, config?Copy to Clipboard): PromiseCopy to Clipboard<ProductVariantCopy to Clipboard[]>

Parameters

NameTypeDescription
selectorCopy to ClipboardFilterableProductVariantPropsCopy to Clipboardthe query object for find
configCopy to ClipboardFindConfigCopy to Clipboard<ProductVariantCopy to Clipboard> & PriceSelectionContextCopy to Clipboardquery config object for variant retrieval

Returns

PromiseCopy to Clipboard<ProductVariantCopy to Clipboard[]>

the result of the find operation

Defined in

packages/medusa/src/services/product-variant.ts:592


listAndCount

listAndCount(selectorCopy to Clipboard, config?Copy to Clipboard): PromiseCopy to Clipboard<[ProductVariantCopy to Clipboard[], numberCopy to Clipboard]>

Parameters

NameTypeDescription
selectorCopy to ClipboardFilterableProductVariantPropsCopy to Clipboardthe query object for find
configCopy to ClipboardFindConfigCopy to Clipboard<ProductVariantCopy to Clipboard> & PriceSelectionContextCopy to Clipboardquery config object for variant retrieval

Returns

PromiseCopy to Clipboard<[ProductVariantCopy to Clipboard[], numberCopy to Clipboard]>

the result of the find operation

Defined in

packages/medusa/src/services/product-variant.ts:551


prepareListQuery_

prepareListQuery_(selectorCopy to Clipboard, configCopy to Clipboard): ObjectCopy to Clipboard

Creates a query object to be used for list queries.

Parameters

NameTypeDescription
selectorCopy to ClipboardFilterableProductVariantPropsCopy to Clipboardthe selector to create the query from
configCopy to ClipboardFindConfigCopy to Clipboard<ProductVariantCopy to Clipboard>the config to use for the query

Returns

ObjectCopy to Clipboard

an object containing the query, relations and free-text search param.

NameType
q?Copy to ClipboardstringCopy to Clipboard
queryCopy to ClipboardFindWithRelationsOptionsCopy to Clipboard
relationsCopy to ClipboardstringCopy to Clipboard[]

Defined in

packages/medusa/src/services/product-variant.ts:706


retrieve

retrieve(variantIdCopy to Clipboard, config?Copy to Clipboard): PromiseCopy to Clipboard<ProductVariantCopy to Clipboard>

Gets a product variant by id.

Parameters

NameTypeDescription
variantIdCopy to ClipboardstringCopy to Clipboardthe id of the product to get.
configCopy to ClipboardFindConfigCopy to Clipboard<ProductVariantCopy to Clipboard> & PriceSelectionContextCopy to Clipboardquery config object for variant retrieval.

Returns

PromiseCopy to Clipboard<ProductVariantCopy to Clipboard>

the product document.

Defined in

packages/medusa/src/services/product-variant.ts:85


retrieveBySKU

retrieveBySKU(skuCopy to Clipboard, config?Copy to Clipboard): PromiseCopy to Clipboard<ProductVariantCopy to Clipboard>

Gets a product variant by id.

Parameters

NameTypeDescription
skuCopy to ClipboardstringCopy to ClipboardThe unique stock keeping unit used to identify the product variant.
configCopy to ClipboardFindConfigCopy to Clipboard<ProductVariantCopy to Clipboard> & PriceSelectionContextCopy to Clipboardquery config object for variant retrieval.

Returns

PromiseCopy to Clipboard<ProductVariantCopy to Clipboard>

the product document.

Defined in

packages/medusa/src/services/product-variant.ts:113


setCurrencyPrice

setCurrencyPrice(variantIdCopy to Clipboard, priceCopy to Clipboard): PromiseCopy to Clipboard<MoneyAmountCopy to Clipboard>

Sets the default price for the given currency.

Parameters

NameTypeDescription
variantIdCopy to ClipboardstringCopy to Clipboardthe id of the variant to set prices for
priceCopy to ClipboardProductVariantPriceCopy to Clipboardthe price for the variant

Returns

PromiseCopy to Clipboard<MoneyAmountCopy to Clipboard>

the result of the update operation

Defined in

packages/medusa/src/services/product-variant.ts:438


setRegionPrice

setRegionPrice(variantIdCopy to Clipboard, priceCopy to Clipboard): PromiseCopy to Clipboard<MoneyAmountCopy to Clipboard>

Sets the default price of a specific region

Parameters

NameTypeDescription
variantIdCopy to ClipboardstringCopy to Clipboardthe id of the variant to update
priceCopy to ClipboardProductVariantPriceCopy to Clipboardthe price for the variant.

Returns

PromiseCopy to Clipboard<MoneyAmountCopy to Clipboard>

the result of the update operation

Defined in

packages/medusa/src/services/product-variant.ts:402


shouldRetryTransaction_

ProtectedCopy to Clipboard shouldRetryTransaction_(errCopy to Clipboard): booleanCopy to Clipboard

Parameters

NameType
errCopy to ClipboardRecordCopy to Clipboard<stringCopy to Clipboard, unknownCopy to Clipboard> | { codeCopy to Clipboard: stringCopy to Clipboard }

Returns

booleanCopy to Clipboard

Inherited from

TransactionBaseService.shouldRetryTransaction_

Defined in

packages/medusa/src/interfaces/transaction-base-service.ts:31


update

update(variantOrVariantIdCopy to Clipboard, updateCopy to Clipboard): PromiseCopy to Clipboard<ProductVariantCopy to Clipboard>

Updates a variant. Price updates should use dedicated methods. The function will throw, if price updates are attempted.

Parameters

NameTypeDescription
variantOrVariantIdCopy to ClipboardstringCopy to Clipboard | PartialCopy to Clipboard<ProductVariantCopy to Clipboard>variant or id of a variant.
updateCopy to ClipboardUpdateProductVariantInputCopy to Clipboardan object with the update values.

Returns

PromiseCopy to Clipboard<ProductVariantCopy to Clipboard>

resolves to the update result.

Defined in

packages/medusa/src/services/product-variant.ts:257


updateOptionValue

updateOptionValue(variantIdCopy to Clipboard, optionIdCopy to Clipboard, optionValueCopy to Clipboard): PromiseCopy to Clipboard<ProductOptionValueCopy to Clipboard>

Updates variant's option value. Option value must be of type string or number.

Parameters

NameTypeDescription
variantIdCopy to ClipboardstringCopy to Clipboardthe variant to decorate.
optionIdCopy to ClipboardstringCopy to Clipboardthe option from product.
optionValueCopy to ClipboardstringCopy to Clipboardoption value to add.

Returns

PromiseCopy to Clipboard<ProductOptionValueCopy to Clipboard>

the result of the update operation.

Defined in

packages/medusa/src/services/product-variant.ts:459


updateVariantPrices

updateVariantPrices(variantIdCopy to Clipboard, pricesCopy to Clipboard): PromiseCopy to Clipboard<voidCopy to Clipboard>

Updates a variant's prices. Deletes any prices that are not in the update object, and is not associated with a price list.

Parameters

NameTypeDescription
variantIdCopy to ClipboardstringCopy to Clipboardthe id of variant
pricesCopy to ClipboardProductVariantPriceCopy to Clipboard[]the update prices

Returns

PromiseCopy to Clipboard<voidCopy to Clipboard>

empty promise

Defined in

packages/medusa/src/services/product-variant.ts:335


withTransaction

withTransaction(transactionManager?Copy to Clipboard): ProductVariantServiceCopy to Clipboard

Parameters

NameType
transactionManager?Copy to ClipboardEntityManagerCopy to Clipboard

Returns

ProductVariantServiceCopy to Clipboard

Inherited from

TransactionBaseService.withTransaction

Defined in

packages/medusa/src/interfaces/transaction-base-service.ts:14