Search.../

updateDiscountRule( )

Developer Preview

Updates a discount rule's properties.

Description

The updateDiscountRule() function returns a Promise that resolves when the specified discount rule's properties are updated.

Each time the discount rule is updated, revision increments by 1. The existing revision must be included when updating the discount rule. This ensures you're working with the latest discount rule information, and it prevents unintended overwrites.

Admin Method

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

Syntax

function updateDiscountRule(_id: string, discountRule: UpdateDiscountRule): Promise<DiscountRule>

updateDiscountRule Parameters

NAME
TYPE
DESCRIPTION
_id
string

Discount rule ID.

discountRule
UpdateDiscountRule

Discount rule info.

Returns

Updated 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?

updateDiscountRule example

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