# Sorting

### 1. Core Sorting Behaviour by Shopware Version

#### ≤ Shopware 6.6.9

| Area            | Behaviour                                                                                                                                                                                                      |
| --------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Admin panel** | <p>• One unified sorting configuration covers both category listings <em>and</em> search results.<br>• The <em>Top Results</em> (<code>score</code>) option is <strong>not</strong> visible/selectable.</p>    |
| **Storefront**  | <p><strong>Category pages</strong> – <em>Top Results</em> is absent from the dropdown.<br><strong>Search results</strong> – <em>Top Results</em> is hard-coded as the default and visible in the dropdown.</p> |

<figure><img src="https://2164703617-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGRcylPzIZ8Znff4RskcP%2Fuploads%2FkmO5DsBc1k6qm7Fh3Hiu%2Fsw%20default%20sorting.png?alt=media&#x26;token=20258f24-a43a-40b1-b27e-ffa06fa522f4" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2164703617-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGRcylPzIZ8Znff4RskcP%2Fuploads%2F6WFagP1hTKyQ9k5HQ8Ur%2Ffront%20default%20sorting.png?alt=media&#x26;token=7e72be90-da5a-44a7-bcf0-3becafa48be4" alt=""><figcaption></figcaption></figure>

***

#### ≥ Shopware 6.6.10

| Area            | Behaviour                                                                                                                                                                                                                                                                                |
| --------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Admin panel** | <p>• Sorting settings are split: one for <strong>categories</strong>, one for <strong>search</strong>.<br>• <em>Top Results</em> appears <strong>only</strong> in <strong>Search</strong> sorting.<br>• <em>Top Results</em> is still absent from <strong>Category</strong> sorting.</p> |
| **Storefront**  | <p><strong>Category pages</strong> – <em>Top Results</em> still not shown.<br><strong>Search results</strong> – <em>Top Results</em> remains hard-coded as default.</p>                                                                                                                  |

<figure><img src="https://2164703617-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGRcylPzIZ8Znff4RskcP%2Fuploads%2F7cNCWc7QY2oiqXvrMPuj%2Fimage-20250310-113220.png?alt=media&#x26;token=a1749424-119c-43f6-adab-7f57a17994c0" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2164703617-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGRcylPzIZ8Znff4RskcP%2Fuploads%2FXTuOzN4jNj0vW8aC9yI7%2Fimage-20250310-113532.png?alt=media&#x26;token=adcc7527-d220-4fa8-85d1-5abea31e6409" alt=""><figcaption></figcaption></figure>

<br>

***

### 2. What the Nosto Plugin Adds

| Property  | Value                                                       | Purpose                           |
| --------- | ----------------------------------------------------------- | --------------------------------- |
| **Label** | *Recommendation*                                            | Human-readable name               |
| **Key**   | `nosto-recommendation`                                      | Technical identifier              |
| **Usage** | May be set as default in **both** category and search pages | Personalised relevance-based sort |

***

### 3. Plugin Lifecycle & Fallback Logic

#### ✔️ Install

* Adds *Recommendation* if it does not yet exist.

#### ❌ Uninstall

* Removes *Recommendation*.
* **Fallbacks** if *Recommendation* was the default:

| Shopware Version | Area(s)        | Action                                                                           |
| ---------------- | -------------- | -------------------------------------------------------------------------------- |
| ≤ 6.6.9          | Unified config | Pick first active, unlocked option with highest priority                         |
| ≥ 6.6.10         | Category       | Same as above                                                                    |
|                  | Search         | Use *Top Results* if present; otherwise first active, unlocked, highest-priority |

#### 🚫 Deactivate

* Marks *Recommendation* as inactive (`active = 0`).
* Applies the same fallback rules as **Uninstall**.

#### ✔️ Activate

* Sets `active = 1` for *Recommendation* without touching existing defaults.

***

### 4. Storefront Visibility Logic

“Why don’t I see both *Top Results* and *Recommendation*?”

Only **one** relevance-based option is shown to avoid duplication.

| Condition                      | Visible in Dropdown    | Hidden                |
| ------------------------------ | ---------------------- | --------------------- |
| *Top Results* is default       | *Top Results*          | Recommendation        |
| *Recommendation* is default    | Recommendation         | Top Results           |
| Neither is default             | Higher-priority option | Lower-priority option |
| Same priority, neither default | Recommendation         | Top Results           |

> **Rule of thumb:** *Recommendation* replaces *Top Results* when its priority is **≥** the priority of *Top Results*.

***

#### If Nosto Services Are Inactive

*Recommendation* is suppressed in the storefront—but still remains configured in Admin.\
Customers then see whichever active option has the highest priority instead.

***

### 5. Shopware Handling of Sortings Without Criteria

If a sorting option contains **no criteria**, Shopware runs the listing **without** an `ORDER BY` clause. MySQL then applies a nondeterministic order (effectively by ID). Shopware mitigates this by appending a fallback sort on product ID.

***

### 6. Managing Sorting Options in the Backend

#### Changing Priority

1. **Settings → Catalogue → Product Sorting**
2. Drag options or adjust the **Priority** column.

<figure><img src="https://2164703617-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGRcylPzIZ8Znff4RskcP%2Fuploads%2FQ0wcOVyOvsTWBothweZd%2Fsw%20sort%20prio.png?alt=media&#x26;token=230bc544-a445-4bce-9334-966200078fe4" alt=""><figcaption></figcaption></figure>

*Higher numbers = higher dropdown position.*\
\&#xNAN;*Avoid giving two options the exact same priority.*

#### Creating a New Option

1. Click **Add option**.<br>

   <figure><img src="https://2164703617-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGRcylPzIZ8Znff4RskcP%2Fuploads%2Fb9KKriAlQONRNZxqVAKK%2Fsw%20add%20option.png?alt=media&#x26;token=63224150-da6c-4464-98b9-8eb2fa8e4efa" alt=""><figcaption></figcaption></figure>
2. Fill in **Name**, **Technical name**, set **Active**, and add criteria.<br>

   <figure><img src="https://2164703617-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGRcylPzIZ8Znff4RskcP%2Fuploads%2Faj7RLgGzLpKnDmrvvQcg%2Fsw%20add%20option%20config.png?alt=media&#x26;token=1cfc65f6-2185-4344-950a-3264cea4073e" alt=""><figcaption></figcaption></figure>
3. For each criterion define **Order** *(ASC/DESC)* and \**Priority*.<br>

   <figure><img src="https://2164703617-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGRcylPzIZ8Znff4RskcP%2Fuploads%2FvmxQFWfQl6XnYPgcfXdA%2Fsw%20add%20option%20config%20criteria%20setup.png?alt=media&#x26;token=e5361555-b16b-4d11-943c-0acbc480b86e" alt=""><figcaption></figcaption></figure>

***

### 7. Using a Custom Field as Sorting Criteria

1. Create the custom field in **Shopware Backend → Settings → Custom fields** and attach it to products.<br>

   <figure><img src="https://2164703617-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGRcylPzIZ8Znff4RskcP%2Fuploads%2FF4v6hV0wS3o1E8hrOOwC%2Fcf%201.png?alt=media&#x26;token=8dde6c58-fd5e-48a0-9eb3-c3720adfe712" alt=""><figcaption></figcaption></figure>
2. Back in **Product Sorting**, pick the custom field from the **Name** dropdown.<br>

   <figure><img src="https://2164703617-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGRcylPzIZ8Znff4RskcP%2Fuploads%2F01Dsd46EllWKAzlDaOS0%2Fcf%202.png?alt=media&#x26;token=aba07b61-a632-4fdc-98f8-212bceddbedf" alt=""><figcaption></figcaption></figure>
3. In **Settings → Extensions → Nosto**, add the same custom field.<br>

   <figure><img src="https://2164703617-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGRcylPzIZ8Znff4RskcP%2Fuploads%2Fb3zGlHEo2wPhliiQo67x%2Fcf%203.png?alt=media&#x26;token=d0d09535-ec97-4d3f-9242-2888d3c1c3a0" alt=""><figcaption></figcaption></figure>
4. Run a **Full Product Sync**.
5. In the Nosto account:\
   **Product Experience Cloud → Search → Settings → Indexed fields → + Add attribute**.<br>

   <figure><img src="https://2164703617-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGRcylPzIZ8Znff4RskcP%2Fuploads%2F1gXZtCsy4XLdUyXTkgtg%2Fnosto%20add%20attribute.png?alt=media&#x26;token=3654f278-f4db-43b6-b4d0-6d3abf5ef1d4" alt=""><figcaption></figcaption></figure>
6. Save. Indexing runs every 6 hours—changes may take time to appear.<br>

   <figure><img src="https://2164703617-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FGRcylPzIZ8Znff4RskcP%2Fuploads%2F6J5xwDj3q1HKFVEzu4Y4%2Fcf%20shop.png?alt=media&#x26;token=337f4680-d63a-47dc-b66b-595db8fc3325" alt=""><figcaption></figcaption></figure>
