# Custom sorting ohne NULL zu berücksichtigen

**URL:** <https://forum.shopware.com/t/custom-sorting-ohne-null-zu-berucksichtigen/72640>\
**Category:** Programmierung\
**Created:** [9. Februar 2021 um 10:10 UTC](https://forum.shopware.com/t/custom-sorting-ohne-null-zu-berucksichtigen/72640 "2021-02-09T10:10:52Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![pino](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/pino/32/14373_2.png) [@pino](https://forum.shopware.com/u/pino)\
**Post date:** [9. Februar 2021 um 10:10 UTC](https://forum.shopware.com/t/custom-sorting-ohne-null-zu-berucksichtigen/72640/1 "2021-02-09T10:10:52Z")

</div>

Tach zusammen,

es ist ja möglich zu seinen eigenen Entities eine Sortierung für das Listing anzuhängen:  
[Shopware 6: Extending the storefront listing](https://docs.shopware.com/en/shopware-platform-dev-en/how-to/extend-storefront-listing#create-custom-sorting-options)

Das funktioniert eigentlich.  
Nur haben einige Product eben keinen Wert für das angehängt&nbsp;Entity und haben somit einen NULL Wert.

```
product.myentity.value

```

Das Ergebnis der Sortierung ist nun folgender:

DESC  
4, 2, 3, 2, 1, NULL, NULL, NULL.

ASC  
NULL, NULL, NULL, 1, 2, 3, 4

Ziel bei ASC muss sein:  
1, 2, 3, 4, NULL, NULL, NULL

Wie erreicht ich das?

So sieht mein Eintrag jetzt in die DB (product\_sorting) aus:

```
[
    'id' => Uuid::randomBytes(),
    'url_key' => 'myentity-asc',
    'priority' => 0,
    'active' => 1,
    'locked' => 0,
    'fields' => json_encode([
        [
            'field' => 'product.myentity.value',
            'order' => 'asc',
            'priority' => 1,
            'naturalSorting' => 0
        ],
    ]),
    'created_at' => (new \DateTime())->format(Defaults::STORAGE_DATE_TIME_FORMAT),
]

```

&nbsp;
