From e162e9fca4a0c2b27d6f88e5df08b2f1ff55df5a Mon Sep 17 00:00:00 2001 From: vienthuong Date: Tue, 25 Aug 2026 17:13:54 +0700 Subject: [PATCH 1/2] docs(storefront): use ProductListingCollectSortingEvent for runtime sortings --- .../add-custom-sorting-product-listing.md | 22 ++++++++----------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/guides/plugins/plugins/storefront/howto/add-custom-sorting-product-listing.md b/guides/plugins/plugins/storefront/howto/add-custom-sorting-product-listing.md index 9c7ce3713e..c31bab1b27 100644 --- a/guides/plugins/plugins/storefront/howto/add-custom-sorting-product-listing.md +++ b/guides/plugins/plugins/storefront/howto/add-custom-sorting-product-listing.md @@ -91,7 +91,11 @@ class Migration1615470599ExampleSorting extends MigrationStep ## Create individual sorting at runtime -You can subscribe to the `ProductListingCriteriaEvent` to add a `ProductSortingEntity` as available sorting on the fly. If you don't know how to do this, head over to our [Listening to events](../../framework/event/listening-to-events.md) guide. +You can subscribe to the `ProductListingCollectSortingEvent` to add a `ProductSortingEntity` as an available sorting on the fly. If you don't know how to do this, head over to our [Listening to events](../../framework/event/listening-to-events.md) guide. + +::: info +This event is available since Shopware 6.7.15.0. +::: ::: info While possible, it is not recommended adding an individual sorting at runtime. If you just wish for your individual sorting to be not editable by users in the Administration, create a migration and set the parameter `locked` to be `true`. @@ -105,8 +109,7 @@ Here's an example how your subscriber could look like: namespace Swag\BasicExample\Subscriber; -use Shopware\Core\Content\Product\Events\ProductListingCriteriaEvent; -use Shopware\Core\Content\Product\SalesChannel\Sorting\ProductSortingCollection; +use Shopware\Core\Content\Product\Events\ProductListingCollectSortingEvent; use Shopware\Core\Content\Product\SalesChannel\Sorting\ProductSortingEntity; use Shopware\Core\Framework\Uuid\Uuid; use Symfony\Component\EventDispatcher\EventSubscriberInterface; @@ -117,17 +120,12 @@ class ExampleListingSubscriber implements EventSubscriberInterface public static function getSubscribedEvents(): array { return [ - // be sure to subscribe with high priority to add you sorting before the default shopware logic applies - // otherwise storefront will throw a ProductSortingNotFoundException - ProductListingCriteriaEvent::class => ['addMyCustomSortingToStorefront', 500], + ProductListingCollectSortingEvent::class => 'addMyCustomSortingToStorefront', ]; } - public function addMyCustomSortingToStorefront(ProductListingCriteriaEvent $event): void + public function addMyCustomSortingToStorefront(ProductListingCollectSortingEvent $event): void { - /** @var ProductSortingCollection $availableSortings */ - $availableSortings = $event->getCriteria()->getExtension('sortings') ?? new ProductSortingCollection(); - $myCustomSorting = new ProductSortingEntity(); $myCustomSorting->setId(Uuid::randomHex()); $myCustomSorting->setActive(true); @@ -143,9 +141,7 @@ class ExampleListingSubscriber implements EventSubscriberInterface ], ]); - $availableSortings->add($myCustomSorting); - - $event->getCriteria()->addExtension('sortings', $availableSortings); + $event->getSortings()->add($myCustomSorting); } } ``` From c4678bb8676df31a12fdb7ebc3ce79ef8850c03a Mon Sep 17 00:00:00 2001 From: Micha Hobert Date: Fri, 28 Aug 2026 16:55:56 +0200 Subject: [PATCH 2/2] adjust/grammar-punctuation --- .../storefront/howto/add-custom-sorting-product-listing.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/guides/plugins/plugins/storefront/howto/add-custom-sorting-product-listing.md b/guides/plugins/plugins/storefront/howto/add-custom-sorting-product-listing.md index c31bab1b27..f8497ff215 100644 --- a/guides/plugins/plugins/storefront/howto/add-custom-sorting-product-listing.md +++ b/guides/plugins/plugins/storefront/howto/add-custom-sorting-product-listing.md @@ -101,7 +101,7 @@ This event is available since Shopware 6.7.15.0. While possible, it is not recommended adding an individual sorting at runtime. If you just wish for your individual sorting to be not editable by users in the Administration, create a migration and set the parameter `locked` to be `true`. ::: -Here's an example how your subscriber could look like: +Here's an example of what your subscriber could look like: ```php // /src/Subscriber/ExampleListingSubscriber.php @@ -148,4 +148,4 @@ class ExampleListingSubscriber implements EventSubscriberInterface ## Next steps -To [add a custom filter](./add-listing-filters.md) to your listing in the Storefront head over to the corresponding guide. +To [add a custom filter](./add-listing-filters.md) to your listing in the Storefront, head over to the corresponding guide.