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 | EntityManagerRequiredvalidateAndMutatePrice
anyRequiredAccessors
activeManager_
Protected
get
activeManager_(): EntityManager
Returns
EntityManager
EntityManager
EntityManagerRequiredInherited 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
optionId
stringRequiredReturns
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.
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>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
optionId
stringRequireddata
Record<string, unknown>RequiredReturns
Promise
<ShippingMethod
>
the resulting shipping method.
delete
delete(optionId
): Promise
<void
| ShippingOption
>
Deletes a profile with a given profile id.
Parameters
optionId
stringRequiredReturns
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
data
Record<string, unknown>RequiredReturns
Promise
<number
>
Promise
Promise<number>Requiredthe price of the shipping option.
Promise
Promise<number>Requiredlist
list(selector
, config?
): Promise
<ShippingOption
[]>
Parameters
config
FindConfig<ShippingOption>Returns
Promise
<ShippingOption
[]>
the result of the find operation
listAndCount
listAndCount(selector
, config?
): Promise
<[ShippingOption
[], number
]>
Parameters
config
FindConfig<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
requirementId
anyRequiredReturns
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
optionId
anyRequiredoptions
FindConfig<ShippingOption>Returns
Promise
<ShippingOption
>
the profile document.
shouldRetryTransaction_
Protected
shouldRetryTransaction_(err
): boolean
Parameters
err
Record<string, unknown> | { code: string }RequiredReturns
boolean
boolean
booleanInherited 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
optionId
stringRequiredReturns
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
id
stringRequiredReturns
Promise
<undefined
| ShippingMethod
>
the resulting shipping method
updateShippingProfile
updateShippingProfile(optionIds
, profileId
): Promise
<ShippingOption
[]>
Parameters
optionIds
string | string[]RequiredprofileId
stringRequiredReturns
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
optionId
stringReturns
Promise
<ShippingOptionRequirement
>
a validated shipping requirement
withTransaction
withTransaction(transactionManager?
): ShippingOptionService
Parameters
transactionManager
EntityManager