Skip to main content
Skip to main content
You're viewing the documentation for v1, which isn't the latest Medusa version.Latest documentation

ShippingProfileService

Provides layer to manipulate profiles.

Implements​

constructor​

Parameters​

__namedParametersInjectedDependenciesRequired

Properties​

manager_EntityManagerRequired
transactionManager_undefined | EntityManagerRequired
__container__anyRequired
productService_ProductServiceRequired
shippingOptionService_ShippingOptionServiceRequired
customShippingOptionService_CustomShippingOptionServiceRequired
shippingProfileRepository_Repository<ShippingProfile> & objectRequired
productRepository_Repository<Product> & objectRequired
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

list​

Parameters​

selectorSelector<ShippingProfile>Required
the query object for find

Default: {}

the config object for find

Returns​

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

getMapProfileIdsByProductIds​

Parameters​

productIdsstring[]Required

Returns​

PromisePromise<Map<string, string>>Required

retrieve​

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

Parameters​

profileIdstringRequired
the id of the profile to get.
optionsFindConfig<ShippingProfile>Required
options opf the query.

Default: {}

Returns​

PromisePromise<ShippingProfile>Required
the profile document.

retrieveForProducts​

Parameters​

productIdsstring | string[]Required

Returns​

PromisePromise<object>Required

retrieveDefault​

Returns​

PromisePromise<null | ShippingProfile>Required

createDefault​

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

Returns​

PromisePromise<ShippingProfile>Required
the shipping profile

retrieveGiftCardDefault​

Retrieves the default gift card profile

Returns​

PromisePromise<null | ShippingProfile>Required
the shipping profile for gift cards

createGiftCardDefault​

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

Returns​

PromisePromise<ShippingProfile>Required
the shipping profile

create​

Creates a new shipping profile.

Parameters​

profileCreateShippingProfileRequired
the shipping profile to create from

Returns​

PromisePromise<ShippingProfile>Required
the result of the create operation

update​

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​

profileIdstringRequired
the id of the profile. Must be a string that can be casted to an ObjectId
updateUpdateShippingProfileRequired
an object with the update values.

Returns​

PromisePromise<ShippingProfile>Required
resolves to the update result.

delete​

Deletes a profile with a given profile id.

Parameters​

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

Returns​

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

addProduct​

Parameters​

profileIdstringRequired
productIdstring | string[]Required

Returns​

PromisePromise<ShippingProfile>Required

Deprecated​

use addProducts instead

addProducts​

Adds a product or an array of products to the profile.

Parameters​

profileIdstringRequired
the profile to add the products to.
productIdstring | string[]Required
the ID of the product or multiple products to add.

Returns​

PromisePromise<ShippingProfile>Required
the result of update

removeProducts​

Removes a product or an array of products from the profile.

Parameters​

profileIdnull | stringRequired
the profile to add the products to.
productIdstring | string[]Required
the ID of the product or multiple products to add.

Returns​

PromisePromise<void | ShippingProfile>Required
the result of update

addShippingOption​

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

Parameters​

profileIdstringRequired
the profile to apply the shipping option to
optionIdstring | string[]Required
the ID of the option or multiple options to add to the profile

Returns​

PromisePromise<ShippingProfile>Required
the result of the model update operation

fetchCartOptions​

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

Parameters​

cartanyRequired
the cart object to find shipping options for

Returns​

PromisePromise<ShippingOption[]>Required
a list of the available shipping options

getProfilesInCart​

Returns a list of all the productIds in the cart.

Parameters​

cartCartRequired
the cart to extract products from

Returns​

PromisePromise<string[]>Required
a list of product ids
Was this section helpful?