# Creating a Custom Sorting only using a Subscriber or a AbstractListingProcessor

**URL:** <https://forum.shopware.com/t/creating-a-custom-sorting-only-using-a-subscriber-or-a-abstractlistingprocessor/102509>\
**Category:** Shopware 6 (English)\
**Tags:** programming\
**Created:** [15. Januar 2024 um 11:11 UTC](https://forum.shopware.com/t/creating-a-custom-sorting-only-using-a-subscriber-or-a-abstractlistingprocessor/102509 "2024-01-15T11:11:49Z")\
**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:11 UTC](https://forum.shopware.com/t/creating-a-custom-sorting-only-using-a-subscriber-or-a-abstractlistingprocessor/102509/1 "2024-01-15T11:11:49Z")

</div>

I am trying to add a custom sorting that does sorting depending on my own entity.value and as the [document](https://developer.shopware.com/docs/guides/plugins/plugins/storefront/add-custom-sorting-product-listing.html) is suggesting, it is possible to create custom sorting either through a database migration or **Subscriber** and after more digging I found out that in the future this method won’t be available in the future and that it would be replaced with the **AbstractListingProcessor** but both of them will not create a new value for my ` custom sorting` in the database and gives me the `custom-sorting key isn't found` error. and I would like to know what I am doing wrong I did the same exact steps that [Create individual sorting at runtime document](https://developer.shopware.com/docs/guides/plugins/plugins/storefront/add-custom-sorting-product-listing.html#create-individual-sorting-at-runtime) suggest (when following the debugger it looks that my custom sorting is being added to the `$availableSorting` but it isn’t added to the database). any help would be appreciated.

```
$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);

```
