Skip to main content
Skip to main content

DiscountService

Provides layer to manipulate discounts.

Implements

Constructors

constructor

new DiscountService(«destructured»)

Parameters

__namedParametersObjectRequired

Properties

__configModule__Record<string, unknown>
__container__anyRequired
__moduleDeclaration__Record<string, unknown>
customerService_CustomerServiceRequired
discountConditionRepository_Repository<DiscountCondition> & { addConditionResources: Method addConditionResources ; canApplyForCustomer: Method canApplyForCustomer ; findOneWithDiscount: Method findOneWithDiscount ; getJoinTableResourceIdentifiers: Method getJoinTableResourceIdentifiers ; isValidForProduct: Method isValidForProduct ; queryConditionTable: Method queryConditionTable ; removeConditionResources: Method removeConditionResources }Required
discountConditionService_DiscountConditionServiceRequired
discountRepository_Repository<Discount>Required
discountRuleRepository_Repository<DiscountRule>Required
eventBus_EventBusServiceRequired
featureFlagRouter_FlagRouterRequired
giftCardRepository_Repository<GiftCard> & { listGiftCardsAndCount: Method listGiftCardsAndCount }Required
manager_EntityManagerRequired
newTotalsService_NewTotalsServiceRequired
productService_ProductServiceRequired
regionService_RegionServiceRequired
totalsService_TotalsServiceRequired
transactionManager_undefined | EntityManagerRequired

Accessors

activeManager_

Protected get activeManager_(): EntityManager

Returns

EntityManager

EntityManagerEntityManagerRequired

Methods

addRegion

addRegion(discountId, regionId): Promise<Discount>

Adds a region to the discount regions array.

Parameters

discountIdstringRequired
id of discount
regionIdstringRequired
id of region to add

Returns

Promise<Discount>

PromisePromise<Discount>Required
the result of the 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

calculateDiscountForLineItem

calculateDiscountForLineItem(discountId, lineItem, calculationContextData): Promise<number>

Parameters

discountIdstringRequired
lineItemLineItemRequired
Line Items are created when a product is added to a Cart. When Line Items are purchased they will get copied to the resulting order, swap, or claim, and can eventually be referenced in Fulfillments and Returns. Line items may also be used for order edits.
calculationContextDataCalculationContextDataRequired

Returns

Promise<number>

PromisePromise<number>Required

canApplyForCustomer

canApplyForCustomer(discountRuleId, customerId): Promise<boolean>

Parameters

discountRuleIdstringRequired
customerIdundefined | stringRequired

Returns

Promise<boolean>

PromisePromise<boolean>Required

create

create(discount): Promise<Discount>

Creates a discount with provided data given that the data is validated. Normalizes discount code to uppercase.

Parameters

discountCreateDiscountInputRequired
the discount data to create

Returns

Promise<Discount>

PromisePromise<Discount>Required
the result of the create operation

createDynamicCode

createDynamicCode(discountId, data): Promise<Discount>

Creates a dynamic code for a discount id.

Parameters

discountIdstringRequired
the id of the discount to create a code for
the object containing a code to identify the discount by

Returns

Promise<Discount>

PromisePromise<Discount>Required
the newly created dynamic code

delete

delete(discountId): Promise<void>

Deletes a discount idempotently

Parameters

discountIdstringRequired
id of discount to delete

Returns

Promise<void>

PromisePromise<void>Required
the result of the delete operation

deleteDynamicCode

deleteDynamicCode(discountId, code): Promise<void>

Deletes a dynamic code for a discount id.

Parameters

discountIdstringRequired
the id of the discount to create a code for
codestringRequired
the code to identify the discount by

Returns

Promise<void>

PromisePromise<void>Required
the newly created dynamic code

hasCustomersGroupCondition

hasCustomersGroupCondition(discount): boolean

Parameters

discountDiscountRequired
A discount can be applied to a cart for promotional purposes.

Returns

boolean

booleanboolean

hasExpired

hasExpired(discount): boolean

Parameters

discountDiscountRequired
A discount can be applied to a cart for promotional purposes.

Returns

boolean

booleanboolean

hasNotStarted

hasNotStarted(discount): boolean

Parameters

discountDiscountRequired
A discount can be applied to a cart for promotional purposes.

Returns

boolean

booleanboolean

hasReachedLimit

hasReachedLimit(discount): boolean

Parameters

discountDiscountRequired
A discount can be applied to a cart for promotional purposes.

Returns

boolean

booleanboolean

isDisabled

isDisabled(discount): boolean

Parameters

discountDiscountRequired
A discount can be applied to a cart for promotional purposes.

Returns

boolean

booleanboolean

isValidForRegion

isValidForRegion(discount, region_id): Promise<boolean>

Parameters

discountDiscountRequired
A discount can be applied to a cart for promotional purposes.
region_idstringRequired

Returns

Promise<boolean>

PromisePromise<boolean>Required

list

list(selector?, config?): Promise<Discount[]>

Parameters

selectorFilterableDiscountPropsRequired
the query object for find

Default: {}

configFindConfig<Discount>Required
the config object containing query settings

Returns

Promise<Discount[]>

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

listAndCount

listAndCount(selector?, config?): Promise<[Discount[], number]>

Parameters

selectorFilterableDiscountPropsRequired
the query object for find

Default: {}

configFindConfig<Discount>Required
the config object containing query settings

Returns

Promise<[Discount[], number]>

PromisePromise<[Discount[], number]>Required
the result of the find operation

listByCodes

listByCodes(discountCodes, config?): Promise<Discount[]>

List all the discounts corresponding to the given codes

Parameters

discountCodesstring[]Required
discount codes of discounts to retrieve
configFindConfig<Discount>Required
the config object containing query settings

Default: {}

Returns

Promise<Discount[]>

PromisePromise<Discount[]>Required
the discounts

removeRegion

removeRegion(discountId, regionId): Promise<Discount>

Removes a region from the discount regions array.

Parameters

discountIdstringRequired
id of discount
regionIdstringRequired
id of region to remove

Returns

Promise<Discount>

PromisePromise<Discount>Required
the result of the update operation

retrieve

retrieve(discountId, config?): Promise<Discount>

Gets a discount by id.

Parameters

discountIdstringRequired
id of discount to retrieve
configFindConfig<Discount>Required
the config object containing query settings

Default: {}

Returns

Promise<Discount>

PromisePromise<Discount>Required
the discount

retrieveByCode

retrieveByCode(discountCode, config?): Promise<Discount>

Gets the discount by discount code.

Parameters

discountCodestringRequired
discount code of discount to retrieve
configFindConfig<Discount>Required
the config object containing query settings

Default: {}

Returns

Promise<Discount>

PromisePromise<Discount>Required
the discount

shouldRetryTransaction_

Protected shouldRetryTransaction_(err): boolean

Parameters

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

Returns

boolean

booleanboolean

update

update(discountId, update): Promise<Discount>

Updates a discount.

Parameters

discountIdstringRequired
discount id of discount to update
updateUpdateDiscountInputRequired
the data to update the discount with

Returns

Promise<Discount>

PromisePromise<Discount>Required
the result of the update operation

validateDiscountForCartOrThrow

validateDiscountForCartOrThrow(cart, discount): Promise<void>

Parameters

cartCartRequired
A cart represents a virtual shopping bag. It can be used to complete an order, a swap, or a claim.
discountDiscount | Discount[]Required

Returns

Promise<void>

PromisePromise<void>Required

validateDiscountForProduct

validateDiscountForProduct(discountRuleId, productId?): Promise<boolean>

Parameters

discountRuleIdstringRequired
productIdstring

Returns

Promise<boolean>

PromisePromise<boolean>Required

validateDiscountRule_

validateDiscountRule_<T>(discountRule): T

Creates a discount rule with provided data given that the data is validated.

TobjectRequired

Parameters

discountRuleTRequired
the discount rule to create

Returns

T


withTransaction

withTransaction(transactionManager?): DiscountService

Parameters

transactionManagerEntityManager

Returns

DiscountService

DiscountServiceDiscountServiceRequired
Was this section helpful?