createDalSorting example

if (!$request->get('order')) {
            $request->request->set('order', $this->getSystemDefaultSorting($context));
        }

        /** @var ProductSortingCollection $sortings */
        $sortings = $criteria->getExtension('sortings') ?? new ProductSortingCollection();
        $sortings->merge($this->getAvailableSortings($request$context->getContext()));

        $currentSorting = $this->getCurrentSorting($sortings$request);

        $criteria->addSorting(
            ...$currentSorting->createDalSorting()
        );

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

    public function process(Request $request, ProductListingResult $result, SalesChannelContext $context): void
    {
        /** @var ProductSortingCollection $sortings */
        $sortings = $result->getCriteria()->getExtension('sortings');
        $currentSortingKey = $this->getCurrentSorting($sortings$request)->getKey();

        
public function testProductSortingFieldPriority(): void
    {
        $productSortingEntity = new ProductSortingEntity();
        $productSortingEntity->setFields(
            [
                ['field' => 'product.name', 'order' => 'asc', 'priority' => 1, 'naturalSorting' => 1],
                ['field' => 'product.cheapestPrice', 'order' => 'asc', 'priority' => 1000, 'naturalSorting' => 1],
            ]
        );

        /** @var FieldSorting[] $sortings */
        $sortings = $productSortingEntity->createDalSorting();

        static::assertCount(2, $sortings);
        static::assertEquals('product.cheapestPrice', $sortings[0]->getField());
        static::assertEquals('product.name', $sortings[1]->getField());
    }

    public function testDuplicateProductSortingKey(): void
    {
        $productSortingKey = Uuid::randomHex();

        $data = [
            
Home | Imprint | This part of the site doesn't use cookies.