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_
Returns
EntityManager
EntityManagerRequiredMethods
addRegion
Adds a region to the discount regions array.
Parameters
discountId
stringRequiredid of discount
regionId
stringRequiredid of region to add
Returns
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.
Parameters
work
(transactionManager: EntityManager) => Promise<TResult>Requiredthe transactional work to be done
isolationOrErrorHandler
IsolationLevel | (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
Promise<TResult>Requiredthe result of the transactional work
calculateDiscountForLineItem
Parameters
discountId
stringRequiredLine 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.
Returns
Promise
Promise<number>RequiredcanApplyForCustomer
Parameters
discountRuleId
stringRequiredcustomerId
undefined | stringRequiredReturns
Promise
Promise<boolean>Requiredcreate
Creates a discount with provided data given that the data is validated. Normalizes discount code to uppercase.
Parameters
the discount data to create
Returns
the result of the create operation
createDynamicCode
Creates a dynamic code for a discount id.
Parameters
discountId
stringRequiredthe id of the discount to create a code for
the object containing a code to identify the discount by
Returns
the newly created dynamic code
delete
Deletes a discount idempotently
Parameters
discountId
stringRequiredid of discount to delete
Returns
Promise
Promise<void>Requiredthe result of the delete operation
deleteDynamicCode
Deletes a dynamic code for a discount id.
Parameters
discountId
stringRequiredthe id of the discount to create a code for
code
stringRequiredthe code to identify the discount by
Returns
Promise
Promise<void>Requiredthe newly created dynamic code
hasCustomersGroupCondition
Parameters
A discount can be applied to a cart for promotional purposes.
Returns
boolean
booleanhasExpired
Parameters
A discount can be applied to a cart for promotional purposes.
Returns
boolean
booleanhasNotStarted
Parameters
A discount can be applied to a cart for promotional purposes.
Returns
boolean
booleanhasReachedLimit
Parameters
A discount can be applied to a cart for promotional purposes.
Returns
boolean
booleanisDisabled
Parameters
A discount can be applied to a cart for promotional purposes.
Returns
boolean
booleanisValidForRegion
Parameters
A discount can be applied to a cart for promotional purposes.
region_id
stringRequiredReturns
Promise
Promise<boolean>Requiredlist
Parameters
selector
FilterableDiscountPropsthe query object for find
config
FindConfig<Discount>the config object containing query settings
Returns
the result of the find operation
listAndCount
Parameters
selector
FilterableDiscountPropsthe query object for find
config
FindConfig<Discount>the config object containing query settings
Returns
the result of the find operation
listByCodes
List all the discounts corresponding to the given codes
Parameters
discountCodes
string[]Requireddiscount codes of discounts to retrieve
config
FindConfig<Discount>the config object containing query settings
Returns
the discounts
removeRegion
Removes a region from the discount regions array.
Parameters
discountId
stringRequiredid of discount
regionId
stringRequiredid of region to remove
Returns
the result of the update operation
retrieve
Gets a discount by id.
Parameters
discountId
stringRequiredid of discount to retrieve
config
FindConfig<Discount>the config object containing query settings
Returns
the discount
retrieveByCode
Gets the discount by discount code.
Parameters
discountCode
stringRequireddiscount code of discount to retrieve
config
FindConfig<Discount>the config object containing query settings
Returns
the discount
shouldRetryTransaction_
Parameters
err
Record<string, unknown> | { code: string }RequiredReturns
boolean
booleanupdate
Updates a discount.
Parameters
discountId
stringRequireddiscount id of discount to update
the data to update the discount with
Returns
the result of the update operation
validateDiscountForCartOrThrow
Parameters
Returns
Promise
Promise<void>RequiredvalidateDiscountForProduct
Parameters
discountRuleId
stringRequiredproductId
stringReturns
Promise
Promise<boolean>RequiredvalidateDiscountRule_
Creates a discount rule with provided data given that the data is validated.
Parameters
discountRule
TRequiredthe discount rule to create
Returns
withTransaction
Parameters
transactionManager
EntityManagerReturns
Was this section helpful?