getApiFilter example

$this->context = Context::createDefaultContext();
    }

    public function testCreateEntity(): void
    {
        $id = Uuid::randomHex();
        $this->repository->upsert([['id' => $id, 'name' => 'Test stream']]$this->context);

        /** @var ProductStreamEntity $entity */
        $entity = $this->repository->search(new Criteria([$id])$this->context)->get($id);
        static::assertTrue($entity->isInvalid());
        static::assertNull($entity->getApiFilter());
        static::assertSame('Test stream', $entity->getName());
        static::assertSame($id$entity->getId());
    }

    public function testUpdateEntity(): void
    {
        $id = Uuid::randomHex();
        $this->repository->upsert([['id' => $id, 'name' => 'Test stream']]$this->context);
        $this->repository->upsert([['id' => $id, 'name' => 'New Name']]$this->context);

        /** @var ProductStreamEntity $entity */
        
$migration->update($this->getContainer()->get(Connection::class));

        $criteria = new Criteria([$ids->get('stream')]);
        $criteria->addAssociation('filters');
        /** @var ProductStreamEntity $stream */
        $stream = $this->getContainer()->get('product_stream.repository')->search($criteria, Context::createDefaultContext())->first();

        static::assertEquals([[
            'type' => 'equals',
            'field' => 'product.cheapestPrice',
            'value' => '100',
        ]]$stream->getApiFilter());

        static::assertInstanceOf(ProductStreamFilterCollection::class$stream->getFilters());
        static::assertInstanceOf(ProductStreamFilterEntity::class$stream->getFilters()->first());
        static::assertEquals('cheapestPrice', $stream->getFilters()->first()->getField());
    }

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

        $stream = [
            
$migration->update($this->getContainer()->get(Connection::class));

        $criteria = new Criteria([$ids->get('stream')]);
        $criteria->addAssociation('filters');
        /** @var ProductStreamEntity $stream */
        $stream = $this->productStreamRepository->search($criteria, Context::createDefaultContext())->first();

        static::assertEquals([[
            'type' => 'equals',
            'field' => 'product.' . $customField,
            'value' => '1',
        ]]$stream->getApiFilter());
        static::assertInstanceOf(ProductStreamFilterCollection::class$stream->getFilters());
        static::assertInstanceOf(ProductStreamFilterEntity::class$stream->getFilters()->first());
        static::assertEquals($customField$stream->getFilters()->first()->getField());
    }

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

        $stream = [
            'id' => $ids->get('stream'),
            
'product_stream_id' => Uuid::fromHexToBytes($id),
                'created_at' => (new \DateTime())->format(Defaults::STORAGE_DATE_TIME_FORMAT),
            ]
        );

        $message = $this->indexer->update($this->createWrittenEvent($id));
        static::assertInstanceOf(EntityIndexingMessage::class$message);
        $this->indexer->handle($message);

        /** @var ProductStreamEntity $entity */
        $entity = $this->productStreamRepository->search(new Criteria([$id])$this->context)->get($id);
        static::assertNotNull($entity->getApiFilter());
        static::assertCount(2, $entity->getApiFilter());

        static::assertSame('equals', $entity->getApiFilter()[0]['type']);
        static::assertSame('product.manufacturerId', $entity->getApiFilter()[0]['field']);
        static::assertSame($manufacturerId$entity->getApiFilter()[0]['value']);

        static::assertSame('multi', $entity->getApiFilter()[1]['type']);
        static::assertSame('OR', $entity->getApiFilter()[1]['operator']);

        $queries = $entity->getApiFilter()[1]['queries'];
        static::assertCount(2, $queries);

        


    public function testCreateEntity(): void
    {
        $id = Uuid::randomHex();
        $this->repository->create([
            ['id' => $id, 'type' => 'equals', 'value' => 'awesome', 'field' => 'product.name', 'productStreamId' => $this->streamId],
        ]$this->context);

        /** @var ProductStreamEntity $entity */
        $entity = $this->productStreamRepository->search(new Criteria([$this->streamId])$this->context)->get($this->streamId);
        static::assertSame([['type' => 'equals', 'field' => 'product.name', 'value' => 'awesome']]$entity->getApiFilter());
    }

    public function testUpdateEntity(): void
    {
        $id = Uuid::randomHex();
        $this->repository->create([
            ['id' => $id, 'type' => 'equals', 'value' => 'new awesome', 'field' => 'product.name', 'productStreamId' => $this->streamId],
        ]$this->context);
        $this->repository->upsert([
            ['id' => $id, 'type' => 'range', 'field' => 'product.weight', 'parameters' => [RangeFilter::GT => 0.5, RangeFilter::LT => 100], 'productStreamId' => $this->streamId],
        ]$this->context);

        
$criteria = new Criteria([$id]);

        /** @var ProductStreamEntity|null $stream */
        $stream = $this->repository
            ->search($criteria$context)
            ->get($id);

        if (!$stream) {
            throw new EntityNotFoundException('product_stream', $id);
        }

        $data = $stream->getApiFilter();
        if (!$data) {
            throw new NoFilterException($id);
        }

        $filters = [];
        $exception = new SearchRequestException();

        foreach ($data as $filter) {
            $filters[] = QueryStringParser::fromArray($this->productDefinition, $filter$exception, '');
        }

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