Skip to main content
Skip to main content

DiscountService

Provides layer to manipulate discounts.

Implements

Properties

__configModule__Record<string, unknown>
__container__anyRequired
__moduleDeclaration__Record<string, unknown>
customerService_CustomerServiceRequired
discountConditionRepository_Repository<DiscountCondition> & { addConditionResources: Method addConditionResources ; canApplyForCustomer: Method canApplyForCustomer ; findOneWithDiscount: Method findOneWithDiscount ; getJoinTableResourceIdentifiers: Method getJoinTableResourceIdentifiers ; isValidForProduct: Method isValidForProduct ; queryConditionTable: Method queryConditionTable ; removeConditionResources: Method removeConditionResources }Required
discountConditionService_DiscountConditionServiceRequired
discountRepository_Repository<Discount>Required
discountRuleRepository_Repository<DiscountRule>Required
eventBus_EventBusServiceRequired
featureFlagRouter_FlagRouterRequired
giftCardRepository_Repository<GiftCard> & { listGiftCardsAndCount: Method listGiftCardsAndCount }Required
manager_EntityManagerRequired
newTotalsService_NewTotalsServiceRequired
productService_ProductServiceRequired
regionService_RegionServiceRequired
totalsService_TotalsServiceRequired
transactionManager_undefined | EntityManagerRequired

Accessors

activeManager_

Inherited from

TransactionBaseService.activeManager_

Methods

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

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>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

calculateDiscountForLineItem

Parameters
discountIdstringRequired
lineItemLineItemRequired
Line 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.
calculationContextDataCalculationContextDataRequired
Returns
PromisePromise<number>Required

canApplyForCustomer

Parameters
discountRuleIdstringRequired
customerIdundefined | stringRequired
Returns
PromisePromise<boolean>Required

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

createDynamicCode

Creates a dynamic code for a discount id.

Parameters
discountIdstringRequired
the id of the discount to create a code for
the object containing a code to identify the discount by
Returns
PromisePromise<Discount>Required
the newly created dynamic code

delete

Deletes a discount idempotently

Parameters
discountIdstringRequired
id of discount to delete
Returns
PromisePromise<void>Required
the result of the delete operation

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

hasCustomersGroupCondition

Parameters
discountDiscountRequired
A discount can be applied to a cart for promotional purposes.
Returns
booleanboolean

hasExpired

Parameters
discountDiscountRequired
A discount can be applied to a cart for promotional purposes.
Returns
booleanboolean

hasNotStarted

Parameters
discountDiscountRequired
A discount can be applied to a cart for promotional purposes.
Returns
booleanboolean

hasReachedLimit

Parameters
discountDiscountRequired
A discount can be applied to a cart for promotional purposes.
Returns
booleanboolean

isDisabled

Parameters
discountDiscountRequired
A discount can be applied to a cart for promotional purposes.
Returns
booleanboolean

isValidForRegion

Parameters
discountDiscountRequired
A discount can be applied to a cart for promotional purposes.
region_idstringRequired
Returns
PromisePromise<boolean>Required

list

Parameters
the query object for find
the config object containing query settings
Returns
PromisePromise<Discount[]>Required
the result of the find operation

listAndCount

Parameters
the query object for find
the config object containing query settings
Returns
PromisePromise<[Discount[], number]>Required
the result of the find operation

listByCodes

List all the discounts corresponding to the given codes

Parameters
discountCodesstring[]Required
discount codes of discounts to retrieve
the config object containing query settings
Returns
PromisePromise<Discount[]>Required
the discounts

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

retrieve

Gets a discount by id.

Parameters
discountIdstringRequired
id of discount to retrieve
the config object containing query settings
Returns
PromisePromise<Discount>Required
the discount

retrieveByCode

Gets the discount by discount code.

Parameters
discountCodestringRequired
discount code of discount to retrieve
the config object containing query settings
Returns
PromisePromise<Discount>Required
the discount

shouldRetryTransaction_

Parameters
errRecord<string, unknown> | { code: string }Required
Returns
booleanboolean

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

validateDiscountForCartOrThrow

Parameters
cartCartRequired
A cart represents a virtual shopping bag. It can be used to complete an order, a swap, or a claim.
discountDiscount | Discount[]Required
Returns
PromisePromise<void>Required

validateDiscountForProduct

Parameters
discountRuleIdstringRequired
productIdstring
Returns
PromisePromise<boolean>Required

validateDiscountRule_

Creates a discount rule with provided data given that the data is validated.

Parameters
discountRuleTRequired
the discount rule to create
Returns
TTRequired
the result of the create operation

withTransaction

Parameters
transactionManagerEntityManager
Returns
DiscountServiceDiscountServiceRequired
Was this section helpful?