# 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="/files/dghjcpwBJsTwYBIlTcXu" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/H3dC4lqfceeCjZzXmQph" 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="/files/zsWFVIY5NFDOmLeYjYhf" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/SGHewPWZUmaV6Es1CD8a" 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="/files/6375o9ehq4FaGyc7q3lM" 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="/files/M68nlyuZIJ5AeQyDORKR" alt=""><figcaption></figcaption></figure>
2. Fill in **Name**, **Technical name**, set **Active**, and add criteria.<br>

   <figure><img src="/files/fMwPDpB5iOcwiAb8WIEN" alt=""><figcaption></figcaption></figure>
3. For each criterion define **Order** *(ASC/DESC)* and \**Priority*.<br>

   <figure><img src="/files/zRCxEB2IbI7u4mYtW4V1" 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="/files/ijxEm09vl8iz4dxoFlik" alt=""><figcaption></figcaption></figure>
2. Back in **Product Sorting**, pick the custom field from the **Name** dropdown.<br>

   <figure><img src="/files/ME9a7zllXWmdsuh0kn5K" alt=""><figcaption></figcaption></figure>
3. In **Settings → Extensions → Nosto**, add the same custom field.<br>

   <figure><img src="/files/FPSqB6i7vYhRHrigkbJP" 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="/files/BXEAB5xKUgJCOfGbweUr" alt=""><figcaption></figcaption></figure>
6. Save. Indexing runs every 6 hours—changes may take time to appear.<br>

   <figure><img src="/files/wRq2W04Jf3unHMJ05DFu" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.nosto.com/shopware-6/getting-started/guides/sorting.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
