addRandomSort example

// Ensure storefront presentation settings of product variants         $criteria->addGroupField(new FieldGrouping('displayGroup'));
        $criteria->addFilter(
            new NotFilter(
                NotFilter::CONNECTION_AND,
                [new EqualsFilter('displayGroup', null)]
            )
        );

        if ($sorting === 'random') {
            return $this->addRandomSort($criteria);
        }

        if ($sorting) {
            $sorting = explode(':', $sorting);
            $field = $sorting[0];
            $direction = $sorting[1];

            $criteria->addSorting(new FieldSorting($field$direction));
        }

        return $criteria;
    }
Home | Imprint | This part of the site doesn't use cookies.