Search.../

getDiscountRule( )

Retrieves a discount rule.

Description

The getDiscountRule() function returns a Promise that resolves when the specified discount rule is retrieved.

Admin Method

This function requires elevated permissions to run. This function is not universal and runs only on the backend.

Syntax

function getDiscountRule(discountRuleId: string): Promise<DiscountRule>

getDiscountRule Parameters

NAME
TYPE
DESCRIPTION
discountRuleId
string

ID of the discount rule to retrieve.

Returns

The requested discount rule.

Return Type:

Promise<
DiscountRule
>
NAME
TYPE
DESCRIPTION
_createdDate
Date

Date and time the discount rule was created.

_id
string

Discount rule ID.

_updatedDate
Date

Date and time the discount rule was last updated.

active
boolean

Whether the discount rule is active.

Default: true

activeTimeInfo
ActiveTimeInfo

Time frame in which the discount rule is active.

discounts
Discounts

List of discounts that are applied when one or more triggers are met.

Currently, a discount rule can apply only 1 discount.

name
string

Discount rule name.

revision
string

Revision number, which increments by 1 each time the discount rule is updated. To prevent conflicting changes, the current revision must be passed when updating the discount rule.

status
string

Discount rule status.

trigger
DiscountTrigger

Discount rule trigger. A set of conditions that must be met for the discounts to be applied. Not passing a trigger will cause the discount to always apply.

usageCount
number

Number of times the discount rule was used.

Was this helpful?

getDiscountRule example

Copy Code
1import { discountRules } from 'wix-ecom-backend';
2
3 async function getDiscountRule(discountRuleId) {
4 try {
5 const result = await discountRules.getDiscountRule(discountRuleId);
6
7 return result;
8 } catch (error) {
9 console.error(error);
10 // Handle the error
11 }
12 }
13