# Discount

An object representing a discount.

# Properties

Property Type Description
uid integer The unique identifier of the delivery method.
name object Name of the discount, by language.
active boolean If this discount is active and available to use.
type string The type of discount e.g. Freight, BuyXPayY or Percentage.

# Methods

# count

Takes a filter object and returns the number of discounts found, as an integer.

# Parameters

A filter object specifying which discounts to count. See Filter objects on the page List selection.

# Example

Discount.count({
  "/active": true
})

# create

Creates a new discount. This is shorthand for set with the unique identifier null.

# Parameters

Parameter Description
patch An object containing the properties and values to set for the new discount.
query A query specifying what to return after article discount has been successful (optional). See Query language.

# Example

Discount.create({
  "name": {
    "en": "Free shipping"
  },
  "active": true,
  "type": "FreeDelivery"
})

# delete

Permanently delete a discount.

# Parameters

Parameter Description
uid The unique identifier of a discount.

# Example

Discount.delete(6735)

# get

Fetches information about a customer.

# Parameters

Parameter Description
uid The unique identifier of a customer.
query Which info to return. See Query language.

# Example

Discount.get(6735, [
  "active"
])

# getSchema

Fetches the JSON Schema which can be used for client-side validation.

# Parameters

The unique identifier of a discount or null for a new instance.

# list

Returns an array of objects representing dicsounts.

# Parameters

Parameter Description
query A query object specifying what to fetch from each discount. This is the same as for get. See Query language.
selection A list-selection object specifying which discounts to fetch. See List selection.

# Example

Discount.list([
  "uid",
  "name"
], {
  "/active": true
})

# normalize

Fetches a normalized version of the patch. Uses the same parameters as set and validate. While set also normalizes the patch, before storing, normalize only returns the normalized patch. For all properties with number types, integers or floating-point values in strings are converted to number literals. A normalization error is thrown when we are unable to convert a string to a number literal.

# Parameters

Parameter Description
uid The unique identifier of a discount or null to create a new discount.
patch An object containing the properties and values to normalize.

# Example

Customer.normalize(null, {
  "active": "true"
})

# set

Creates or updates a discount.

# Parameters

Parameter Description
uid The unique identifier of a customer or null to create a new customer.
patch An object containing the properties and values to set for the customer.
query A query specifying what to return after a successful set (optional). See Query language.

# Example

Discount.set(6735, {
  "active": false
}, [
  "uid",
  "active"
])

# validate

Validates the data to be set. The performed validation is the same as in set; it validates the resulting object and includes all the required properties. However, nothing is saved.

# Parameters

Parameter Description
uid The unique identifier of an existing discount or null.
patch An object containing the properties and values to set before validating.

# Returns

An array of validation-error objects, each containing the keys pointer (a property referenced using a JSON Pointer) and message (a readable text in the language of the context). An empty array is returned if there are no validation errors.