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
EntityManagerEntityManagerRequiredMethods
addRegion
Adds a region to the discount regions array.
Parameters
discountIdstringRequiredid of discount
regionIdstringRequiredid 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
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>Requiredthe result of the transactional work
calculateDiscountForLineItem
Parameters
discountIdstringRequiredLine 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
PromisePromise<number>RequiredcanApplyForCustomer
Parameters
discountRuleIdstringRequiredcustomerIdundefined | stringRequiredReturns
PromisePromise<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
discountIdstringRequiredthe 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
discountIdstringRequiredid of discount to delete
Returns
PromisePromise<void>Requiredthe result of the delete operation
deleteDynamicCode
Deletes a dynamic code for a discount id.
Parameters
discountIdstringRequiredthe id of the discount to create a code for
codestringRequiredthe code to identify the discount by
Returns
PromisePromise<void>Requiredthe newly created dynamic code
hasCustomersGroupCondition
Parameters
A discount can be applied to a cart for promotional purposes.
Returns
booleanbooleanhasExpired
Parameters
A discount can be applied to a cart for promotional purposes.
Returns
booleanbooleanhasNotStarted
Parameters
A discount can be applied to a cart for promotional purposes.
Returns
booleanbooleanhasReachedLimit
Parameters
A discount can be applied to a cart for promotional purposes.
Returns
booleanbooleanisDisabled
Parameters
A discount can be applied to a cart for promotional purposes.
Returns
booleanbooleanisValidForRegion
Parameters
A discount can be applied to a cart for promotional purposes.
region_idstringRequiredReturns
PromisePromise<boolean>Requiredlist
Parameters
selectorFilterableDiscountPropsthe query object for find
configFindConfig<Discount>the config object containing query settings
Returns
the result of the find operation
listAndCount
Parameters
selectorFilterableDiscountPropsthe query object for find
configFindConfig<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
discountCodesstring[]Requireddiscount codes of discounts to retrieve
configFindConfig<Discount>the config object containing query settings
Returns
the discounts
removeRegion
Removes a region from the discount regions array.
Parameters
discountIdstringRequiredid of discount
regionIdstringRequiredid of region to remove
Returns
the result of the update operation
retrieve
Gets a discount by id.
Parameters
discountIdstringRequiredid of discount to retrieve
configFindConfig<Discount>the config object containing query settings
Returns
the discount
retrieveByCode
Gets the discount by discount code.
Parameters
discountCodestringRequireddiscount code of discount to retrieve
configFindConfig<Discount>the config object containing query settings
Returns
the discount
shouldRetryTransaction_
Parameters
errRecord<string, unknown> | { code: string }RequiredReturns
booleanbooleanupdate
Updates a discount.
Parameters
discountIdstringRequireddiscount id of discount to update
the data to update the discount with
Returns
the result of the update operation
validateDiscountForCartOrThrow
Parameters
Returns
PromisePromise<void>RequiredvalidateDiscountForProduct
Parameters
discountRuleIdstringRequiredproductIdstringReturns
PromisePromise<boolean>RequiredvalidateDiscountRule_
Creates a discount rule with provided data given that the data is validated.
Parameters
discountRuleTRequiredthe discount rule to create
Returns
withTransaction
Parameters
transactionManagerEntityManagerReturns
Was this section helpful?