--- displayed_sidebar: servicesSidebar --- import ParameterTypes from "@site/src/components/ParameterTypes" # DiscountService Provides layer to manipulate discounts. #### Implements ## Constructors ### constructor `**new DiscountService**(«destructured»)` #### Parameters ## Properties `", "description": "", "optional": true, "defaultValue": "", "expandable": false, "children": [] }, { "name": "__container__", "type": "`any`", "description": "", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "__moduleDeclaration__", "type": "`Record`", "description": "", "optional": true, "defaultValue": "", "expandable": false, "children": [] }, { "name": "customerService_", "type": "[CustomerService](CustomerService.mdx)", "description": "", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "discountConditionRepository_", "type": "Repository<[DiscountCondition](DiscountCondition.mdx)> & `{ addConditionResources: Method addConditionResources ; canApplyForCustomer: Method canApplyForCustomer ; findOneWithDiscount: Method findOneWithDiscount ; getJoinTableResourceIdentifiers: Method getJoinTableResourceIdentifiers ; isValidForProduct: Method isValidForProduct ; queryConditionTable: Method queryConditionTable ; removeConditionResources: Method removeConditionResources }`", "description": "", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "discountConditionService_", "type": "[DiscountConditionService](DiscountConditionService.mdx)", "description": "", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "discountRepository_", "type": "Repository<[Discount](Discount.mdx)>", "description": "", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "discountRuleRepository_", "type": "Repository<[DiscountRule](DiscountRule.mdx)>", "description": "", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "eventBus_", "type": "[EventBusService](EventBusService.mdx)", "description": "", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "featureFlagRouter_", "type": "[FlagRouter](FlagRouter.mdx)", "description": "", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "giftCardRepository_", "type": "Repository<[GiftCard](GiftCard.mdx)> & `{ listGiftCardsAndCount: Method listGiftCardsAndCount }`", "description": "", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "manager_", "type": "EntityManager", "description": "", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "newTotalsService_", "type": "[NewTotalsService](NewTotalsService.mdx)", "description": "", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "productService_", "type": "[ProductService](ProductService.mdx)", "description": "", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "regionService_", "type": "[RegionService](RegionService.mdx)", "description": "", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "totalsService_", "type": "[TotalsService](TotalsService.mdx)", "description": "", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "transactionManager_", "type": "`undefined` \\| EntityManager", "description": "", "optional": false, "defaultValue": "", "expandable": false, "children": [] } ]} /> ## Accessors ### activeManager\_ `Protected get**activeManager_**(): EntityManager` #### Returns EntityManager ## Methods ### addRegion `**addRegion**(discountId, regionId): Promise<[Discount](Discount.mdx)>` Adds a region to the discount regions array. #### Parameters #### Returns Promise<[Discount](Discount.mdx)> ___ ### atomicPhase\_ `Protected **atomicPhase_**(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. #### Parameters Promise<TResult>", "description": "the transactional work to be done", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "isolationOrErrorHandler", "type": "`IsolationLevel` \\| (`error`: `TError`) => Promise<void \\| TResult>", "description": "the isolation level to be used for the work.", "optional": true, "defaultValue": "", "expandable": false, "children": [] }, { "name": "maybeErrorHandlerOrDontFail", "type": "(`error`: `TError`) => Promise<void \\| TResult>", "description": "Potential error handler", "optional": true, "defaultValue": "", "expandable": false, "children": [] } ]} /> #### Returns Promise<TResult> ___ ### calculateDiscountForLineItem `**calculateDiscountForLineItem**(discountId, lineItem, calculationContextData): Promise<number>` #### Parameters #### Returns Promise<number> ___ ### canApplyForCustomer `**canApplyForCustomer**(discountRuleId, customerId): Promise<boolean>` #### Parameters #### Returns Promise<boolean> ___ ### create `**create**(discount): Promise<[Discount](Discount.mdx)>` Creates a discount with provided data given that the data is validated. Normalizes discount code to uppercase. #### Parameters #### Returns Promise<[Discount](Discount.mdx)> ___ ### createDynamicCode `**createDynamicCode**(discountId, data): Promise<[Discount](Discount.mdx)>` Creates a dynamic code for a discount id. #### Parameters #### Returns Promise<[Discount](Discount.mdx)> ___ ### delete `**delete**(discountId): Promise<void>` Deletes a discount idempotently #### Parameters #### Returns Promise<void> ___ ### deleteDynamicCode `**deleteDynamicCode**(discountId, code): Promise<void>` Deletes a dynamic code for a discount id. #### Parameters #### Returns Promise<void> ___ ### hasCustomersGroupCondition `**hasCustomersGroupCondition**(discount): boolean` #### Parameters #### Returns `boolean` ___ ### hasExpired `**hasExpired**(discount): boolean` #### Parameters #### Returns `boolean` ___ ### hasNotStarted `**hasNotStarted**(discount): boolean` #### Parameters #### Returns `boolean` ___ ### hasReachedLimit `**hasReachedLimit**(discount): boolean` #### Parameters #### Returns `boolean` ___ ### isDisabled `**isDisabled**(discount): boolean` #### Parameters #### Returns `boolean` ___ ### isValidForRegion `**isValidForRegion**(discount, region_id): Promise<boolean>` #### Parameters #### Returns Promise<boolean> ___ ### list `**list**(selector?, config?): Promise<[Discount](Discount.mdx)[]>` #### Parameters #### Returns Promise<[Discount](Discount.mdx)[]> ___ ### listAndCount `**listAndCount**(selector?, config?): Promise<[[Discount](Discount.mdx)[], number]>` #### Parameters #### Returns Promise<[[Discount](Discount.mdx)[], number]> ___ ### listByCodes `**listByCodes**(discountCodes, config?): Promise<[Discount](Discount.mdx)[]>` List all the discounts corresponding to the given codes #### Parameters #### Returns Promise<[Discount](Discount.mdx)[]> ___ ### removeRegion `**removeRegion**(discountId, regionId): Promise<[Discount](Discount.mdx)>` Removes a region from the discount regions array. #### Parameters #### Returns Promise<[Discount](Discount.mdx)> ___ ### retrieve `**retrieve**(discountId, config?): Promise<[Discount](Discount.mdx)>` Gets a discount by id. #### Parameters #### Returns Promise<[Discount](Discount.mdx)> ___ ### retrieveByCode `**retrieveByCode**(discountCode, config?): Promise<[Discount](Discount.mdx)>` Gets the discount by discount code. #### Parameters #### Returns Promise<[Discount](Discount.mdx)> ___ ### shouldRetryTransaction\_ `Protected **shouldRetryTransaction_**(err): boolean` #### Parameters ` \\| `{ code: string }`", "description": "", "optional": false, "defaultValue": "", "expandable": false, "children": [] } ]} /> #### Returns `boolean` ___ ### update `**update**(discountId, update): Promise<[Discount](Discount.mdx)>` Updates a discount. #### Parameters #### Returns Promise<[Discount](Discount.mdx)> ___ ### validateDiscountForCartOrThrow `**validateDiscountForCartOrThrow**(cart, discount): Promise<void>` #### Parameters #### Returns Promise<void> ___ ### validateDiscountForProduct `**validateDiscountForProduct**(discountRuleId, productId?): Promise<boolean>` #### Parameters #### Returns Promise<boolean> ___ ### validateDiscountRule\_ `**validateDiscountRule_**(discountRule): T` Creates a discount rule with provided data given that the data is validated. #### Parameters #### Returns `T` ___ ### withTransaction `**withTransaction**(transactionManager?): [DiscountService](DiscountService.mdx)` #### Parameters #### Returns [DiscountService](DiscountService.mdx)