ProductSortingCollection example

public static function unknownSortingProvider(): \Generator
    {
        yield 'Requested unknown sorting will throw exception' => ['unknown'];
        yield 'Requested empty sorting will throw exception' => [''];
        yield 'Requested null sorting will throw exception' => [null];
        yield 'Requested empty array sorting will throw exception' => [[]];
    }

    private function buildSortings(): ProductSortingCollection
    {
        return new ProductSortingCollection([
            (new ProductSortingEntity())->assign([
                '_uniqueIdentifier' => 'foo',
                'key' => 'foo',
                'fields' => [
                    ['field' => 'foo', 'priority' => 1, 'order' => 'DESC'],
                    ['field' => 'id', 'priority' => 2, 'order' => 'ASC'],
                ],
            ]),
            (new ProductSortingEntity())->assign([
                '_uniqueIdentifier' => 'bar',
                'key' => 'bar',
                

        throw new DecorationPatternException(self::class);
    }

    public function prepare(Request $request, Criteria $criteria, SalesChannelContext $context): void
    {
        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);
    }

    
Home | Imprint | This part of the site doesn't use cookies.