getDataOfId example

$result = $this->getContainer()->get('product.repository')
            ->searchIds($criteria$context);

        $exception = null;

        try {
            $result->getScore($ids->get('john'));
        } catch (\Exception $exception) {
        }
        static::assertInstanceOf(\RuntimeException::class$exception);

        static::assertEquals([]$result->getDataOfId('not-exists'));
        static::assertSame($context$result->getContext());
        static::assertEquals($criteria$result->getCriteria());
    }

    public function testDataProperty(): void
    {
        $ids = new IdsCollection();

        $products = [
            (new ProductBuilder($ids, 'p1'))
                ->price(100)
                


            // current id was mapped to another variant             if (!$entities->has($mapping[$id])) {
                continue;
            }

            /** @var Entity $entity */
            $entity = $entities->get($mapping[$id]);

            // get access to the data of the search result             $entity->addExtension('search', new ArrayEntity($ids->getDataOfId($id)));
        }
    }
}
public function getDataOfId(string $id): array
    {
        if (!\array_key_exists($id$this->data)) {
            return [];
        }

        return $this->data[$id];
    }

    public function getDataFieldOfId(string $id, string $field): mixed
    {
        $data = $this->getDataOfId($id);

        if (\array_key_exists($field$data)) {
            return $data[$field];
        }

        return null;
    }

    public function getScore(string $id): float
    {
        $score = $this->getDataFieldOfId($id, '_score');

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