Skip to main content
Skip to main content

ShippingOptionService

Provides layer to manipulate profiles.

constructor

Parameters

__namedParametersInjectedDependenciesRequired

Properties

manager_EntityManagerRequired
transactionManager_undefined | EntityManagerRequired
__container__anyRequired
providerService_FulfillmentProviderServiceRequired
regionService_RegionServiceRequired
requirementRepository_Repository<ShippingOptionRequirement>Required
optionRepository_Repository<ShippingOption> & objectRequired
methodRepository_Repository<ShippingMethod>Required
featureFlagRouter_FlagRouterRequired
__configModule__Record<string, unknown>
__moduleDeclaration__Record<string, unknown>

Accessors

activeManager_

Returns

EntityManagerEntityManagerRequired

Methods

withTransaction

Parameters

transactionManagerEntityManager

Returns

thisthisRequired

shouldRetryTransaction_

Parameters

errRecord<string, unknown> | objectRequired

Returns

booleanbooleanRequired

atomicPhase_

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

TResultobjectRequired
TErrorobjectRequired

Parameters

work(transactionManager: EntityManager) => Promise<TResult>Required
the transactional work to be done
isolationOrErrorHandlerIsolationLevel | (error: TError) => Promise<void | TResult>
the isolation level to be used for the work.
maybeErrorHandlerOrDontFail(error: TError) => Promise<void | TResult>
Potential error handler

Returns

PromisePromise<TResult>Required
the result of the transactional work

validateRequirement_

Validates a requirement

Parameters

requirementValidateRequirementTypeInputRequired
the requirement to validate
optionIdundefined | stringRequired
the id to validate the requirement

Default: undefined

Returns

PromisePromise<ShippingOptionRequirement>Required
a validated shipping requirement

list

Parameters

selectorSelector<ShippingOption> & objectRequired
the query object for find

Default: {}

configFindConfig<ShippingOption>Required
config object

Returns

PromisePromise<ShippingOption[]>Required
the result of the find operation

listAndCount

Parameters

selectorSelector<ShippingOption> & objectRequired
the query object for find

Default: {}

configFindConfig<ShippingOption>Required
config object

Returns

PromisePromise<[ShippingOption[], number]>Required
the result of the find operation

retrieve

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

Parameters

optionIdanyRequired
the id of the profile to get.
optionsFindConfig<ShippingOption>Required
the options to get a profile

Default: {}

Returns

PromisePromise<ShippingOption>Required
the profile document.

updateShippingMethod

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

Parameters

idstringRequired
the id of the shipping method to update
updateShippingMethodUpdateRequired
the values to update the method with

Returns

PromisePromise<undefined | ShippingMethod>Required
the resulting shipping method

deleteShippingMethods

Removes a given shipping method

Parameters

shippingMethodsShippingMethod | ShippingMethod[]Required
the shipping method to remove

Returns

PromisePromise<ShippingMethod[]>Required
removed shipping methods

createShippingMethod

Creates a shipping method for a given cart.

Parameters

optionIdstringRequired
the id of the option to use for the method.
dataRecord<string, unknown>Required
the optional provider data to use.
configCreateShippingMethodDtoRequired
the cart to create the shipping method for.

Returns

PromisePromise<ShippingMethod>Required
the resulting shipping method.

validateCartOption

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

optionShippingOptionRequired
the option object to check
cartCartRequired
the cart object to check against

Returns

PromisePromise<null | ShippingOption>Required
the validated shipping option

validateAndMutatePrice

Parameters

optionShippingOption | CreateShippingOptionInputRequired
priceInputValidatePriceTypeAndAmountInputRequired

Returns

PromisePromise<CreateShippingOptionInput | Omit<ShippingOption, "beforeInsert">>Required

create

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

dataCreateShippingOptionInputRequired
the data to create shipping options

Returns

PromisePromise<ShippingOption>Required
the result of the create operation

validatePriceType_

Validates a shipping option price

Parameters

priceTypeShippingOptionPriceTypeRequired
the price to validate
optionShippingOptionRequired
the option to validate against

Returns

PromisePromise<ShippingOptionPriceType>Required
the validated price

update

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

optionIdstringRequired
the id of the option. Must be a string that can be casted to an ObjectId
updateUpdateShippingOptionInputRequired
an object with the update values.

Returns

PromisePromise<ShippingOption>Required
resolves to the update result.

delete

Deletes a profile with a given profile id.

Parameters

optionIdstringRequired
the id of the profile to delete. Must be castable as an ObjectId

Returns

PromisePromise<void | ShippingOption>Required
the result of the delete operation.

addRequirement

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

Parameters

optionIdstringRequired
the option to add the requirement to.
requirementShippingOptionRequirementRequired
the requirement for the option.

Returns

PromisePromise<ShippingOption>Required
the result of update

removeRequirement

Removes a requirement from a shipping option

Parameters

requirementIdanyRequired
the id of the requirement to remove

Returns

PromisePromise<void | ShippingOptionRequirement>Required
the result of update

updateShippingProfile

Parameters

optionIdsstring | string[]Required
ID or IDs of the shipping options to update
profileIdstringRequired
Shipping profile ID to update the shipping options with

Returns

PromisePromise<ShippingOption[]>Required
updated shipping options

getPrice_

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

optionShippingOptionRequired
the shipping option to retrieve the price for.
dataRecord<string, unknown>Required
the shipping data to retrieve the price.
cartundefined | Order | CartRequired
the context in which the price should be retrieved.

Returns

PromisePromise<number>Required
the price of the shipping option.
Was this section helpful?