Skip to main content
Skip to main content

ShippingProfileService

internal.internal.ShippingProfileService

Provides layer to manipulate profiles.

Implements

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 get activeManager_(): EntityManager

Returns

EntityManager

EntityManagerEntityManagerRequired

Inherited from

TransactionBaseService.activeManager_

Methods

addProduct

addProduct(profileId, productId): Promise<ShippingProfile>

Parameters

profileIdstringRequired
productIdstring | string[]Required

Returns

Promise<ShippingProfile>

PromisePromise<ShippingProfile>Required

Deprecated

use addProducts instead


addProducts

addProducts(profileId, productId): Promise<ShippingProfile>

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<ShippingProfile>

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_<TResult, TError>(work, isolationOrErrorHandler?, maybeErrorHandlerOrDontFail?): Promise<TResult>

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.

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

Inherited from

TransactionBaseService.atomicPhase_


create

create(profile): Promise<ShippingProfile>

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<ShippingProfile>

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

Returns

Promise<ShippingProfile>

PromisePromise<ShippingProfile>Required
the shipping profile

createGiftCardDefault

createGiftCardDefault(): Promise<ShippingProfile>

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<void>

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<ShippingOption[]>

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<Map<string, string>>

Parameters

productIdsstring[]Required

Returns

Promise<Map<string, string>>

PromisePromise<Map<string, string>>Required

getProfilesInCart

Protected getProfilesInCart(cart): Promise<string[]>

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<ShippingProfile[]>

Parameters

the query object for find
the config object for find

Returns

Promise<ShippingProfile[]>

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

removeProducts

removeProducts(profileId, productId): Promise<void | ShippingProfile>

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<ShippingProfile>

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.
options opf the query.

Returns

Promise<ShippingProfile>

PromisePromise<ShippingProfile>Required
the profile document.

retrieveDefault

retrieveDefault(): Promise<null | ShippingProfile>

Returns

Promise<null | ShippingProfile>

PromisePromise<null | ShippingProfile>Required

retrieveForProducts

retrieveForProducts(productIds): Promise<{ [product_id: string]: ShippingProfile[]; }>

Parameters

productIdsstring | string[]Required

Returns

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

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

retrieveGiftCardDefault

retrieveGiftCardDefault(): Promise<null | ShippingProfile>

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

Inherited from

TransactionBaseService.shouldRetryTransaction_


update

update(profileId, update): Promise<ShippingProfile>

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

Parameters

transactionManagerEntityManager

Returns

ShippingProfileService

ShippingProfileServiceShippingProfileServiceRequired

Inherited from

TransactionBaseService.withTransaction

Was this section helpful?