RandomSorting example

break;
            case self::TYPE_HIGHEST_PRICE:
                $criteria->addSorting(new PriceSorting(SortingInterface::SORT_DESC));
                break;
            case self::TYPE_TOPSELLER:
                $criteria->addSorting(new PopularitySorting(SortingInterface::SORT_DESC));
                break;
            case self::TYPE_NEWCOMER:
                $criteria->addSorting(new ReleaseDateSorting(SortingInterface::SORT_DESC));
                break;
            case self::TYPE_RANDOM:
                $criteria->addSorting(new RandomSorting());
                break;
        }

        return $criteria;
    }
}
$criteria = $this->criteriaFactory->createBaseCriteria([$categoryId]$context);
        $criteria->limit(1);

        switch ($type) {
            case self::TYPE_TOPSELLER:
                $criteria->addSorting(new PopularitySorting(SortingInterface::SORT_DESC));
                break;
            case self::TYPE_NEWCOMER:
                $criteria->addSorting(new ReleaseDateSorting(SortingInterface::SORT_DESC));
                break;
            case self::TYPE_RANDOM:
                $criteria->addSorting(new RandomSorting());
        }

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