Skip to main content

Class: ShippingProfileService

Provides layer to manipulate profiles.

implements {BaseService}

Hierarchy

  • "medusa-interfaces"

    ShippingProfileService

Constructors

constructor

new ShippingProfileService(__namedParameters)

Parameters

NameType
__namedParametersObject

Overrides

BaseService.constructor

Defined in

services/shipping-profile.js:12

Methods

addProduct

addProduct(profileId, productId): Promise<any>

Adds a product to a profile. The method is idempotent, so multiple calls with the same product variant will have the same result.

Parameters

NameTypeDescription
profileIdstringthe profile to add the product to.
productIdstringthe product to add.

Returns

Promise<any>

the result of update

Defined in

services/shipping-profile.js:343


addShippingOption

addShippingOption(profileId, optionId): Promise<any>

Adds a shipping option to the profile. The shipping option can be used to fulfill the products in the products field.

Parameters

NameTypeDescription
profileIdstringthe profile to apply the shipping option to
optionIdstringthe option to add to the profile

Returns

Promise<any>

the result of the model update operation

Defined in

services/shipping-profile.js:361


create

create(profile): Promise<any>

Creates a new shipping profile.

Parameters

NameTypeDescription
profileShippingProfilethe shipping profile to create from

Returns

Promise<any>

the result of the create operation

Defined in

services/shipping-profile.js:235


createDefault

createDefault(): Promise<ShippingProfile>

Creates a default shipping profile, if this does not already exist.

Returns

Promise<ShippingProfile>

the shipping profile

Defined in

services/shipping-profile.js:167


createGiftCardDefault

createGiftCardDefault(): Promise<ShippingProfile>

Creates a default shipping profile, for gift cards if unless it already exists.

Returns

Promise<ShippingProfile>

the shipping profile

Defined in

services/shipping-profile.js:209


decorate

decorate(profile, fields, expandFields?): Profile

Decorates a profile.

Parameters

NameTypeDefault valueDescription
profileProfileundefinedthe profile to decorate.
fieldsstring[]undefinedthe fields to include.
expandFieldsstring[][]fields to expand.

Returns

Profile

return the decorated profile.

Defined in

services/shipping-profile.js:379


delete

delete(profileId): Promise<any>

Deletes a profile with a given profile id.

Parameters

NameTypeDescription
profileIdstringthe 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-profile.js:317


fetchCartOptions

fetchCartOptions(cart): [ShippingOption]

Finds all the shipping profiles that cover the products in a cart, and validates all options that are available for the cart.

Parameters

NameTypeDescription
cartCartthe cart object to find shipping options for

Returns

[ShippingOption]

a list of the available shipping options

Defined in

services/shipping-profile.js:425


fetchOptionsByProductIds

fetchOptionsByProductIds(productIds, filter): Promise<any[]>

Parameters

NameType
productIdsany
filterany

Returns

Promise<any[]>

Defined in

services/shipping-profile.js:73


getProfilesInCart_

getProfilesInCart_(cart): [string]

Returns a list of all the productIds in the cart.

Parameters

NameTypeDescription
cartCartthe cart to extract products from

Returns

[string]

a list of product ids

Defined in

services/shipping-profile.js:406


list

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

Parameters

NameTypeDescription
selectoranythe query object for find
configanythe config object for find

Returns

Promise<any>

the result of the find operation

Defined in

services/shipping-profile.js:64


retrieve

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

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

Parameters

NameTypeDescription
profileIdstringthe id of the profile to get.
optionsanyoptions opf the query.

Returns

Promise<Product>

the profile document.

Defined in

services/shipping-profile.js:121


retrieveDefault

retrieveDefault(): Promise<any>

Returns

Promise<any>

Defined in

services/shipping-profile.js:151


retrieveGiftCardDefault

retrieveGiftCardDefault(): any

Retrieves the default gift card profile

Returns

any

the shipping profile for gift cards

Defined in

services/shipping-profile.js:192


update

update(profileId, update): Promise<any>

Updates a profile. Metadata updates and product updates should use dedicated methods, e.g. setMetadata, addProduct, etc. The function will throw errors if metadata or product updates are attempted.

Parameters

NameTypeDescription
profileIdstringthe id of the profile. 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-profile.js:263


withTransaction

withTransaction(transactionManager): ShippingProfileService

Parameters

NameType
transactionManagerany

Returns

ShippingProfileService

Defined in

services/shipping-profile.js:41