getFacets example



        $products = $this->listingLinkRewriteService->rewriteLinks($criteria$products$context);

        $pageSizes = explode('|', $this->config->get('numberArticlesToShow'));
        $pageSizes = array_map('\intval', $pageSizes);
        $sPage = (int) $request->getParam('sPage', 1);

        return [
            'sArticles' => $products,
            'criteria' => $criteria,
            'facets' => $searchResult->getFacets(),
            'sPage' => $sPage,
            'pageIndex' => $sPage,
            'pageSizes' => $pageSizes,
            'sPerPage' => $criteria->getLimit(),
            'sNumberArticles' => $searchResult->getTotalCount(),
            'shortParameters' => $this->queryAliasMapper->getQueryAliases(),
            'sTemplate' => $request->getParam('sTemplate') ? (string) $request->getParam('sTemplate') : null,
            'sSort' => (int) $request->getParam('sSort', $this->config->get('defaultListingSorting')),
        ];
    }

    
$service = Shopware()->Container()->get(CustomSortingServiceInterface::class);

        $sortingIds = $this->container->get(Shopware_Components_Config::class)->get('searchSortings');
        $sortingIds = array_filter(explode('|', $sortingIds));
        $sortingIds = array_map('\intval', $sortingIds);
        $sortings = $service->getList($sortingIds$context);

        $this->View()->assign([
            'term' => $term,
            'criteria' => $criteria,
            'facets' => $result->getFacets(),
            'sPage' => $this->Request()->getParam('sPage', 1),
            'sSort' => $this->Request()->getParam('sSort', 7),
            'sTemplate' => $this->Request()->getParam('sTemplate'),
            'sPerPage' => array_values(explode('|', $pageCounts)),
            'sRequests' => $request,
            'shortParameters' => $mapper->getQueryAliases(),
            'pageSizes' => array_values(explode('|', $pageCounts)),
            'ajaxCountUrlParams' => [],
            'sortings' => $sortings,
            'sSearchResults' => [
                'sArticles' => $products,
                
'MIN(allVariants.width) as minWidth',
            'MAX(allVariants.width) as maxWidth',
            'MIN(allVariants.length) as minLength',
            'MAX(allVariants.length) as maxLength',
        ]);

        $query->setMaxResults(1);

        $stats = $query->execute()->fetch(PDO::FETCH_ASSOC);

        $results = [];
        foreach ($criteria->getFacets() as $criteriaFacet) {
            if (!$criteriaFacet instanceof WeightFacet
                && !$criteriaFacet instanceof WidthFacet
                && !$criteriaFacet instanceof LengthFacet
                && !$criteriaFacet instanceof HeightFacet
            ) {
                continue;
            }
            $facetResult = $this->createRangeFacet($criteriaFacet$stats$criteria);
            if ($facetResult === null) {
                continue;
            }

            
$facets,
            $result->getAttributes()
        );
    }

    private function buildSearch(Criteria $criteria, ShopContextInterface $context): EsSearch
    {
        $search = new EsSearch();

        $this->addConditions($criteria$context$search);
        $this->addCriteriaParts($criteria$context$search$criteria->getSortings());
        $this->addCriteriaParts($criteria$context$search$criteria->getFacets());

        if ($criteria->getOffset() !== null) {
            $search->setFrom($criteria->getOffset());
        }
        if ($criteria->getLimit() !== null) {
            $search->setSize($criteria->getLimit());
        }

        $search->addSort(new FieldSort('id', 'asc'));

        return $search;
    }

        return $query->getConnection()->fetchColumn('SELECT FOUND_ROWS()');
    }

    /** * @throws Exception * * @return SearchBundle\FacetResultInterface[] */
    private function createFacets(SearchBundle\Criteria $criteria, ShopContextInterface $context)
    {
        if (\count($criteria->getFacets()) === 0) {
            return [];
        }

        $facets = [];

        $clone = clone $criteria;

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

        
ShopContextInterface $context
    ) {
        $numberResult = $this->searchGateway->search($criteria$context);

        $numbers = array_keys($numberResult->getProducts());
        $products = $this->productService->getList($numbers$context);
        $products = $this->assignAttributes($products$numberResult->getProducts());

        $result = new ProductSearchResult(
            $products,
            $numberResult->getTotalCount(),
            $numberResult->getFacets(),
            $criteria,
            $context
        );

        $result->addAttributes($numberResult->getAttributes());

        return $result;
    }

    /** * @param ListProduct[] $products * @param BaseProduct[] $searchProducts * * @return ListProduct[] */
return array_map('\intval', $query->execute()->fetchFirstColumn());
    }

    private function setSearchResultResponse(ProductSearchResult $result): void
    {
        $body = [
            'totalCount' => $result->getTotalCount(),
        ];

        if ($this->Request()->getParam('loadFacets')) {
            $body['facets'] = array_values($result->getFacets());
            $body['listing'] = false;
            $body['pagination'] = false;
        }
        if ($this->Request()->getParam('loadProducts')) {
            $this->prepareListing($result);
            $body['listing'] = true;
            $this->preparePagination($result);
            $body['pagination'] = true;
        }
        $this->View()->assign($body);

        
public function hydrate(
        array $elasticResult,
        ProductNumberSearchResult $result,
        Criteria $criteria,
        ShopContextInterface $context
    ) {
        if (!isset($elasticResult['aggregations'])) {
            return;
        }

        foreach ($criteria->getFacets() as $criteriaFacet) {
            if (!$criteriaFacet instanceof WeightFacet
                && !$criteriaFacet instanceof WidthFacet
                && !$criteriaFacet instanceof LengthFacet
                && !$criteriaFacet instanceof HeightFacet
            ) {
                continue;
            }

            if (!\array_key_exists($criteriaFacet->getName()$elasticResult['aggregations'])) {
                continue;
            }

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