I am trying to create a sorting without using the Database Migration. I tried doing it as described in the documentation but I get the error that the “custom-sorting” couldn’t be found. I tried using the AbstractListingProcessor
instead the subscriber but it didn’t work as well.
Here is a snippet of my code:
class CustomSortingProcessor extends AbstractListingProcessor
{
public function getDecorated() : AbstractListingProcessor
{
throw new DecorationPatternException(self::class);
}
public function prepare(Request $request, Criteria $criteria, SalesChannelContext
$context): void
/** @var ProductSortingCollection $availableSortings */
$availableSorting = $criteria->getExtension('sortings') ?? new
ProductSortingCollection();
$customSortingProcessorEntity = new ProductSortingEntity();
$customSortingProcessorEntity ->setId(Uuid::randomHex());
$customSortingProcessorEntity ->setActive(true);
$customSortingProcessorEntity ->setTranslated(['label' => 'Custom Sorting']);
$customSortingProcessorEntity ->setKey('custom-sorting-by');
$customSortingProcessorEntity ->setPriority(5);
$customSortingProcessorEntity ->setFields([
[
'field' => 'deepLearning.sold',
'order' => 'desc',
'priority' => 1,
'naturalSorting' => 0,
],
]);
$availableSorting->add($customSortingProcessorEntity);
$criteria->addExtension('sortings', $availableSorting);
}
}