Venddor API - Negative Values as Option Variants

Special Negative Values in Option Combinations

In addition to regular positive option variant IDs, the Venddor API supports special negative values in certain contexts, particularly for product option exceptions. These negative values provide powerful logic for controlling option behavior.

Usage Context: Negative variant values are typically used in exception configuration (product option exceptions) to create rules about which option combinations are allowed or forbidden.

Supported Negative Values

The following special negative values can be used in the combination object when working with option exceptions:

Value Description
-1 Wildcard: Any variant of this option can be selected. This value is used to indicate that all variants of a particular option are acceptable in a given combination rule.
-2 Exclusion: No variant of this option can be selected. This value is used to indicate that no variants of a particular option are acceptable in a given combination rule.
Tip: Using negative values allows you to create powerful product configuration rules without having to specify every possible variant combination manually. This is especially useful for products with many options, where the number of potential combinations would be impractical to manage individually.

Example Usage

Here's an example of an option exception using negative values:

{
  "exception_id": "5",
  "product_id": "12",
  "combination": {
    "3": "16",
    "4": "-1",
    "17": "-2"
  }
}

Practical Example Explained

Let's break down the example above for a specific product scenario:

Assuming we have a T-shirt product with the following options:

This exception (assuming it's of the "Forbidden" type) would enforce the following rule:

"When a customer selects XXL size (variant 16), they can select any color (-1), but the Gift Wrapping option cannot be selected (-2)."

In the customer interface, this means:

Important: When using negative values in option exceptions, ensure that option IDs referenced in the combination object exist for the product. Referencing non-existent option IDs can lead to unpredictable behavior.

Using Negative Values in API Requests

When creating or updating option exceptions via the API, you can include negative values in the combination object as shown below:

POST /products/{product_id}/exceptions

Creates a new option exception for a product.

{
  "exception_type": "F",  // F = Forbidden
  "combination": {
    "3": "16",  // Size = XXL
    "4": "-1",  // Any color is allowed
    "17": "-2"  // Gift wrapping is not allowed
  }
}

Common Use Cases for Negative Values

Negative values in option combinations are particularly useful for: