DiscountService
internal.internal.DiscountService
Provides layer to manipulate discounts.
Implements
Properties
__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
EntityManagerRequiredInherited from
TransactionBaseService.activeManager_
Methods
addRegion
addRegion(discountId
, regionId
): Promise
<Discount
>
Adds a region to the discount regions array.
Parameters
discountId
stringRequiredregionId
stringRequiredReturns
Promise
<Discount
>
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.
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>RequiredInherited from
TransactionBaseService.atomicPhase_
calculateDiscountForLineItem
calculateDiscountForLineItem(discountId
, lineItem
, calculationContextData
): Promise
<number
>
Parameters
discountId
stringRequiredReturns
Promise
<number
>
Promise
Promise<number>Required
Promise
Promise<number>RequiredcanApplyForCustomer
canApplyForCustomer(discountRuleId
, customerId
): Promise
<boolean
>
Parameters
discountRuleId
stringRequiredcustomerId
undefined | stringRequiredReturns
Promise
<boolean
>
Promise
Promise<boolean>Required
Promise
Promise<boolean>Requiredcreate
create(discount
): Promise
<Discount
>
Creates a discount with provided data given that the data is validated. Normalizes discount code to uppercase.
Parameters
Returns
Promise
<Discount
>
the result of the create operation
createDynamicCode
createDynamicCode(discountId
, data
): Promise
<Discount
>
Creates a dynamic code for a discount id.
Parameters
discountId
stringRequiredReturns
Promise
<Discount
>
the newly created dynamic code
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>Required
Promise
Promise<boolean>Requiredlist
list(selector?
, config?
): Promise
<Discount
[]>
Parameters
selector
FilterableDiscountPropsconfig
FindConfig<Discount>Returns
Promise
<Discount
[]>
the result of the find operation
listAndCount
listAndCount(selector?
, config?
): Promise
<[Discount
[], number
]>
Parameters
selector
FilterableDiscountPropsconfig
FindConfig<Discount>Returns
Promise
<[Discount
[], number
]>
the result of the find operation
listByCodes
listByCodes(discountCodes
, config?
): Promise
<Discount
[]>
List all the discounts corresponding to the given codes
Parameters
discountCodes
string[]Requiredconfig
FindConfig<Discount>Returns
Promise
<Discount
[]>
the discounts
removeRegion
removeRegion(discountId
, regionId
): Promise
<Discount
>
Removes a region from the discount regions array.
Parameters
discountId
stringRequiredregionId
stringRequiredReturns
Promise
<Discount
>
the result of the update operation
retrieve
retrieve(discountId
, config?
): Promise
<Discount
>
Gets a discount by id.
Parameters
discountId
stringRequiredconfig
FindConfig<Discount>Returns
Promise
<Discount
>
the discount
retrieveByCode
retrieveByCode(discountCode
, config?
): Promise
<Discount
>
Gets the discount by discount code.
Parameters
discountCode
stringRequiredconfig
FindConfig<Discount>Returns
Promise
<Discount
>
the discount
shouldRetryTransaction_
Protected
shouldRetryTransaction_(err
): boolean
Parameters
err
Record<string, unknown> | { code: string }RequiredReturns
boolean
boolean
booleanInherited from
TransactionBaseService.shouldRetryTransaction_
update
update(discountId
, update
): Promise
<Discount
>
Updates a discount.
Parameters
discountId
stringRequiredReturns
Promise
<Discount
>
the result of the update operation
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>Required
Promise
Promise<boolean>RequiredvalidateDiscountRule_
validateDiscountRule_<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
Parameters
transactionManager
EntityManager