Skip to main content
Skip to main content

LineItemService

Constructors

constructor

**new LineItemService**(«destructured»)

Parameters

__namedParametersInjectedDependenciesRequired

Properties

__configModule__Record<string, unknown>
__container__anyRequired
__moduleDeclaration__Record<string, unknown>
cartRepository_Repository<Cart> & { findOneWithRelations: Method findOneWithRelations ; findWithRelations: Method findWithRelations }Required
featureFlagRouter_FlagRouterRequired
itemTaxLineRepo_Repository<LineItemTaxLine> & { deleteForCart: Method deleteForCart ; upsertLines: Method upsertLines }Required
lineItemAdjustmentService_LineItemAdjustmentServiceRequired
lineItemRepository_Repository<LineItem> & { findByReturn: Method findByReturn }Required
manager_EntityManagerRequired
pricingService_PricingServiceRequired
productService_ProductServiceRequired
productVariantService_ProductVariantServiceRequired
regionService_RegionServiceRequired
taxProviderService_TaxProviderServiceRequired
transactionManager_undefined | EntityManagerRequired

Accessors

activeManager_

Protected get**activeManager_**(): EntityManager

Returns

EntityManager

EntityManagerEntityManagerRequired

Methods

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.

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

cloneTo

**cloneTo**(ids, data?, options?): Promise&#60;[LineItem](/references/services/classes/LineItem)[]&#62;

Parameters

idsstring | string[]Required
dataDeepPartial<LineItem>Required

Default: {}

optionsobjectRequired
options.setOriginalLineItemIdboolean

Returns

Promise<LineItem[]>

PromisePromise<LineItem[]>Required

create

**create**<TypeParameter T, TypeParameter TResult>(data): Promise&#60;TResult&#62;

Create a line item

TobjectRequired
TResultobjectRequired

Parameters

dataTRequired
the line item object to create

Returns

Promise<TResult>

PromisePromise<TResult>Required
the created line item

createReturnLines

**createReturnLines**(returnId, cartId): Promise&#60;[LineItem](/references/services/classes/LineItem)[]&#62;

Creates return line items for a given cart based on the return items in a return.

Parameters

returnIdstringRequired
the id to generate return items from.
cartIdstringRequired
the cart to assign the return line items to.

Returns

Promise<LineItem[]>

PromisePromise<LineItem[]>Required
the created line items

createTaxLine

**createTaxLine**(args): [LineItemTaxLine](/references/services/classes/LineItemTaxLine)

Create a line item tax line.

Parameters

argsDeepPartial<LineItemTaxLine>Required
tax line partial passed to the repo create method

Returns

LineItemTaxLine

LineItemTaxLineLineItemTaxLineRequired
a new line item tax line

delete

**delete**(id): Promise&#60;undefined \| null \| [LineItem](/references/services/classes/LineItem)&#62;

Deletes a line item.

Parameters

idstringRequired
the id of the line item to delete

Returns

Promise<undefined | null | LineItem>

PromisePromise<undefined | null | LineItem>Required
the result of the delete operation

deleteWithTaxLines

**deleteWithTaxLines**(id): Promise&#60;undefined \| null \| [LineItem](/references/services/classes/LineItem)&#62;

Parameters

idstringRequired
the id of the line item to delete

Returns

Promise<undefined | null | LineItem>

PromisePromise<undefined | null | LineItem>Required
the result of the delete operation

Deprecated

no the cascade on the entity takes care of it Deletes a line item with the tax lines.


generate

**generate**<TypeParameter T, TypeParameter TResult>(variantIdOrData, regionIdOrContext, quantity?, context?): Promise&#60;TResult&#62;

Generate a single or multiple line item without persisting the data into the db

TobjectRequired
TResultobjectRequired

Parameters

variantIdOrDataTRequired
regionIdOrContextT extends string ? string : GenerateLineItemContextRequired
quantitynumber

Default: {}

Returns

Promise<TResult>

PromisePromise<TResult>Required

generateLineItem

Protected **generateLineItem**(variant, quantity, context): Promise&#60;[LineItem](/references/services/classes/LineItem)&#62;

Parameters

variantobjectRequired
variant.idstringRequired
variant.productobjectRequired
variant.product.discountablebooleanRequired
variant.product.is_giftcardbooleanRequired
variant.product.thumbnailnull | stringRequired
variant.product.titlestringRequired
variant.product_idstringRequired
variant.titlestringRequired
quantitynumberRequired
contextGenerateLineItemContext & { variantPricing: [ProductVariantPricing](/references/services/types/ProductVariantPricing) }Required

Returns

Promise<LineItem>

PromisePromise<LineItem>Required

list

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

Parameters

selectorSelector<LineItem>Required
configFindConfig<LineItem>Required

Returns

Promise<LineItem[]>

PromisePromise<LineItem[]>Required

retrieve

**retrieve**(id, config?): Promise&#60;[LineItem](/references/services/classes/LineItem)&#62;

Retrieves a line item by its id.

Parameters

idstringRequired
the id of the line item to retrieve
configobjectRequired
the config to be used at query building

Default: {}

Returns

Promise<LineItem>

PromisePromise<LineItem>Required
the line item

shouldRetryTransaction_

Protected **shouldRetryTransaction_**(err): boolean

Parameters

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

Returns

boolean

booleanboolean

update

**update**(idOrSelector, data): Promise&#60;[LineItem](/references/services/classes/LineItem)[]&#62;

Updates a line item

Parameters

idOrSelectorstring | Selector<LineItem>Required
the id or selector of the line item(s) to update
dataPartial<LineItem>Required
the properties to update the line item(s)

Returns

Promise<LineItem[]>

PromisePromise<LineItem[]>Required
the updated line item(s)

validateGenerateArguments

Protected **validateGenerateArguments**<TypeParameter T, TypeParameter TResult>(variantIdOrData, regionIdOrContext, quantity?): void

TobjectRequired
TResultobjectRequired

Parameters

variantIdOrDatastring | TRequired
regionIdOrContextT extends string ? string : GenerateLineItemContextRequired
quantitynumber

Returns

void

voidvoid

withTransaction

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

Parameters

transactionManagerEntityManager

Returns

LineItemService

LineItemServiceLineItemServiceRequired
Was this section helpful?