# Custom Sortierung durch Subscriber oder AbstractListingProcessor

**URL:** <https://forum.shopware.com/t/custom-sortierung-durch-subscriber-oder-abstractlistingprocessor/102510>\
**Category:** Shopware 6 (German)\
**Created:** [15. Januar 2024 um 11:26 UTC](https://forum.shopware.com/t/custom-sortierung-durch-subscriber-oder-abstractlistingprocessor/102510 "2024-01-15T11:26:29Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ShadowHunter](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/shadowhunter/32/22740_2.png) [@ShadowHunter](https://forum.shopware.com/u/ShadowHunter)\
**Post date:** [15. Januar 2024 um 11:26 UTC](https://forum.shopware.com/t/custom-sortierung-durch-subscriber-oder-abstractlistingprocessor/102510/1 "2024-01-15T11:26:29Z")

</div>

Ich versuche, eine Custom Sortierung hinzuzufügen, die die Sortierung abhängig von meinem eigenen Entitätswert und das[Dokument](https://developer.shopware.com/docs/guides/plugins/plugins/storefront/add-custom-sorting-product-listing.html#create-individual-sorting-at-runtime) schlägt vor, dass es möglich ist, eine Custom Sortierung entweder durch eine Datenbankmigration oder **Subscriber** zu erstellen, und nach mehr  
Recherche habe ich herausgefunden, dass diese Methode in Zukunft nicht mehr verfügbar sein wird dass es durch den **AbstractListingProcessor** ersetzt würde, aber beide erstellen keinen neuen Wert für meine „custom-sorting“ in der Datenbank und geben mir die Fehlermeldung „custom sorting key isn’t found“ und ich würde gerne wissen, was ich falsch mache. Ich habe genau die gleichen Schritte ausgeführt wie [Create individual sorting at runtime](https://developer.shopware.com/docs/guides/plugins/plugins/storefront/add-custom-sorting-product-listing.html#create-individual-sorting-at-runtime) vorschlägt (wenn ich dem Debugger folge, sieht es so aus, als würde meine benutzerdefinierte Sortierung zu „$availableSorting“ hinzugefügt, aber nicht zur Datenbank hinzugefügt) .

```
    $criteria->addAssociation('deepLearning');
    $criteria->getAssociation('deepLearning')->addSorting(new FieldSorting('clicked', 
      FieldSorting::DESCENDING));

    /** @var ProductSortingCollection $availableSortings */
    $availableSorting = $criteria->getExtension('sortings') ?? new ProductSortingCollection();

    $customSortingEntity = new ProductSortingEntity();
    $customSortingEntity ->setId(Uuid::randomHex());
    $customSortingEntity ->setActive(true);
    $customSortingEntity ->setTranslated(['label' => 'Custom Sorting']);
    $customSortingEntity ->setKey('custom-sorting');
    $customSortingEntity ->setPriority(5);
    $customSortingEntity ->setFields([
        [
            'field' => 'deepLearning.clicked',
            'order' => 'desc',
            'priority' => 1,
            'naturalSorting' => 0,
        ],
    ]);

    $availableSorting->add($customSortingEntity );

    $criteria->addExtension('sortings', $availableSorting);

```
