createDiscountRule( )
Creates a new discount rule.
Description
The createDiscountRule()
function returns a Promise that resolves to the new discount rule when it's created.
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
Discount rule info.
Returns
Discount rule.
Return Type:
NAME
TYPE
DESCRIPTION
Date and time the discount rule was created.
Discount rule ID.
Date and time the discount rule was last updated.
Whether the discount rule is active.
Default: true
Time frame in which the discount rule is active.
List of discounts that are applied when one or more triggers are met.
Currently, a discount rule can apply only 1 discount.
Discount rule name.
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.
Discount rule status.
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.
Number of times the discount rule was used.
Was this helpful?
createDiscountRule example
1import { discountRules } from 'wix-ecom-backend';23 async function createDiscountRule(discountRule) {4 try {5 const result = await discountRules.createDiscountRule(discountRule);67 return result;8 } catch (error) {9 console.error(error);10 // Handle the error11 }12 }13