Skip to main content
Skip to main content

ShippingProfileService

Provides layer to manipulate profiles.

Implements

Constructors

constructor

**new ShippingProfileService**(«destructured»)

Parameters
__namedParametersInjectedDependenciesRequired

Properties

__configModule__Record<string, unknown>
__container__anyRequired
__moduleDeclaration__Record<string, unknown>
customShippingOptionService_CustomShippingOptionServiceRequired
featureFlagRouter_FlagRouterRequired
manager_EntityManagerRequired
productRepository_Repository<Product> & { _applyCategoriesQuery: Method _applyCategoriesQuery ; _findWithRelations: Method _findWithRelations ; bulkAddToCollection: Method bulkAddToCollection ; bulkRemoveFromCollection: Method bulkRemoveFromCollection ; findOneWithRelations: Method findOneWithRelations ; findWithRelations: Method findWithRelations ; findWithRelationsAndCount: Method findWithRelationsAndCount ; getCategoryIdsFromInput: Method getCategoryIdsFromInput ; getCategoryIdsRecursively: Method getCategoryIdsRecursively ; getFreeTextSearchResultsAndCount: Method getFreeTextSearchResultsAndCount ; isProductInSalesChannels: Method isProductInSalesChannels ; queryProducts: Method queryProducts ; queryProductsWithIds: Method queryProductsWithIds }Required
productService_ProductServiceRequired
shippingOptionService_ShippingOptionServiceRequired
shippingProfileRepository_Repository<ShippingProfile> & { findByProducts: Method findByProducts }Required
transactionManager_undefined | EntityManagerRequired

Accessors

activeManager_

Protected activeManager_: [object Object]

Methods

addProduct

**addProduct**(profileId, productId): Promise&#60;[ShippingProfile](/references/services/classes/ShippingProfile)&#62;

Parameters
profileIdstringRequired
productIdstring | string[]Required
Returns

Promise<ShippingProfile>

PromisePromise<ShippingProfile>Required

Deprecated

use addProducts instead


addProducts

**addProducts**(profileId, productId): Promise&#60;[ShippingProfile](/references/services/classes/ShippingProfile)&#62;

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

Promise<ShippingProfile>

PromisePromise<ShippingProfile>Required
the result of update

addShippingOption

**addShippingOption**(profileId, optionId): Promise&#60;[ShippingProfile](/references/services/classes/ShippingProfile)&#62;

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

Promise<ShippingProfile>

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

atomicPhase_

Protected **atomicPhase_**<TypeParameter TResult, TypeParameter TError>(work, isolationOrErrorHandler?, maybeErrorHandlerOrDontFail?): Promise&#60;TResult&#62;

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

Promise<TResult>

PromisePromise<TResult>Required
the result of the transactional work

create

**create**(profile): Promise&#60;[ShippingProfile](/references/services/classes/ShippingProfile)&#62;

Creates a new shipping profile.

Parameters
profileCreateShippingProfileRequired
the shipping profile to create from
Returns

Promise<ShippingProfile>

PromisePromise<ShippingProfile>Required
the result of the create operation

createDefault

**createDefault**(): Promise&#60;[ShippingProfile](/references/services/classes/ShippingProfile)&#62;

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

Returns

Promise<ShippingProfile>

PromisePromise<ShippingProfile>Required
the shipping profile

createGiftCardDefault

**createGiftCardDefault**(): Promise&#60;[ShippingProfile](/references/services/classes/ShippingProfile)&#62;

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

Returns

Promise<ShippingProfile>

PromisePromise<ShippingProfile>Required
the shipping profile

delete

**delete**(profileId): Promise&#60;void&#62;

Deletes a profile with a given profile id.

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

Promise<void>

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

fetchCartOptions

**fetchCartOptions**(cart): Promise&#60;[ShippingOption](/references/services/classes/ShippingOption)[]&#62;

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

Promise<ShippingOption[]>

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

getMapProfileIdsByProductIds

**getMapProfileIdsByProductIds**(productIds): Promise&#60;Map&#60;string, string&#62;&#62;

Parameters
productIdsstring[]Required
Returns

Promise<Map<string, string>>

PromisePromise<Map<string, string>>Required

getProfilesInCart

Protected **getProfilesInCart**(cart): Promise&#60;string[]&#62;

Returns a list of all the productIds in the cart.

Parameters
cartCartRequired
the cart to extract products from
Returns

Promise<string[]>

PromisePromise<string[]>Required
a list of product ids

list

**list**(selector?, config?): Promise&#60;[ShippingProfile](/references/services/classes/ShippingProfile)[]&#62;

Parameters
selectorSelector<ShippingProfile>Required
the query object for find

Default: {}

the config object for find
Returns

Promise<ShippingProfile[]>

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

removeProducts

**removeProducts**(profileId, productId): Promise&#60;void \| [ShippingProfile](/references/services/classes/ShippingProfile)&#62;

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

Promise<void | ShippingProfile>

PromisePromise<void | ShippingProfile>Required
the result of update

retrieve

**retrieve**(profileId, options?): Promise&#60;[ShippingProfile](/references/services/classes/ShippingProfile)&#62;

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

Promise<ShippingProfile>

PromisePromise<ShippingProfile>Required
the profile document.

retrieveDefault

**retrieveDefault**(): Promise&#60;null \| [ShippingProfile](/references/services/classes/ShippingProfile)&#62;

Returns

Promise<null | ShippingProfile>

PromisePromise<null | ShippingProfile>Required

retrieveForProducts

**retrieveForProducts**(productIds): Promise&#60;&#123; [product_id: string]: [ShippingProfile](/references/services/classes/ShippingProfile)[]; &#125;&#62;

Parameters
productIdsstring | string[]Required
Returns

Promise<{ [product_id: string]: ShippingProfile[]; }>

PromisePromise<{ [product_id: string]: ShippingProfile[]; }>Required

retrieveGiftCardDefault

**retrieveGiftCardDefault**(): Promise&#60;null \| [ShippingProfile](/references/services/classes/ShippingProfile)&#62;

Retrieves the default gift card profile

Returns

Promise<null | ShippingProfile>

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

shouldRetryTransaction_

Protected **shouldRetryTransaction_**(err): boolean

Parameters
errRecord<string, unknown> | { code: string }Required
Returns

boolean

booleanboolean

update

**update**(profileId, update): Promise&#60;[ShippingProfile](/references/services/classes/ShippingProfile)&#62;

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

Promise<ShippingProfile>

PromisePromise<ShippingProfile>Required
resolves to the update result.

withTransaction

**withTransaction**(transactionManager?): [ShippingProfileService](/references/services/classes/ShippingProfileService)

Parameters
transactionManagerEntityManager
Returns

ShippingProfileService

ShippingProfileServiceShippingProfileServiceRequired
Was this section helpful?