Skip to main content
Skip to main content

DiscountService

Provides layer to manipulate discounts.

Implements

constructor

Parameters

__namedParametersObjectRequired

Properties

__configModule__Record<string, unknown>
__container__anyRequired
__moduleDeclaration__Record<string, unknown>
customerService_CustomerServiceRequired
discountConditionRepository_Repository<DiscountCondition> & objectRequired
discountConditionService_DiscountConditionServiceRequired
discountRepository_Repository<Discount>Required
discountRuleRepository_Repository<DiscountRule>Required
eventBus_EventBusServiceRequired
featureFlagRouter_FlagRouterRequired
giftCardRepository_Repository<GiftCard> & objectRequired
manager_EntityManagerRequired
newTotalsService_NewTotalsServiceRequired
productService_ProductServiceRequired
regionService_RegionServiceRequired
totalsService_TotalsServiceRequired
transactionManager_undefined | EntityManagerRequired

Accessors

activeManager_

Returns

EntityManagerEntityManagerRequired

Methods

addRegion

Adds a region to the discount regions array.

Parameters

discountIdstringRequired
id of discount
regionIdstringRequired
id of region to add

Returns

PromisePromise<Discount>Required
the result of the update operation

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

calculateDiscountForLineItem

Parameters

discountIdstringRequired
lineItemLineItemRequired
calculationContextDataCalculationContextDataRequired

Returns

PromisePromise<number>Required

canApplyForCustomer

Parameters

discountRuleIdstringRequired
customerIdundefined | stringRequired

Returns

PromisePromise<boolean>Required

create

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

PromisePromise<Discount>Required
the result of the create operation

createDynamicCode

Creates a dynamic code for a discount id.

Parameters

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

Returns

PromisePromise<Discount>Required
the newly created dynamic code

delete

Deletes a discount idempotently

Parameters

discountIdstringRequired
id of discount to delete

Returns

PromisePromise<void>Required
the result of the delete operation

deleteDynamicCode

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

PromisePromise<void>Required
the newly created dynamic code

hasCustomersGroupCondition

Parameters

discountDiscountRequired

Returns

booleanboolean

hasExpired

Parameters

discountDiscountRequired

Returns

booleanboolean

hasNotStarted

Parameters

discountDiscountRequired

Returns

booleanboolean

hasReachedLimit

Parameters

discountDiscountRequired

Returns

booleanboolean

isDisabled

Parameters

discountDiscountRequired

Returns

booleanboolean

isValidForRegion

Parameters

discountDiscountRequired
region_idstringRequired

Returns

PromisePromise<boolean>Required

list

Parameters

selectorFilterableDiscountPropsRequired
the query object for find

Default: {}

configFindConfig<Discount>Required
the config object containing query settings

Returns

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

listAndCount

Parameters

selectorFilterableDiscountPropsRequired
the query object for find

Default: {}

configFindConfig<Discount>Required
the config object containing query settings

Returns

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

listByCodes

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

PromisePromise<Discount[]>Required
the discounts

removeRegion

Removes a region from the discount regions array.

Parameters

discountIdstringRequired
id of discount
regionIdstringRequired
id of region to remove

Returns

PromisePromise<Discount>Required
the result of the update operation

retrieve

Gets a discount by id.

Parameters

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

Default: {}

Returns

PromisePromise<Discount>Required
the discount

retrieveByCode

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

PromisePromise<Discount>Required
the discount

shouldRetryTransaction_

Parameters

errRecord<string, unknown> | objectRequired

Returns

booleanboolean

update

Updates a discount.

Parameters

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

Returns

PromisePromise<Discount>Required
the result of the update operation

validateDiscountForCartOrThrow

Parameters

cartCartRequired
discountDiscount | Discount[]Required

Returns

PromisePromise<void>Required

validateDiscountForProduct

Parameters

discountRuleIdstringRequired
productIdstring

Returns

PromisePromise<boolean>Required

validateDiscountRule_

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

Type Parameters

TobjectRequired

Parameters

discountRuleTRequired
the discount rule to create

Returns

TTRequired
the result of the create operation

withTransaction

Parameters

transactionManagerEntityManager

Returns

DiscountServiceobjectRequired
Provides layer to manipulate discounts.
Was this section helpful?