DiscountService
Provides layer to manipulate discounts.
Implements
Constructors
constructor
**new DiscountService**(«destructured»)
Parameters
__namedParameters
ObjectRequiredProperties
__configModule__
Record<string, unknown>__container__
anyRequired__moduleDeclaration__
Record<string, unknown>discountConditionRepository_
Repository<DiscountCondition> & { addConditionResources: Method addConditionResources ; canApplyForCustomer: Method canApplyForCustomer ; findOneWithDiscount: Method findOneWithDiscount ; getJoinTableResourceIdentifiers: Method getJoinTableResourceIdentifiers ; isValidForProduct: Method isValidForProduct ; queryConditionTable: Method queryConditionTable ; removeConditionResources: Method removeConditionResources }RequiredgiftCardRepository_
Repository<GiftCard> & { listGiftCardsAndCount: Method listGiftCardsAndCount }Requiredmanager_
EntityManagerRequiredtransactionManager_
undefined | EntityManagerRequiredAccessors
activeManager_
Protected get**activeManager_**(): EntityManager
Returns
EntityManager
EntityManager
EntityManagerRequiredMethods
addRegion
**addRegion**(discountId, regionId): Promise<[Discount](/references/services/classes/Discount)>
Adds a region to the discount regions array.
Parameters
discountId
stringRequiredregionId
stringRequiredReturns
Promise<Discount>
atomicPhase_
Protected **atomicPhase_**<TypeParameter TResult, TypeParameter 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.
TResult
objectRequiredTError
objectRequiredParameters
work
(transactionManager: EntityManager) => Promise<TResult>RequiredisolationOrErrorHandler
IsolationLevel | (error: TError) => Promise<void | TResult>maybeErrorHandlerOrDontFail
(error: TError) => Promise<void | TResult>Returns
Promise<TResult>
Promise
Promise<TResult>RequiredcalculateDiscountForLineItem
**calculateDiscountForLineItem**(discountId, lineItem, calculationContextData): Promise<number>
Parameters
discountId
stringRequiredReturns
Promise<number>
Promise
Promise<number>RequiredcanApplyForCustomer
**canApplyForCustomer**(discountRuleId, customerId): Promise<boolean>
Parameters
discountRuleId
stringRequiredcustomerId
undefined | stringRequiredReturns
Promise<boolean>
Promise
Promise<boolean>Requiredcreate
**create**(discount): Promise<[Discount](/references/services/classes/Discount)>
Creates a discount with provided data given that the data is validated. Normalizes discount code to uppercase.
Parameters
Returns
Promise<Discount>
createDynamicCode
**createDynamicCode**(discountId, data): Promise<[Discount](/references/services/classes/Discount)>
Creates a dynamic code for a discount id.
Parameters
discountId
stringRequiredReturns
Promise<Discount>
delete
**delete**(discountId): Promise<void>
Deletes a discount idempotently
Parameters
discountId
stringRequiredReturns
Promise<void>
Promise
Promise<void>RequireddeleteDynamicCode
**deleteDynamicCode**(discountId, code): Promise<void>
Deletes a dynamic code for a discount id.
Parameters
discountId
stringRequiredcode
stringRequiredReturns
Promise<void>
Promise
Promise<void>RequiredhasCustomersGroupCondition
**hasCustomersGroupCondition**(discount): boolean
Parameters
Returns
boolean
boolean
booleanhasExpired
**hasExpired**(discount): boolean
Parameters
Returns
boolean
boolean
booleanhasNotStarted
**hasNotStarted**(discount): boolean
Parameters
Returns
boolean
boolean
booleanhasReachedLimit
**hasReachedLimit**(discount): boolean
Parameters
Returns
boolean
boolean
booleanisDisabled
**isDisabled**(discount): boolean
Parameters
Returns
boolean
boolean
booleanisValidForRegion
**isValidForRegion**(discount, region_id): Promise<boolean>
Parameters
region_id
stringRequiredReturns
Promise<boolean>
Promise
Promise<boolean>Requiredlist
**list**(selector?, config?): Promise<[Discount](/references/services/classes/Discount)[]>
Parameters
Default: {}
Returns
Promise<Discount[]>
listAndCount
**listAndCount**(selector?, config?): Promise<[[Discount](/references/services/classes/Discount)[], number]>
Parameters
Default: {}
Returns
Promise<[Discount[], number]>
listByCodes
**listByCodes**(discountCodes, config?): Promise<[Discount](/references/services/classes/Discount)[]>
List all the discounts corresponding to the given codes
Parameters
discountCodes
string[]RequiredDefault: {}
Returns
Promise<Discount[]>
removeRegion
**removeRegion**(discountId, regionId): Promise<[Discount](/references/services/classes/Discount)>
Removes a region from the discount regions array.
Parameters
discountId
stringRequiredregionId
stringRequiredReturns
Promise<Discount>
retrieve
**retrieve**(discountId, config?): Promise<[Discount](/references/services/classes/Discount)>
Gets a discount by id.
Parameters
discountId
stringRequiredDefault: {}
Returns
Promise<Discount>
retrieveByCode
**retrieveByCode**(discountCode, config?): Promise<[Discount](/references/services/classes/Discount)>
Gets the discount by discount code.
Parameters
discountCode
stringRequiredDefault: {}
Returns
Promise<Discount>
shouldRetryTransaction_
Protected **shouldRetryTransaction_**(err): boolean
Parameters
err
Record<string, unknown> | { code: string }RequiredReturns
boolean
boolean
booleanupdate
**update**(discountId, update): Promise<[Discount](/references/services/classes/Discount)>
Updates a discount.
Parameters
discountId
stringRequiredReturns
Promise<Discount>
validateDiscountForCartOrThrow
**validateDiscountForCartOrThrow**(cart, discount): Promise<void>
Parameters
Returns
Promise<void>
Promise
Promise<void>RequiredvalidateDiscountForProduct
**validateDiscountForProduct**(discountRuleId, productId?): Promise<boolean>
Parameters
discountRuleId
stringRequiredproductId
stringReturns
Promise<boolean>
Promise
Promise<boolean>RequiredvalidateDiscountRule_
**validateDiscountRule_**<TypeParameter T>(discountRule): T
Creates a discount rule with provided data given that the data is validated.
T
objectRequiredParameters
discountRule
TRequiredReturns
T
withTransaction
**withTransaction**(transactionManager?): [DiscountService](/references/services/classes/DiscountService)
Parameters
transactionManager
EntityManager