ShippingOptionService
Provides layer to manipulate profiles.
Constructors
constructor
**new ShippingOptionService**(«destructured»)
Parameters
Properties
__configModule__
Record<string, unknown>__container__
anyRequired__moduleDeclaration__
Record<string, unknown>manager_
EntityManagerRequiredoptionRepository_
Repository<ShippingOption> & { upsertShippingProfile: Method upsertShippingProfile }RequiredtransactionManager_
undefined | EntityManagerRequiredAccessors
activeManager_
Protected get**activeManager_**(): EntityManager
Returns
EntityManager
EntityManager
EntityManagerRequiredMethods
addRequirement
**addRequirement**(optionId, requirement): Promise<[ShippingOption](/references/services/classes/ShippingOption)>
Adds a requirement to a shipping option. Only 1 requirement of each type is allowed.
Parameters
optionId
stringRequiredReturns
Promise<ShippingOption>
atomicPhase_
Protected **atomicPhase_**<TypeParameter TResult, TypeParameter 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**(data): Promise<[ShippingOption](/references/services/classes/ShippingOption)>
Creates a new shipping option. Used both for outbound and inbound shipping
options. The difference is registered by the is_return
field which
defaults to false.
Parameters
Returns
Promise<ShippingOption>
createShippingMethod
**createShippingMethod**(optionId, data, config): Promise<[ShippingMethod](/references/services/classes/ShippingMethod)>
Creates a shipping method for a given cart.
Parameters
optionId
stringRequireddata
Record<string, unknown>RequiredReturns
Promise<ShippingMethod>
delete
**delete**(optionId): Promise<void \| [ShippingOption](/references/services/classes/ShippingOption)>
Deletes a profile with a given profile id.
Parameters
optionId
stringRequiredReturns
Promise<void | ShippingOption>
deleteShippingMethods
**deleteShippingMethods**(shippingMethods): Promise<[ShippingMethod](/references/services/classes/ShippingMethod)[]>
Removes a given shipping method
Parameters
Returns
Promise<ShippingMethod[]>
getPrice_
**getPrice_**(option, data, cart): Promise<number>
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
data
Record<string, unknown>RequiredReturns
Promise<number>
Promise
Promise<number>Requiredlist
**list**(selector, config?): Promise<[ShippingOption](/references/services/classes/ShippingOption)[]>
Parameters
Returns
Promise<ShippingOption[]>
listAndCount
**listAndCount**(selector, config?): Promise<[[ShippingOption](/references/services/classes/ShippingOption)[], number]>
Parameters
Returns
Promise<[ShippingOption[], number]>
removeRequirement
**removeRequirement**(requirementId): Promise<void \| [ShippingOptionRequirement](/references/services/classes/ShippingOptionRequirement)>
Removes a requirement from a shipping option
Parameters
requirementId
anyRequiredReturns
Promise<void | ShippingOptionRequirement>
retrieve
**retrieve**(optionId, options?): Promise<[ShippingOption](/references/services/classes/ShippingOption)>
Gets a profile by id. Throws in case of DB Error and if profile was not found.
Parameters
optionId
anyRequiredDefault: {}
Returns
Promise<ShippingOption>
shouldRetryTransaction_
Protected **shouldRetryTransaction_**(err): boolean
Parameters
err
Record<string, unknown> | { code: string }RequiredReturns
boolean
boolean
booleanupdate
**update**(optionId, update): Promise<[ShippingOption](/references/services/classes/ShippingOption)>
Updates a profile. Metadata updates and product updates should use
dedicated methods, e.g. setMetadata
, etc. The function
will throw errors if metadata or product updates are attempted.
Parameters
optionId
stringRequiredReturns
Promise<ShippingOption>
updateShippingMethod
**updateShippingMethod**(id, update): Promise<undefined \| [ShippingMethod](/references/services/classes/ShippingMethod)>
Updates a shipping method's associations. Useful when a cart is completed and its methods should be copied to an order/swap entity.
Parameters
id
stringRequiredReturns
Promise<undefined | ShippingMethod>
updateShippingProfile
**updateShippingProfile**(optionIds, profileId): Promise<[ShippingOption](/references/services/classes/ShippingOption)[]>
Parameters
optionIds
string | string[]RequiredprofileId
stringRequiredReturns
Promise<ShippingOption[]>
validateAndMutatePrice
Private **validateAndMutatePrice**(option, priceInput): Promise<[CreateShippingOptionInput](/references/services/types/CreateShippingOptionInput) \| [Omit](/references/services/types/Omit)<[ShippingOption](/references/services/classes/ShippingOption),
"beforeInsert">>
Parameters
Returns
Promise<CreateShippingOptionInput | Omit<ShippingOption, "beforeInsert"
>>
validateCartOption
**validateCartOption**(option, cart): Promise<
null \| [ShippingOption](/references/services/classes/ShippingOption)>
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
Returns
Promise<null
| ShippingOption>
validatePriceType_
**validatePriceType_**(priceType, option): Promise<[ShippingOptionPriceType](/references/services/enums/ShippingOptionPriceType)>
Validates a shipping option price
Parameters
Returns
Promise<ShippingOptionPriceType>
validateRequirement_
**validateRequirement_**(requirement, optionId?): Promise<[ShippingOptionRequirement](/references/services/classes/ShippingOptionRequirement)>
Validates a requirement
Parameters
optionId
undefined | stringRequiredDefault: undefined
Returns
Promise<ShippingOptionRequirement>
withTransaction
**withTransaction**(transactionManager?): [ShippingOptionService](/references/services/classes/ShippingOptionService)
Parameters
transactionManager
EntityManager