# 3. Rule Sets & Validation

The plugin supports two types of rules: **completeness rules** (weighted score) and **validation rules** (binary pass/fail). Both are managed through rule sets.

## Managing rule sets

Go to **Catalogues → Product Completeness → Rule Sets** to view, create, and edit your rule sets.

### Creating a rule set

Click **Add rule set** and fill in the form:

* **Name**: An internal name for the rule set (e.g. "Standard Checklist" or "SEO Audit")
* **Sales channels** *(optional)*: Restrict the rule set to one or more sales channels. Leave empty to apply it across all channels.
* **Language** *(optional)*: Limit the rule set to a specific language. Leave empty to evaluate all languages.

### Adding conditions

Each rule set contains one or more conditions. For each condition, you configure:

| Setting                          | Description                                                                       |
| -------------------------------- | --------------------------------------------------------------------------------- |
| **Field**                        | The product field to evaluate (auto-detected from Shopware's `ProductDefinition`) |
| **Operator**                     | The check logic: `required`, `min_length`, `count_min`, `regex`, and more         |
| **Value** *(operator-dependent)* | The comparison value, e.g. minimum length or minimum count                        |
| **Weight**                       | Completeness rules only: how much this field contributes to the score             |
| **Rule type**                    | Completeness rule (score) or validation rule (valid/invalid)                      |

![Rule set form with conditions](https://459847022-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LtiS3-dzuXFp_IH7yRw-1972196547%2Fuploads%2Fgit-blob-1a13d1a09cb7abbde12041c73cd4341c451e19d2%2F4.png?alt=media)

### Supported operators

| Operator     | Description                                           |
| ------------ | ----------------------------------------------------- |
| `required`   | Field must be present and non-empty                   |
| `min_length` | Text must be at least N characters long               |
| `count_min`  | Collection (e.g. images) must have at least N entries |
| `regex`      | Field value must match a regular expression           |

All regex inputs are validated against ReDoS patterns before saving.

## Completeness rules

Completeness rules contribute to the **weighted score** (0–100%). A product reaches 100% when all conditions in its applicable rule sets are satisfied.

**Example configuration:**

| Field       | Operator        | Weight |
| ----------- | --------------- | ------ |
| Name        | required        | 20     |
| Description | min\_length 100 | 30     |
| Cover image | required        | 25     |
| Categories  | count\_min 1    | 15     |
| Meta title  | required        | 10     |

## Validation rules

Validation rules check **binary conditions** — a product is either valid or invalid. They are shown separately from the score in the dashboard and product list.

Use validation rules for mandatory fields that must always be present (e.g. EAN, manufacturer number) where weighted scoring doesn't make sense.

## Scope: sales channel & language

A rule set only applies to products assigned to the selected sales channel. This lets you define different quality requirements for different shops or export channels:

* **No filter**: The rule set applies to all products in all channels
* **Sales channel filter**: Only products in these channels are evaluated against this rule set
* **Language filter**: Only product translations in this language are evaluated

## Managing rule sets

All configured rule sets are shown in an overview with their name, scope badge, and condition count. Use the toggle in the **Active** column to temporarily disable individual rule sets without deleting them.

![List of completeness rule sets](https://459847022-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LtiS3-dzuXFp_IH7yRw-1972196547%2Fuploads%2Fgit-blob-765965bf24c49b9f2e61ffd7c0383feb6d293886%2F5.png?alt=media)

## Recalculating scores

After changes to rule sets, scores are **not** automatically recalculated for all products. Click **Recalculate Scores** on the dashboard to trigger a full recalculation. This runs asynchronously — depending on catalog size, it may take a few minutes.

Individual product scores are updated automatically every time that product is saved.
