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
>
Adds a requirement to a shipping option. Only 1 requirement of each type is allowed.
Parameters
optionId
stringRequiredReturns
Promise
<ShippingOption
>
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>Requiredcreate
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
>
createShippingMethod
createShippingMethod(optionId
, data
, config
): Promise
<ShippingMethod
>
Creates a shipping method for a given cart.
Parameters
optionId
stringRequireddata
Record<string, unknown>RequiredReturns
Promise
<ShippingMethod
>
delete
delete(optionId
): Promise
<void
| ShippingOption
>
Deletes a profile with a given profile id.
Parameters
optionId
stringRequiredReturns
Promise
<void
| ShippingOption
>
deleteShippingMethods
deleteShippingMethods(shippingMethods
): Promise
<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
[]>
Parameters
Returns
Promise
<ShippingOption
[]>
listAndCount
listAndCount(selector
, config?
): Promise
<[ShippingOption
[], number
]>
Parameters
Returns
Promise
<[ShippingOption
[], number
]>
removeRequirement
removeRequirement(requirementId
): Promise
<void
| ShippingOptionRequirement
>
Removes a requirement from a shipping option
Parameters
requirementId
anyRequiredReturns
Promise
<void
| ShippingOptionRequirement
>
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
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
>
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
>
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
[]>
Parameters
optionIds
string | string[]RequiredprofileId
stringRequiredReturns
Promise
<ShippingOption
[]>
validateAndMutatePrice
Private
validateAndMutatePrice(option
, priceInput
): Promise
<CreateShippingOptionInput
| Omit
<ShippingOption
, "beforeInsert"
>>
Parameters
Returns
Promise
<CreateShippingOptionInput
| Omit
<ShippingOption
, "beforeInsert"
>>
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
>
validatePriceType_
validatePriceType_(priceType
, option
): Promise
<ShippingOptionPriceType
>
Validates a shipping option price
Parameters
Returns
Promise
<ShippingOptionPriceType
>
validateRequirement_
validateRequirement_(requirement
, optionId?
): Promise
<ShippingOptionRequirement
>
Validates a requirement
Parameters
optionId
undefined | stringRequiredDefault: undefined
Returns
Promise
<ShippingOptionRequirement
>
withTransaction
withTransaction(transactionManager?
): ShippingOptionService
Parameters
transactionManager
EntityManager