setMaxResults example


    public function getUrls(Context $context$limit = null, $offset = null)
    {
        $qb = $this->getBaseQuery()
            ->addSelect(['DISTINCT details.articleID', 'details.ordernumber'])
            ->orderBy('details.articleID', 'ASC')
            ->setParameter(':shop', $context->getShopId());

        if ($limit !== null && $offset !== null) {
            $qb->setFirstResult($offset)
                ->setMaxResults($limit);
        }

        $result = $qb->execute()->fetchAll();

        if (!\count($result)) {
            return [];
        }

        return $this->router->generateList(
            array_map(
                function D$product) {
                    
$keyAccessor = 'LOWER(HEX(' . $keyAccessor . '))';
        }

        $query->addSelect(sprintf('%s as `%s`', $keyAccessor$key));

        $key = $aggregation->getName() . '.count';

        $countAccessor = $this->queryHelper->getFieldAccessor('id', $definition$definition->getEntityName()$context);
        $query->addSelect(sprintf('COUNT(%s) as `%s`', $countAccessor$key));

        if ($aggregation->getLimit()) {
            $query->setMaxResults($aggregation->getLimit());
        }

        if ($aggregation->getSorting()) {
            $this->addSorting($aggregation->getSorting()$definition$query$context);
        }

        if ($aggregation->getAggregation()) {
            $this->extendQuery($aggregation->getAggregation()$query$definition$context);
        }
    }

    
/** * {@inheritdoc} */
    public function getIterator()
    {
        $query = $this->entityManager->getConnection()->createQueryBuilder();
        $query->select(['customer.id', 'customer.id']);
        $query->from('s_user', 'customer');
        $query->andWhere('customer.id > :lastId');
        $query->setParameter(':lastId', 0);
        $query->addOrderBy('customer.id');
        $query->setMaxResults(50);

        return new LastIdQuery($query);
    }

    /** * {@inheritdoc} */
    public function getMapping()
    {
        return [
            'properties' => [
                

    public function getList($offset = 0, $limit = 25, array $criteria = [], array $orderBy = [])
    {
        $this->checkPrivilege('read');

        $builder = $this->getListQuery();

        $builder->addFilter($criteria);
        $builder->addOrderBy($orderBy);
        $builder->setFirstResult($offset)
                ->setMaxResults($limit);

        /** @var Query<CustomerModel|array<string, mixed>> $query */
        $query = $builder->getQuery();

        $query->setHydrationMode($this->getResultMode());

        $paginator = $this->getManager()->createPaginator($query);

        // Returns the total count of the query         $totalResult = $paginator->count();

        
ShippingFreeFacet $facet,
        Criteria $reverted,
        Criteria $criteria,
        ShopContextInterface $context
    ): ?BooleanFacetResult {
        $query = $this->queryBuilderFactory->createQuery($reverted$context);
        $query->resetQueryPart('orderBy');
        $query->resetQueryPart('groupBy');

        $query->select('product.id')
            ->andWhere('variant.shippingfree = 1')
            ->setMaxResults(1);

        $total = $query->execute()->fetch(PDO::FETCH_COLUMN);

        if ($total <= 0) {
            return null;
        }

        if (!empty($facet->getLabel())) {
            $label = $facet->getLabel();
        } else {
            $label = $this->snippetNamespace->get($facet->getName(), 'Shipping free');
        }

    public function getBackupListQuery($offset$limit)
    {
        $builder = $this->getBackupListQueryBuilder();

        if ($offset !== null) {
            $builder->setFirstResult($offset);
            $builder->setMaxResults($limit);
        }

        return $builder->getQuery();
    }

    /** * Helper function to create the query builder for the "getBackupListQuery" function. * This function can be hooked to modify the query builder of the query object. * * @return QueryBuilder */
    
public function __construct(Connection $connection)
    {
        $this->connection = $connection;
    }

    public function read(int $amount): array
    {
        return $this->connection->createQueryBuilder()
            ->select('*')
            ->from('s_es_backend_backlog', 'ba')
            ->setMaxResults($amount)
            ->execute()
            ->fetchAll();
    }

    /** * {@inheritdoc} */
    public function write(array $backlogs): void
    {
        foreach ($backlogs as $backlog) {
            $this->connection->insert('s_es_backend_backlog', $backlog->toArray());
        }
/* * Sorting by the cheapest available price */
            $cheapestPriceIdQuery->orderBy('(cheapestPrices.price * cheapestPrices.minpurchase)');
        } else {
            /* * Sorting by the cheapest unit price */
            $cheapestPriceIdQuery->orderBy('cheapestPrices.price');
        }

        $cheapestPriceIdQuery->setMaxResults(1);

        /* * Query to get the different price count */
        $countQuery->select('count(DISTINCT cheapestPrices.price)');
        $countQuery->from('s_articles_details', 'details');
        $countQuery->innerJoin('details', '(' . $countSubQuery->getSQL() . ')', 'cheapestPrices', $joinCondition);
        $countQuery->where('details.id = mainDetail.id');

        /* * Base query to get the cheapest price and different price count for each given variant */

    public function getListing(ListingRequest $context)
    {
        $query = $this->getQuery()
            ->andWhere("plugin.name != 'PluginManager'")
            ->andWhere('plugin.capability_enable = 1');

        $this->addSortings($context$query);

        $data = $query->setFirstResult($context->getOffset())
            ->setMaxResults($context->getLimit())
            ->execute()
            ->fetchAll(PDO::FETCH_ASSOC);

        $plugins = $this->iteratePlugins($data$context);

        return new ListingResultStruct($plugins, \count($plugins));
    }

    /** * @return PluginStruct|null */
    

    public function getPaymentStatusQuery($filter = null, $order = null, $offset = null, $limit = null)
    {
        $builder = $this->getPaymentStatusQueryBuilder($filter$order);
        if ($limit !== null) {
            $builder->setFirstResult($offset)
                ->setMaxResults($limit);
        }

        return $builder->getQuery();
    }

    /** * Helper method to create the query builder for the "getPaymentStatusQuery" function. * This function can be hooked to modify the query builder of the query object. * * @param array|null $filter * @param string|OrderBy $order * * @return QueryBuilder */
$qb->select('*');
        $qb->from('sales_channel_api_context');

        $qb->where('sales_channel_id = :salesChannelId');
        $qb->setParameter('salesChannelId', Uuid::fromHexToBytes($salesChannelId));

        if ($customerId !== null) {
            $qb->andWhere('(token = :token OR customer_id = :customerId)');
            $qb->setParameter('token', $token);
            $qb->setParameter('customerId', Uuid::fromHexToBytes($customerId));
            $qb->setMaxResults(2);
        } else {
            $qb->andWhere('token = :token');
            $qb->setParameter('token', $token);
            $qb->setMaxResults(1);
        }

        $data = $qb->executeQuery()->fetchAllAssociative();

        if (empty($data)) {
            return [];
        }

        
$graduation = 'prices.from = 1';
        if ($this->config->get('useLastGraduationForCheapestPrice')) {
            $graduation = "IF(priceGroup.id IS NOT NULL, prices.from = 1, prices.to = 'beliebig')";
        }

        $subQuery->where('prices.pricegroup = :customerGroup')
            ->andWhere($graduation)
            ->andWhere('variant.active = 1')
            ->andWhere('prices.articleID = outerPrices.articleID');

        $subQuery->setMaxResults(1);

        if ($this->config->get('calculateCheapestPriceWithMinPurchase')) {
            /* * Sorting by the cheapest available price */
            $subQuery->orderBy('(prices.price * variant.minpurchase)');
        } else {
            /* * Sorting by the cheapest unit price */
            $subQuery->orderBy('prices.price');
        }
$builder = $this->filterListQuery($builder$filter);
        if (\is_array($orderBy)) {
            $this->addOrderBy($builder$orderBy);
        }

        $builder->andWhere('documents.orderId = :orderId')
            ->setParameter('orderId', $orderId);

        if ($limit !== null) {
            $builder->setFirstResult($offset)
                    ->setMaxResults($limit);
        }

        return $builder->getQuery();
    }

    /** * Helper function which sets the fromPath and the selectPath for the order list query. * * @return QueryBuilder */
    protected function selectListQuery(QueryBuilder $builder)
    {
// Using distinct instead of groupBy is waaay faster - but will result in some pages having only one result             ->select("DISTINCT {$column}")
            ->from($entity$alias);
        // Limit to results matching the filter string         if ($queryConfig['filter']) {
            $builder->where("{$column} LIKE ?1")
                ->setParameter(1, '%' . $queryConfig['filter'] . '%');
        }
        // Ignore empty results; add pagination         $builder->andWhere("{$column} != ''")
            ->setFirstResult($queryConfig['offset'])
            ->setMaxResults($queryConfig['limit']);

        /** @var Query<array<string, mixed>> $query */
        $query = $builder->getQuery();

        $paginator = Shopware()->Models()->createPaginator($query);
        $totalCount = $paginator->count();
        $results = [];

        // Iterate results, do some formatting if needed         foreach ($paginator as $item) {
            $item = array_pop($item);
            
/** * {@inheritdoc} */
    public function getUrls(Context $context$limit = null, $offset = null)
    {
        $qb = $this->getBaseQuery()
            ->addSelect(['blog.id AS blogID', 'cat.id AS catID'])
            ->setParameter(':shop', $context->getShopId());

        if ($limit !== null && $offset !== null) {
            $qb->setFirstResult($offset)
                ->setMaxResults($limit);
        }

        $result = $qb->execute()->fetchAll();

        if (!\count($result)) {
            return [];
        }

        return $this->router->generateList(
            array_map(
                function D$blog) {
                    
Home | Imprint | This part of the site doesn't use cookies.