Skip to main content

Class: ShippingOptionService

Provides layer to manipulate profiles.

Hierarchy

  • TransactionBaseServiceCopy to Clipboard

    ShippingOptionServiceCopy to Clipboard

Constructors

constructor

new ShippingOptionService(__namedParametersCopy to Clipboard)

Parameters

NameType
__namedParametersCopy to ClipboardInjectedDependenciesCopy to Clipboard

Overrides

TransactionBaseService.constructor

Defined in

medusa/src/services/shipping-option.ts:52

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

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


__container__

ProtectedCopy to Clipboard ReadonlyCopy to Clipboard __container__: anyCopy to Clipboard

Inherited from

TransactionBaseService.__container__

Defined in

medusa/src/interfaces/transaction-base-service.ts:13


__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

medusa/src/interfaces/transaction-base-service.ts:15


featureFlagRouter_

ProtectedCopy to Clipboard ReadonlyCopy to Clipboard featureFlagRouter_: FlagRouterCopy to Clipboard

Defined in

medusa/src/services/shipping-option.ts:50


manager_

ProtectedCopy to Clipboard manager_: EntityManagerCopy to Clipboard

Inherited from

TransactionBaseService.manager_

Defined in

medusa/src/interfaces/transaction-base-service.ts:5


methodRepository_

ProtectedCopy to Clipboard ReadonlyCopy to Clipboard methodRepository_: RepositoryCopy to Clipboard<ShippingMethodCopy to Clipboard>

Defined in

medusa/src/services/shipping-option.ts:49


optionRepository_

ProtectedCopy to Clipboard ReadonlyCopy to Clipboard optionRepository_: RepositoryCopy to Clipboard<ShippingOptionCopy to Clipboard> & { upsertShippingProfileCopy to Clipboard: (shippingOptionIdsCopy to Clipboard: stringCopy to Clipboard[], shippingProfileIdCopy to Clipboard: stringCopy to Clipboard) => PromiseCopy to Clipboard<ShippingOptionCopy to Clipboard[]> }

Defined in

medusa/src/services/shipping-option.ts:48


providerService_

ProtectedCopy to Clipboard ReadonlyCopy to Clipboard providerService_: FulfillmentProviderServiceCopy to Clipboard

Defined in

medusa/src/services/shipping-option.ts:44


regionService_

ProtectedCopy to Clipboard ReadonlyCopy to Clipboard regionService_: RegionServiceCopy to Clipboard

Defined in

medusa/src/services/shipping-option.ts:45


requirementRepository_

ProtectedCopy to Clipboard ReadonlyCopy to Clipboard requirementRepository_: RepositoryCopy to Clipboard<ShippingOptionRequirementCopy to Clipboard>

Defined in

medusa/src/services/shipping-option.ts:47


transactionManager_

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

Inherited from

TransactionBaseService.transactionManager_

Defined in

medusa/src/interfaces/transaction-base-service.ts:6

Accessors

activeManager_

ProtectedCopy to Clipboard getCopy to Clipboard activeManager_(): EntityManagerCopy to Clipboard

Returns

EntityManagerCopy to Clipboard

Inherited from

TransactionBaseService.activeManager_

Defined in

medusa/src/interfaces/transaction-base-service.ts:8

Methods

addRequirement

addRequirement(optionIdCopy to Clipboard, requirementCopy to Clipboard): PromiseCopy to Clipboard<ShippingOptionCopy to Clipboard>

Adds a requirement to a shipping option. Only 1 requirement of each type is allowed.

Parameters

NameTypeDescription
optionIdCopy to ClipboardstringCopy to Clipboardthe option to add the requirement to.
requirementCopy to ClipboardShippingOptionRequirementCopy to Clipboardthe requirement for the option.

Returns

PromiseCopy to Clipboard<ShippingOptionCopy to Clipboard>

the result of update

Defined in

medusa/src/services/shipping-option.ts:693


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

medusa/src/interfaces/transaction-base-service.ts:56


create

create(dataCopy to Clipboard): PromiseCopy to Clipboard<ShippingOptionCopy to Clipboard>

Creates a new shipping option. Used both for outbound and inbound shipping options. The difference is registered by the is_returnCopy to Clipboard field which defaults to false.

Parameters

NameTypeDescription
dataCopy to ClipboardCreateShippingOptionInputCopy to Clipboardthe data to create shipping options

Returns

PromiseCopy to Clipboard<ShippingOptionCopy to Clipboard>

the result of the create operation

Defined in

medusa/src/services/shipping-option.ts:431


createShippingMethod

createShippingMethod(optionIdCopy to Clipboard, dataCopy to Clipboard, configCopy to Clipboard): PromiseCopy to Clipboard<ShippingMethodCopy to Clipboard>

Creates a shipping method for a given cart.

Parameters

NameTypeDescription
optionIdCopy to ClipboardstringCopy to Clipboardthe id of the option to use for the method.
dataCopy to ClipboardRecordCopy to Clipboard<stringCopy to Clipboard, unknownCopy to Clipboard>the optional provider data to use.
configCopy to ClipboardCreateShippingMethodDtoCopy to Clipboardthe cart to create the shipping method for.

Returns

PromiseCopy to Clipboard<ShippingMethodCopy to Clipboard>

the resulting shipping method.

Defined in

medusa/src/services/shipping-option.ts:258


delete

delete(optionIdCopy to Clipboard): PromiseCopy to Clipboard<voidCopy to Clipboard | ShippingOptionCopy to Clipboard>

Deletes a profile with a given profile id.

Parameters

NameTypeDescription
optionIdCopy to ClipboardstringCopy to Clipboardthe id of the profile to delete. Must be castable as an ObjectId

Returns

PromiseCopy to Clipboard<voidCopy to Clipboard | ShippingOptionCopy to Clipboard>

the result of the delete operation.

Defined in

medusa/src/services/shipping-option.ts:671


deleteShippingMethods

deleteShippingMethods(shippingMethodsCopy to Clipboard): PromiseCopy to Clipboard<ShippingMethodCopy to Clipboard[]>

Removes a given shipping method

Parameters

NameTypeDescription
shippingMethodsCopy to ClipboardShippingMethodCopy to Clipboard | ShippingMethodCopy to Clipboard[]the shipping method to remove

Returns

PromiseCopy to Clipboard<ShippingMethodCopy to Clipboard[]>

removed shipping methods

Defined in

medusa/src/services/shipping-option.ts:238


getPrice_

getPrice_(optionCopy to Clipboard, dataCopy to Clipboard, cartCopy to Clipboard): PromiseCopy to Clipboard<numberCopy to Clipboard>

Returns the amount to be paid for a shipping method. Will ask the fulfillment provider to calculate the price if the shipping option has the price type "calculated".

Parameters

NameTypeDescription
optionCopy to ClipboardShippingOptionCopy to Clipboardthe shipping option to retrieve the price for.
dataCopy to ClipboardRecordCopy to Clipboard<stringCopy to Clipboard, unknownCopy to Clipboard>the shipping data to retrieve the price.
cartCopy to ClipboardundefinedCopy to Clipboard | OrderCopy to Clipboard | CartCopy to Clipboardthe context in which the price should be retrieved.

Returns

PromiseCopy to Clipboard<numberCopy to Clipboard>

the price of the shipping option.

Defined in

medusa/src/services/shipping-option.ts:771


list

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

Parameters

NameTypeDescription
selectorCopy to ClipboardSelectorCopy to Clipboard<ShippingOptionCopy to Clipboard>the query object for find
configCopy to ClipboardFindConfigCopy to Clipboard<ShippingOptionCopy to Clipboard>config object

Returns

PromiseCopy to Clipboard<ShippingOptionCopy to Clipboard[]>

the result of the find operation

Defined in

medusa/src/services/shipping-option.ts:145


listAndCount

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

Parameters

NameTypeDescription
selectorCopy to ClipboardSelectorCopy to Clipboard<ShippingOptionCopy to Clipboard>the query object for find
configCopy to ClipboardFindConfigCopy to Clipboard<ShippingOptionCopy to Clipboard>config object

Returns

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

the result of the find operation

Defined in

medusa/src/services/shipping-option.ts:160


removeRequirement

removeRequirement(requirementIdCopy to Clipboard): PromiseCopy to Clipboard<voidCopy to Clipboard | ShippingOptionRequirementCopy to Clipboard>

Removes a requirement from a shipping option

Parameters

NameTypeDescription
requirementIdCopy to ClipboardanyCopy to Clipboardthe id of the requirement to remove

Returns

PromiseCopy to Clipboard<voidCopy to Clipboard | ShippingOptionRequirementCopy to Clipboard>

the result of update

Defined in

medusa/src/services/shipping-option.ts:722


retrieve

retrieve(optionIdCopy to Clipboard, options?Copy to Clipboard): PromiseCopy to Clipboard<ShippingOptionCopy to Clipboard>

Gets a profile by id. Throws in case of DB Error and if profile was not found.

Parameters

NameTypeDescription
optionIdCopy to ClipboardanyCopy to Clipboardthe id of the profile to get.
optionsCopy to ClipboardFindConfigCopy to Clipboard<ShippingOptionCopy to Clipboard>the options to get a profile

Returns

PromiseCopy to Clipboard<ShippingOptionCopy to Clipboard>

the profile document.

Defined in

medusa/src/services/shipping-option.ts:177


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

medusa/src/interfaces/transaction-base-service.ts:37


update

update(optionIdCopy to Clipboard, updateCopy to Clipboard): PromiseCopy to Clipboard<ShippingOptionCopy to Clipboard>

Updates a profile. Metadata updates and product updates should use dedicated methods, e.g. setMetadataCopy to Clipboard, etc. The function will throw errors if metadata or product updates are attempted.

Parameters

NameTypeDescription
optionIdCopy to ClipboardstringCopy to Clipboardthe id of the option. Must be a string that can be casted to an ObjectId
updateCopy to ClipboardUpdateShippingOptionInputCopy to Clipboardan object with the update values.

Returns

PromiseCopy to Clipboard<ShippingOptionCopy to Clipboard>

resolves to the update result.

Defined in

medusa/src/services/shipping-option.ts:559


updateShippingMethod

updateShippingMethod(idCopy to Clipboard, updateCopy to Clipboard): PromiseCopy to Clipboard<undefinedCopy to Clipboard | ShippingMethodCopy to Clipboard>

Updates a shipping method's associations. Useful when a cart is completed and its methods should be copied to an order/swap entity.

Parameters

NameTypeDescription
idCopy to ClipboardstringCopy to Clipboardthe id of the shipping method to update
updateCopy to ClipboardShippingMethodUpdateCopy to Clipboardthe values to update the method with

Returns

PromiseCopy to Clipboard<undefinedCopy to Clipboard | ShippingMethodCopy to Clipboard>

the resulting shipping method

Defined in

medusa/src/services/shipping-option.ts:211


updateShippingProfile

updateShippingProfile(optionIdsCopy to Clipboard, profileIdCopy to Clipboard): PromiseCopy to Clipboard<ShippingOptionCopy to Clipboard[]>

Parameters

NameTypeDescription
optionIdsCopy to ClipboardstringCopy to Clipboard | stringCopy to Clipboard[]ID or IDs of the shipping options to update
profileIdCopy to ClipboardstringCopy to ClipboardShipping profile ID to update the shipping options with

Returns

PromiseCopy to Clipboard<ShippingOptionCopy to Clipboard[]>

updated shipping options

Defined in

medusa/src/services/shipping-option.ts:747


validateAndMutatePrice

PrivateCopy to Clipboard validateAndMutatePrice(optionCopy to Clipboard, priceInputCopy to Clipboard): PromiseCopy to Clipboard<CreateShippingOptionInputCopy to Clipboard | OmitCopy to Clipboard<ShippingOptionCopy to Clipboard, "beforeInsert"Copy to Clipboard>>

Parameters

NameType
optionCopy to ClipboardShippingOptionCopy to Clipboard | CreateShippingOptionInputCopy to Clipboard
priceInputCopy to ClipboardValidatePriceTypeAndAmountInputCopy to Clipboard

Returns

PromiseCopy to Clipboard<CreateShippingOptionInputCopy to Clipboard | OmitCopy to Clipboard<ShippingOptionCopy to Clipboard, "beforeInsert"Copy to Clipboard>>

Defined in

medusa/src/services/shipping-option.ts:388


validateCartOption

validateCartOption(optionCopy to Clipboard, cartCopy to Clipboard): PromiseCopy to Clipboard<nullCopy to Clipboard | ShippingOptionCopy to Clipboard>

Checks if a given option id is a valid option for a cart. If it is the option is returned with the correct price. Throws when region_ids do not match, or when the shipping option requirements are not satisfied.

Parameters

NameTypeDescription
optionCopy to ClipboardShippingOptionCopy to Clipboardthe option object to check
cartCopy to ClipboardCartCopy to Clipboardthe cart object to check against

Returns

PromiseCopy to Clipboard<nullCopy to Clipboard | ShippingOptionCopy to Clipboard>

the validated shipping option

Defined in

medusa/src/services/shipping-option.ts:346


validatePriceType_

validatePriceType_(priceTypeCopy to Clipboard, optionCopy to Clipboard): PromiseCopy to Clipboard<ShippingOptionPriceTypeCopy to Clipboard>

Validates a shipping option price

Parameters

NameTypeDescription
priceTypeCopy to ClipboardShippingOptionPriceTypeCopy to Clipboardthe price to validate
optionCopy to ClipboardShippingOptionCopy to Clipboardthe option to validate against

Returns

PromiseCopy to Clipboard<ShippingOptionPriceTypeCopy to Clipboard>

the validated price

Defined in

medusa/src/services/shipping-option.ts:519


validateRequirement_

validateRequirement_(requirementCopy to Clipboard, optionId?Copy to Clipboard): PromiseCopy to Clipboard<ShippingOptionRequirementCopy to Clipboard>

Validates a requirement

Parameters

NameTypeDefault valueDescription
requirementCopy to ClipboardShippingOptionRequirementCopy to ClipboardundefinedCopy to Clipboardthe requirement to validate
optionIdCopy to ClipboardundefinedCopy to Clipboard | stringCopy to ClipboardundefinedCopy to Clipboardthe id to validate the requirement

Returns

PromiseCopy to Clipboard<ShippingOptionRequirementCopy to Clipboard>

a validated shipping requirement

Defined in

medusa/src/services/shipping-option.ts:77


withTransaction

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

Parameters

NameType
transactionManager?Copy to ClipboardEntityManagerCopy to Clipboard

Returns

ShippingOptionServiceCopy to Clipboard

Inherited from

TransactionBaseService.withTransaction

Defined in

medusa/src/interfaces/transaction-base-service.ts:20

Was this page helpful?