Skip to main content
Skip to main content

DiscountService

Provides layer to manipulate discounts.

Implements

constructor

Parameters

__namedParametersobjectRequired
__namedParameters.discountRepositoryanyRequired
__namedParameters.discountRuleRepositoryanyRequired
__namedParameters.giftCardRepositoryanyRequired
__namedParameters.discountConditionRepositoryanyRequired
__namedParameters.discountConditionServiceanyRequired
__namedParameters.totalsServiceanyRequired
__namedParameters.newTotalsServiceanyRequired
__namedParameters.productServiceanyRequired
__namedParameters.regionServiceanyRequired
__namedParameters.customerServiceanyRequired
__namedParameters.eventBusServiceanyRequired
__namedParameters.featureFlagRouteranyRequired

Properties

manager_EntityManagerRequired
transactionManager_undefined | EntityManagerRequired
__container__anyRequired
EventsobjectRequired
Events.CREATEDstringRequired

Default: "discount.created"

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

Accessors

activeManager_

Returns

EntityManagerEntityManagerRequired

Methods

withTransaction

Parameters

transactionManagerEntityManager

Returns

thisthisRequired

shouldRetryTransaction_

Parameters

errRecord<string, unknown> | objectRequired

Returns

booleanbooleanRequired

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

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

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

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

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

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

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

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

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

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

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

delete

Deletes a discount idempotently

Parameters

discountIdstringRequired
id of discount to delete

Returns

PromisePromise<void>Required
the result of the delete operation

validateDiscountForProduct

Parameters

discountRuleIdstringRequired
productIdstring

Returns

PromisePromise<boolean>Required

calculateDiscountForLineItem

Parameters

discountIdstringRequired
lineItemLineItemRequired
calculationContextDataCalculationContextDataRequired

Returns

PromisePromise<number>Required

validateDiscountForCartOrThrow

Parameters

cartCartRequired
discountDiscount | Discount[]Required

Returns

PromisePromise<void>Required

hasCustomersGroupCondition

Parameters

discountDiscountRequired

Returns

booleanbooleanRequired

hasReachedLimit

Parameters

discountDiscountRequired

Returns

booleanbooleanRequired

hasNotStarted

Parameters

discountDiscountRequired

Returns

booleanbooleanRequired

hasExpired

Parameters

discountDiscountRequired

Returns

booleanbooleanRequired

isDisabled

Parameters

discountDiscountRequired

Returns

booleanbooleanRequired

isValidForRegion

Parameters

discountDiscountRequired
region_idstringRequired

Returns

PromisePromise<boolean>Required

canApplyForCustomer

Parameters

discountRuleIdstringRequired
customerIdundefined | stringRequired

Returns

PromisePromise<boolean>Required
Was this section helpful?