getFacet example

$customFacets = $this->facetService->getList($ids$context);
        } elseif ($this->isCategoryListing($request)) {
            $categoryId = (int) $request->getParam('sCategory');
            $customFacets = $this->facetService->getFacetsOfCategories([$categoryId]$context);
            /** @var CustomFacet[] $customFacets */
            $customFacets = array_shift($customFacets);
        } else {
            $customFacets = $this->facetService->getAllCategoryFacets($context);
        }

        foreach ($customFacets as $customFacet) {
            if (!$customFacet->getFacet()) {
                continue;
            }
            $facet = $customFacet->getFacet();
            $criteria->addFacet($facet);

            if ($facet instanceof ProductAttributeFacet) {
                $this->handleProductAttributeFacet($request$criteria$facet);
            } elseif ($facet instanceof CombinedConditionFacet) {
                $this->handleCombinedConditionFacet($request$criteria$facet);
            }
        }
    }
 {
        if (!isset($elasticResult['aggregations']['variant'])) {
            return;
        }

        $buckets = $elasticResult['aggregations']['variant']['buckets'];

        if (empty($buckets)) {
            return;
        }

        $facet = $criteria->getFacet('option');
        if (!$facet instanceof VariantFacet) {
            return;
        }

        $ids = array_column($buckets, 'key');
        $groups = $this->gateway->getOptions($ids$context);
        if (empty($groups)) {
            return;
        }

        $groups = array_filter($groupsfunction DGroup $group) use ($facet) {
            
$ids = $query->execute()->fetchAll(PDO::FETCH_COLUMN);
        $ids = array_filter($ids);

        if (empty($ids)) {
            return null;
        }

        $manufacturers = $this->manufacturerService->getList($ids$context);

        $activeManufacturers = $this->getActiveIds($criteria);

        return $this->getFacet($facet$manufacturers$activeManufacturers);
    }

    /** * @param Manufacturer[] $manufacturers * @param int[] $activeIds */
    private function getFacet(
        ManufacturerFacet $facet,
        array $manufacturers,
        array $activeIds
    ): ValueListFacetResult {
        
if (!isset($elasticResult['aggregations']) || !isset($elasticResult['aggregations']['category'])) {
            return;
        }

        $data = $elasticResult['aggregations']['category']['buckets'];
        $ids = array_column($data, 'key');

        if (empty($ids)) {
            return;
        }

        $categoryFacet = $criteria->getFacet('category');
        if (!$categoryFacet instanceof CategoryFacet) {
            return;
        }

        $ids = $this->filterSystemCategories($ids$context);
        $ids = $this->categoryDepthService->get(
            $context->getShop()->getCategory(),
            $categoryFacet->getDepth(),
            $ids
        );

        
public function supportsFacet(FacetInterface $facet)
    {
        return $facet instanceof VoteAverageFacet;
    }

    public function generatePartialFacet(
        FacetInterface $facet,
        Criteria $reverted,
        Criteria $criteria,
        ShopContextInterface $context
    ) {
        return $this->getFacet($facet$reverted$criteria$context);
    }

    private function getFacet(
        VoteAverageFacet $facet,
        Criteria $reverted,
        Criteria $criteria,
        ShopContextInterface $context
    ): ?RadioFacetResult {
        $query = $this->queryBuilderFactory->createQuery($reverted$context);
        $query->resetQueryPart('orderBy');
        $query->resetQueryPart('groupBy');

        


        $criteriaPart = $this->createFacet($criteria);

        $result->addFacet($criteriaPart);
    }

    private function createFacet(Criteria $criteria): BooleanFacetResult
    {
        $fieldName = $this->queryAliasMapper->getShortAlias('shippingFree') ?? 'shippingFree';

        $facet = $criteria->getFacet('shipping_free');
        if ($facet instanceof ShippingFreeFacet && !empty($facet->getLabel())) {
            $label = $facet->getLabel();
        } else {
            $label = $this->snippetManager
                ->getNamespace('frontend/listing/facet_labels')
                ->get('shipping_free', 'Shipping free');
        }

        return new BooleanFacetResult(
            'shipping_free',
            $fieldName,
            
public function supportsFacet(FacetInterface $facet)
    {
        return $facet instanceof ShippingFreeFacet;
    }

    public function generatePartialFacet(
        FacetInterface $facet,
        Criteria $reverted,
        Criteria $criteria,
        ShopContextInterface $context
    ) {
        return $this->getFacet($facet$reverted$criteria$context);
    }

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

        
public function supportsFacet(FacetInterface $facet)
    {
        return $facet instanceof ImmediateDeliveryFacet;
    }

    public function generatePartialFacet(
        FacetInterface $facet,
        Criteria $reverted,
        Criteria $criteria,
        ShopContextInterface $context
    ) {
        return $this->getFacet($facet$reverted$criteria$context);
    }

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

        
public function supportsFacet(FacetInterface $facet)
    {
        return $facet instanceof ProductAttributeFacet;
    }

    public function generatePartialFacet(
        FacetInterface $facet,
        Criteria $reverted,
        Criteria $criteria,
        ShopContextInterface $context
    ) {
        return $this->getFacet($facet$reverted$criteria$context);
    }

    /** * @return BooleanFacetResult|RadioFacetResult|RangeFacetResult|ValueListFacetResult|null */
    private function getFacet(
        ProductAttributeFacet $facet,
        Criteria $reverted,
        Criteria $criteria,
        ShopContextInterface $context
    ): ?FacetResultInterface {
        

        $context = $this->container->get(ContextServiceInterface::class)->getShopContext();

        $criteria = $this->container->get(CriteriaFactoryInterface::class)->createCriteria($this->Request()$context);

        $streamRepository = $this->container->get(Repository::class);
        $streamRepository->prepareCriteria($criteria$productStreamId);

        $facets = $this->container->get(CustomFacetServiceInterface::class)->getFacetsOfCategories([$categoryId]$context);
        $facets = $facets[$categoryId];
        foreach ($facets as $facet) {
            $customFacet = $facet->getFacet();
            if ($customFacet instanceof FacetInterface) {
                $criteria->addFacet($customFacet);
            }
        }

        $facetFilter = $this->container->get('shopware_product_stream.facet_filter');
        $facetFilter->add($criteria);

        $criteria->setGeneratePartialFacets(
            $this->container->get(Shopware_Components_Config::class)->get('listingMode') === 'filter_ajax_reload'
        );

        
$this->productStreamRepository->prepareCriteria($criteria$streamId);

        $facets = $this->customFacetService->getFacetsOfCategories([$categoryId]$context);

        $facets = array_shift($facets);

        if (!\is_array($facets)) {
            $facets = [];
        }

        foreach ($facets as $facet) {
            $customFacet = $facet->getFacet();

            if ($customFacet instanceof FacetInterface) {
                $criteria->addFacet($customFacet);
            }
        }

        $this->facetFilter->add($criteria);

        $criteria->removeFacet('category');

        return $criteria;
    }
continue;
            }

            if ($aggregation['doc_count'] <= 0) {
                continue;
            }

            if (!$criteria->hasFacet($key)) {
                continue;
            }

            $facet = $criteria->getFacet($key);
            if (!$facet instanceof CombinedConditionFacet) {
                continue;
            }

            $result->addFacet(
                new BooleanFacetResult(
                    $facet->getName(),
                    $facet->getRequestParameter(),
                    $criteria->hasCondition($facet->getName()),
                    $facet->getLabel()
                )
            );
public function supportsFacet(FacetInterface $facet)
    {
        return $facet instanceof CategoryFacet;
    }

    public function generatePartialFacet(
        FacetInterface $facet,
        Criteria $reverted,
        Criteria $criteria,
        ShopContextInterface $context
    ) {
        return $this->getFacet($facet$reverted$criteria$context);
    }

    private function getFacet(
        CategoryFacet $facet,
        Criteria $reverted,
        Criteria $criteria,
        ShopContextInterface $context
    ): ?TreeFacetResult {
        $ids = $this->fetchCategoriesOfProducts($reverted$context);

        if (empty($ids)) {
            
if ($data['value'] <= 0) {
            return;
        }

        $criteriaPart = $this->createFacet($criteria);

        $result->addFacet($criteriaPart);
    }

    private function createFacet(Criteria $criteria): BooleanFacetResult
    {
        $facet = $criteria->getFacet('immediate_delivery');
        if ($facet instanceof ImmediateDeliveryFacet && !empty($facet->getLabel())) {
            $label = $facet->getLabel();
        } else {
            $label = $this->snippetManager
                ->getNamespace('frontend/listing/facet_labels')
                ->get('immediate_delivery', 'Immediate delivery');
        }

        $fieldName = $this->queryAliasMapper->getShortAlias('immediateDelivery') ?? 'immediateDelivery';

        return new BooleanFacetResult(
            


    /** * {@inheritdoc} */
    public function generatePartialFacet(
        FacetInterface $facet,
        Criteria $reverted,
        Criteria $criteria,
        ShopContextInterface $context
    ) {
        return $this->getFacet($facet$reverted$criteria$context);
    }

    private function getFacet(
        CombinedConditionFacet $facet,
        Criteria $reverted,
        Criteria $criteria,
        ShopContextInterface $context
    ): ?BooleanFacetResult {
        $own = clone $reverted;

        if (!$criteria->hasCondition($facet->getName())) {
            
Home | Imprint | This part of the site doesn't use cookies.