Skip to main content

Class: ShippingOptionService

Provides layer to manipulate profiles.

Hierarchy

  • "medusa-interfaces"

    ShippingOptionService

Constructors

constructor

new ShippingOptionService(__namedParameters)

Parameters

NameType
__namedParametersObject

Overrides

BaseService.constructor

Defined in

services/shipping-option.js:9

Methods

addRequirement

addRequirement(optionId, requirement): Promise<any>

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

Parameters

NameTypeDescription
optionIdstringthe option to add the requirement to.
requirementShippingRequirementthe requirement for the option.

Returns

Promise<any>

the result of update

Defined in

services/shipping-option.js:594


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

NameTypeDescription
dataShippingOptionthe data to create shipping options

Returns

Promise<ShippingOption>

the result of the create operation

Defined in

services/shipping-option.js:350


createShippingMethod

createShippingMethod(optionId, data, config): ShippingMethod

Creates a shipping method for a given cart.

Parameters

NameTypeDescription
optionIdstringthe id of the option to use for the method.
dataanythe optional provider data to use.
configanythe cart to create the shipping method for.

Returns

ShippingMethod

the resulting shipping method.

Defined in

services/shipping-option.js:231


decorate

decorate(optionId, fields?, expandFields?): ShippingOption

Decorates a shipping option.

Parameters

NameTypeDefault valueDescription
optionIdShippingOptionundefinedthe shipping option to decorate using optionId.
fieldsstring[][]the fields to include.
expandFieldsstring[][]fields to expand.

Returns

ShippingOption

the decorated ShippingOption.

Defined in

services/shipping-option.js:645


delete

delete(optionId): Promise<any>

Deletes a profile with a given profile id.

Parameters

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

Returns

Promise<any>

the result of the delete operation.

Defined in

services/shipping-option.js:566


deleteShippingMethods

deleteShippingMethods(shippingMethods): Promise<any>

Removes a given shipping method

Parameters

NameTypeDescription
shippingMethodsanythe shipping method to remove

Returns

Promise<any>

Defined in

services/shipping-option.js:213


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

NameTypeDescription
optionShippingOptionthe shipping option to retrieve the price for.
dataShippingDatathe shipping data to retrieve the price.
cartanythe context in which the price should be retrieved.

Returns

Promise<number>

the price of the shipping option.

Defined in

services/shipping-option.js:697


list

list(selector, config?): Promise<any>

Parameters

NameTypeDescription
selectoranythe query object for find
configanyconfig object

Returns

Promise<any>

the result of the find operation

Defined in

services/shipping-option.js:123


listAndCount

listAndCount(selector, config?): Promise<any>

Parameters

NameTypeDescription
selectoranythe query object for find
configanyconfig object

Returns

Promise<any>

the result of the find operation

Defined in

services/shipping-option.js:135


removeRequirement

removeRequirement(requirementId): Promise<any>

Removes a requirement from a shipping option

Parameters

NameTypeDescription
requirementIdstringthe id of the requirement to remove

Returns

Promise<any>

the result of update

Defined in

services/shipping-option.js:620


retrieve

retrieve(optionId, options?): Promise<Product>

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

Parameters

NameTypeDescription
optionIdstringthe id of the profile to get.
optionsanythe options to get a profile

Returns

Promise<Product>

the profile document.

Defined in

services/shipping-option.js:149


setMetadata_

setMetadata_(option, metadata): Promise<any>

Dedicated method to set metadata for a shipping option.

Parameters

NameTypeDescription
optionanythe option to set metadata for.
metadataanyobject for metadata field

Returns

Promise<any>

resolves to the updated result.

Defined in

services/shipping-option.js:664


update

update(optionId, update): Promise<any>

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

NameTypeDescription
optionIdstringthe id of the option. Must be a string that can be casted to an ObjectId
updateanyan object with the update values.

Returns

Promise<any>

resolves to the update result.

Defined in

services/shipping-option.js:464


updateShippingMethod

updateShippingMethod(id, update): Promise<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

NameTypeDescription
idstringthe id of the shipping method to update
updateanythe values to update the method with

Returns

Promise<ShippingMethod>

the resulting shipping method

Defined in

services/shipping-option.js:184


validateCartOption

validateCartOption(option, cart): 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

NameTypeDescription
optionanythe option object to check
cartCartthe cart object to check against

Returns

ShippingOption

the validated shipping option

Defined in

services/shipping-option.js:309


validatePriceType_

validatePriceType_(priceType, option): Promise<ShippingOptionPrice>

Validates a shipping option price

Parameters

NameTypeDescription
priceTypeShippingOptionPricethe price to validate
optionShippingOptionthe option to validate against

Returns

Promise<ShippingOptionPrice>

the validated price

Defined in

services/shipping-option.js:431


validateRequirement_

validateRequirement_(requirement, optionId): ShippingRequirement

Validates a requirement

Parameters

NameTypeDescription
requirementShippingRequirementthe requirement to validate
optionIdstringthe id to validate the requirement

Returns

ShippingRequirement

a validated shipping requirement

Defined in

services/shipping-option.js:63


withTransaction

withTransaction(transactionManager): ShippingOptionService

Parameters

NameType
transactionManagerany

Returns

ShippingOptionService

Defined in

services/shipping-option.js:38