Search.../

createDiscountRule( )

Developer Preview

Creates a new discount rule.

Description

The createDiscountRule() function returns a Promise that resolves to the new discount rule when it's created.

Admin Method

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

Syntax

function createDiscountRule(discountRule: DiscountRule): Promise<DiscountRule>

createDiscountRule Parameters

NAME
TYPE
DESCRIPTION
discountRule
DiscountRule

Discount rule info.

Returns

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?

createDiscountRule example

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