ShippingOptionService
internal.internal.ShippingOptionService
Provides layer to manipulate profiles.
Properties
__configModule__Record<string, unknown>__container__anyRequired__moduleDeclaration__Record<string, unknown>manager_EntityManagerRequiredoptionRepository_Repository<ShippingOption> & { upsertShippingProfile: Method upsertShippingProfile }RequiredtransactionManager_undefined | EntityManagerRequiredvalidateAndMutatePriceanyRequiredAccessors
activeManager_
Protected get activeManager_(): EntityManager
Returns
EntityManager
EntityManagerEntityManagerRequiredInherited from
TransactionBaseService.activeManager_
Methods
addRequirement
addRequirement(optionId, requirement): Promise<ShippingOption>
Adds a requirement to a shipping option. Only 1 requirement of each type is allowed.
Parameters
optionIdstringRequiredReturns
Promise<ShippingOption>
the result of update
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.
TResultobjectRequiredTErrorobjectRequiredParameters
work(transactionManager: EntityManager) => Promise<TResult>RequiredisolationOrErrorHandlerIsolationLevel | (error: TError) => Promise<void | TResult>maybeErrorHandlerOrDontFail(error: TError) => Promise<void | TResult>Returns
Promise<TResult>
PromisePromise<TResult>RequiredInherited from
TransactionBaseService.atomicPhase_
create
create(data): Promise<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>
the result of the create operation
createShippingMethod
createShippingMethod(optionId, data, config): Promise<ShippingMethod>
Creates a shipping method for a given cart.
Parameters
optionIdstringRequireddataRecord<string, unknown>RequiredReturns
Promise<ShippingMethod>
the resulting shipping method.
delete
delete(optionId): Promise<void | ShippingOption>
Deletes a profile with a given profile id.
Parameters
optionIdstringRequiredReturns
Promise<void | ShippingOption>
the result of the delete operation.
deleteShippingMethods
deleteShippingMethods(shippingMethods): Promise<ShippingMethod[]>
Removes a given shipping method
Parameters
Returns
Promise<ShippingMethod[]>
removed shipping methods
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
dataRecord<string, unknown>RequiredReturns
Promise<number>
PromisePromise<number>Requiredthe price of the shipping option.
PromisePromise<number>Requiredlist
list(selector, config?): Promise<ShippingOption[]>
Parameters
configFindConfig<ShippingOption>Returns
Promise<ShippingOption[]>
the result of the find operation
listAndCount
listAndCount(selector, config?): Promise<[ShippingOption[], number]>
Parameters
configFindConfig<ShippingOption>Returns
Promise<[ShippingOption[], number]>
the result of the find operation
removeRequirement
removeRequirement(requirementId): Promise<void | ShippingOptionRequirement>
Removes a requirement from a shipping option
Parameters
requirementIdanyRequiredReturns
Promise<void | ShippingOptionRequirement>
the result of update
retrieve
retrieve(optionId, options?): Promise<ShippingOption>
Gets a profile by id. Throws in case of DB Error and if profile was not found.
Parameters
optionIdanyRequiredoptionsFindConfig<ShippingOption>Returns
Promise<ShippingOption>
the profile document.
shouldRetryTransaction_
Protected shouldRetryTransaction_(err): boolean
Parameters
errRecord<string, unknown> | { code: string }RequiredReturns
boolean
booleanbooleanInherited from
TransactionBaseService.shouldRetryTransaction_
update
update(optionId, update): Promise<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
optionIdstringRequiredReturns
Promise<ShippingOption>
resolves to the update result.
updateShippingMethod
updateShippingMethod(id, update): Promise<undefined | 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
idstringRequiredReturns
Promise<undefined | ShippingMethod>
the resulting shipping method
updateShippingProfile
updateShippingProfile(optionIds, profileId): Promise<ShippingOption[]>
Parameters
optionIdsstring | string[]RequiredprofileIdstringRequiredReturns
Promise<ShippingOption[]>
updated shipping options
validateCartOption
validateCartOption(option, cart): Promise<null | 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>
the validated shipping option
validatePriceType_
validatePriceType_(priceType, option): Promise<ShippingOptionPriceType>
Validates a shipping option price
Parameters
Returns
Promise<ShippingOptionPriceType>
the validated price
validateRequirement_
validateRequirement_(requirement, optionId?): Promise<ShippingOptionRequirement>
Validates a requirement
Parameters
optionIdstringReturns
Promise<ShippingOptionRequirement>
a validated shipping requirement
withTransaction
withTransaction(transactionManager?): ShippingOptionService
Parameters
transactionManagerEntityManager