resetSorting example



    public function enrich(EnrichExportCriteriaEvent $event): void
    {
        /** @var ImportExportProfileEntity $profile */
        $profile = $event->getLogEntity()->getProfile();
        if ($profile->getSourceEntity() !== ProductDefinition::ENTITY_NAME) {
            return;
        }

        $criteria = $event->getCriteria();
        $criteria->resetSorting();

        $criteria->addSorting(new FieldSorting('autoIncrement'));

        $config = Config::fromLog($event->getLogEntity());

        if ($config->get('includeVariants') !== true) {
            $criteria->addFilter(new EqualsFilter('parentId', null));
        }
    }
}
private readonly CriteriaQueryBuilder $criteriaQueryBuilder,
        private readonly LoggerInterface $logger,
        private readonly CriteriaFieldsResolver $criteriaFieldsResolver
    ) {
    }

    /** * @return EntityCollection<Entity> */
    public function read(EntityDefinition $definition, Criteria $criteria, Context $context): EntityCollection
    {
        $criteria->resetSorting();
        $criteria->resetQueries();

        /** @var EntityCollection<Entity> $collectionClass */
        $collectionClass = $definition->getCollectionClass();

        $fields = $this->criteriaFieldsResolver->resolve($criteria$definition);

        return $this->_read(
            $criteria,
            $definition,
            $context,
            
$criteria = $this->createCriteriaFromRequest($request$context);

        $this->eventManager->notify('Shopware_SearchBundle_Create_Ajax_Count_Criteria', [
            'criteria' => $criteria,
            'request' => $request,
            'context' => $context,
        ]);

        $criteria
            ->offset(0)
            ->limit(1)
            ->resetSorting()
            ->resetFacets();

        return $criteria;
    }

    /** * @param int $categoryId * * @return \Shopware\Bundle\SearchBundle\Criteria */
    public function createProductNavigationCriteria(
        

        if (\count($criteria->getFacets()) === 0) {
            return [];
        }

        $facets = [];

        $clone = clone $criteria;

        if (!$criteria->generatePartialFacets()) {
            $clone->resetConditions();
            $clone->resetSorting();
        }

        foreach ($criteria->getFacets() as $facet) {
            $handler = $this->getFacetHandler($facet);

            if ($criteria->generatePartialFacets() && !$handler instanceof PartialFacetHandlerInterface) {
                throw new RuntimeException(sprintf("New filter mode activated, handler class %s doesn't support this mode", \get_class($handler)));
            }

            if ($handler instanceof PartialFacetHandlerInterface) {
                $result = $handler->generatePartialFacet($facet$clone$criteria$context);
            }
$criteria->resetAggregations();
        }

        if ($request->get('only-aggregations')) {
            // set limit to zero to fetch no products.             $criteria->setLimit(0);

            // no total count required             $criteria->setTotalCountMode(Criteria::TOTAL_COUNT_MODE_NONE);

            // sorting and association are only required for the product data             $criteria->resetSorting();
            $criteria->resetAssociations();
        }
    }
}


        $checkRedirect = ($hasEmotion && $this->Request()->getParam('sPage')) || (!$hasEmotion);

        if (!$checkRedirect || !$this->config->get('categoryDetailLink')) {
            return null;
        }

        $criteria = $this->storeFrontCriteriaFactory->createListingCriteria($this->Request()$context);
        $criteria->resetFacets()
            ->resetConditions()
            ->resetSorting()
            ->offset(0)
            ->limit(2)
            ->setFetchCount(false);
        $result = $this->productNumberSearch->search($criteria$context);
        if (\count($result->getProducts()) !== 1) {
            return null;
        }

        $products = $result->getProducts();
        $firstProducts = array_shift($products);

        

    }

    private function fetchAggregation(
        Aggregation $aggregation,
        EntityDefinition $definition,
        Criteria $criteria,
        Context $context
    ): AggregationResult {
        $clone = clone $criteria;
        $clone->resetAggregations();
        $clone->resetSorting();
        $clone->resetPostFilters();
        $clone->resetGroupFields();

        // Early resolve terms to extract score queries         if ($clone->getTerm()) {
            $pattern = $this->interpreter->interpret((string) $criteria->getTerm());
            $queries = $this->scoreBuilder->buildScoreQueries($pattern$definition$definition->getEntityName()$context);
            $clone->addQuery(...$queries);
            $clone->setTerm(null);
        }

        


    public function enrich(EnrichExportCriteriaEvent $event): void
    {
        /** @var ImportExportProfileEntity $profile */
        $profile = $event->getLogEntity()->getProfile();
        if ($profile->getSourceEntity() !== CategoryDefinition::ENTITY_NAME) {
            return;
        }

        $criteria = $event->getCriteria();
        $criteria->resetSorting();

        $criteria->addSorting(new FieldSorting('level'));
        $criteria->addSorting(new FieldSorting('id'));
    }
}
Home | Imprint | This part of the site doesn't use cookies.