getFilteredValues example

'rest_total_hits_as_int' => true,
            'track_total_hits' => true,
        ];

        $data = $this->client->search(
            $arguments
        );

        $data = $data['hits']['hits'];

        $properties = $this->hydrateProperties($data$ids);
        $actives = $this->getFilteredValues($criteria);
        $criteriaPart = $this->createCollectionResult($properties$actives);
        $result->addFacet($criteriaPart);
    }

    /** * @param array[] $data * @param int[] $optionIds * * @return Group[] */
    private function hydrateProperties(array $data, array $optionIds): array
    {
$ids = array_column($buckets, 'key');
        $groups = $this->gateway->getOptions($ids$context);
        if (empty($groups)) {
            return;
        }

        $groups = array_filter($groupsfunction DGroup $group) use ($facet) {
            return \in_array($group->getId()$facet->getGroupIds(), true);
        });

        $actives = $this->getFilteredValues($criteria);
        $facet = $this->createCollectionResult($facet$groups$actives);
        $result->addFacet($facet);
    }

    /** * @param Group[] $groups * @param int[] $actives */
    private function createCollectionResult(
        VariantFacet $facet,
        array $groups,
        
$filters = array_shift($filters);

        if (\count($properties) <= 0) {
            static::assertNull($filters);

            return;
        }

        static::assertInstanceOf(MultiFilter::class$filters);
        static::assertCount(\count($properties)$filters->getQueries()$message);

        $filtered = $this->getFilteredValues($filters->getQueries());

        static::assertNotEmpty($filtered$message);

        foreach ($properties as $ids) {
            foreach ($ids as $id) {
                static::assertContains($id$filtered$message);
            }
        }
    }

    /** * @param Filter[] $filters * * @return array<mixed> */
public function generatePartialFacet(
        FacetInterface $facet,
        Criteria $reverted,
        Criteria $criteria,
        ShopContextInterface $context
    ) {
        $options = $this->getOptions($context$reverted$facet);

        if ($options === null) {
            return null;
        }
        $actives = $this->getFilteredValues($criteria);

        return $this->createCollectionResult($facet$options$actives);
    }

    /** * @deprecated - Will be private with Shopware 5.8 * * @return Group[]|null */
    protected function getOptions(ShopContextInterface $context, Criteria $queryCriteria, VariantFacet $facet)
    {
        
public function generatePartialFacet(
        FacetInterface $facet,
        Criteria $reverted,
        Criteria $criteria,
        ShopContextInterface $context
    ) {
        $properties = $this->getProperties($context$reverted);

        if ($properties === null) {
            return null;
        }
        $actives = $this->getFilteredValues($criteria);

        return $this->createCollectionResult($facet$properties$actives);
    }

    /** * @deprecated - Will be private with Shopware 5.8 * * @return array<int, Set>|null */
    protected function getProperties(ShopContextInterface $context, Criteria $queryCriteria)
    {
        
Home | Imprint | This part of the site doesn't use cookies.