Skip to main content

Class: DiscountService

Provides layer to manipulate discounts.

implements {BaseService}

Hierarchy

  • "medusa-interfaces"

    DiscountService

Constructors

constructor

new DiscountService(__namedParameters)

Parameters

NameType
__namedParametersObject

Overrides

BaseService.constructor

Defined in

services/discount.ts:59

Properties

discountConditionRepository_

Private discountConditionRepository_: typeof DiscountConditionRepository

Defined in

services/discount.ts:52


discountConditionService_

Private discountConditionService_: DiscountConditionService

Defined in

services/discount.ts:53


discountRepository_

Private discountRepository_: typeof DiscountRepository

Defined in

services/discount.ts:49


discountRuleRepository_

Private discountRuleRepository_: typeof DiscountRuleRepository

Defined in

services/discount.ts:50


eventBus_

Private eventBus_: EventBusService

Defined in

services/discount.ts:57


giftCardRepository_

Private giftCardRepository_: typeof GiftCardRepository

Defined in

services/discount.ts:51


manager_

Private manager_: EntityManager

Defined in

services/discount.ts:48


productService_

Private productService_: ProductService

Defined in

services/discount.ts:55


regionService_

Private regionService_: RegionService

Defined in

services/discount.ts:56


totalsService_

Private totalsService_: TotalsService

Defined in

services/discount.ts:54

Methods

addRegion

addRegion(discountId, regionId): Promise<Discount>

Adds a region to the discount regions array.

Parameters

NameTypeDescription
discountIdstringid of discount
regionIdstringid of region to add

Returns

Promise<Discount>

the result of the update operation

Defined in

services/discount.ts:521


calculateDiscountForLineItem

calculateDiscountForLineItem(discountId, lineItem, cart): Promise<number>

Parameters

NameType
discountIdstring
lineItemLineItem
cartCart

Returns

Promise<number>

Defined in

services/discount.ts:624


canApplyForCustomer

canApplyForCustomer(discountRuleId, customerId): Promise<boolean>

Parameters

NameType
discountRuleIdstring
customerIdundefined | string

Returns

Promise<boolean>

Defined in

services/discount.ts:762


create

create(discount): Promise<Discount>

Creates a discount with provided data given that the data is validated. Normalizes discount code to uppercase.

Parameters

NameTypeDescription
discountCreateDiscountInputthe discount data to create

Returns

Promise<Discount>

the result of the create operation

Defined in

services/discount.ts:220


createDynamicCode

createDynamicCode(discountId, data): Promise<Discount>

Creates a dynamic code for a discount id.

Parameters

NameTypeDescription
discountIdstringthe id of the discount to create a code for
dataCreateDynamicDiscountInputthe object containing a code to identify the discount by

Returns

Promise<Discount>

the newly created dynamic code

Defined in

services/discount.ts:446


delete

delete(discountId): Promise<void>

Deletes a discount idempotently

Parameters

NameTypeDescription
discountIdstringid of discount to delete

Returns

Promise<void>

the result of the delete operation

Defined in

services/discount.ts:583


deleteDynamicCode

deleteDynamicCode(discountId, code): Promise<void>

Deletes a dynamic code for a discount id.

Parameters

NameTypeDescription
discountIdstringthe id of the discount to create a code for
codestringthe code to identify the discount by

Returns

Promise<void>

the newly created dynamic code

Defined in

services/discount.ts:498


hasExpired

hasExpired(discount): boolean

Parameters

NameType
discountDiscount

Returns

boolean

Defined in

services/discount.ts:733


hasNotStarted

hasNotStarted(discount): boolean

Parameters

NameType
discountDiscount

Returns

boolean

Defined in

services/discount.ts:729


hasReachedLimit

hasReachedLimit(discount): boolean

Parameters

NameType
discountDiscount

Returns

boolean

Defined in

services/discount.ts:723


isDisabled

isDisabled(discount): boolean

Parameters

NameType
discountDiscount

Returns

boolean

Defined in

services/discount.ts:741


isValidForRegion

isValidForRegion(discount, region_id): Promise<boolean>

Parameters

NameType
discountDiscount
region_idstring

Returns

Promise<boolean>

Defined in

services/discount.ts:745


list

list(selector?, config?): Promise<Discount[]>

Parameters

NameTypeDescription
selectorFilterableDiscountPropsthe query object for find
configFindConfig<Discount>the config object containing query settings

Returns

Promise<Discount[]>

the result of the find operation

Defined in

services/discount.ts:156


listAndCount

listAndCount(selector?, config?): Promise<[Discount[], number]>

Parameters

NameTypeDescription
selectorFilterableDiscountPropsthe query object for find
configFindConfig<Discount>the config object containing query settings

Returns

Promise<[Discount[], number]>

the result of the find operation

Defined in

services/discount.ts:173


removeRegion

removeRegion(discountId, regionId): Promise<Discount>

Removes a region from the discount regions array.

Parameters

NameTypeDescription
discountIdstringid of discount
regionIdstringid of region to remove

Returns

Promise<Discount>

the result of the update operation

Defined in

services/discount.ts:557


retrieve

retrieve(discountId, config?): Promise<Discount>

Gets a discount by id.

Parameters

NameTypeDescription
discountIdstringid of discount to retrieve
configFindConfig<Discount>the config object containing query settings

Returns

Promise<Discount>

the discount

Defined in

services/discount.ts:285


retrieveByCode

retrieveByCode(discountCode, config?): Promise<Discount>

Gets a discount by discount code.

Parameters

NameTypeDescription
discountCodestringdiscount code of discount to retrieve
configFindConfig<Discount>the config object containing query settings

Returns

Promise<Discount>

the discount document

Defined in

services/discount.ts:313


update

update(discountId, update): Promise<Discount>

Updates a discount.

Parameters

NameTypeDescription
discountIdstringdiscount id of discount to update
updateUpdateDiscountInputthe data to update the discount with

Returns

Promise<Discount>

the result of the update operation

Defined in

services/discount.ts:348


validateDiscountForCartOrThrow

validateDiscountForCartOrThrow(cart, discount): Promise<void>

Parameters

NameType
cartCart
discountDiscount

Returns

Promise<void>

Defined in

services/discount.ts:665


validateDiscountForProduct

validateDiscountForProduct(discountRuleId, productId): Promise<boolean>

Parameters

NameType
discountRuleIdstring
productIdundefined | string

Returns

Promise<boolean>

Defined in

services/discount.ts:599


validateDiscountRule_

validateDiscountRule_<T>(discountRule): T

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

Type parameters

NameType
Textends Object

Parameters

NameTypeDescription
discountRuleTthe discount rule to create

Returns

T

the result of the create operation

Defined in

services/discount.ts:138


withTransaction

withTransaction(transactionManager): DiscountService

Parameters

NameType
transactionManagerEntityManager

Returns

DiscountService

Defined in

services/discount.ts:108