ArrayEntity example

$route->prepareCriteria($criteria$salesChannel);
        static::assertTrue($criteria->hasEqualsFilter('active'));

        static::assertTrue($criteria->hasEqualsFilter('visibilities.salesChannelId'));
    }

    public function testMappingWithInvalidEntity(): void
    {
        $route = new ProductPageSeoUrlRoute($this->createMock(ProductDefinition::class));

        static::expectException(\InvalidArgumentException::class);
        $route->getMapping(new ArrayEntity()new SalesChannelEntity());
    }

    public function testMapping(): void
    {
        $route = new ProductPageSeoUrlRoute($this->createMock(ProductDefinition::class));

        $product = new ProductEntity();
        $product->setId('test');
        $data = $route->getMapping($productnew SalesChannelEntity());

        static::assertNull($data->getError());
        


        static::assertEquals([
            'element-1' => ['foo' => 3, 'bar' => 3, 'baz' => 3],
            'element-2' => ['foo' => 4, 'bar' => 4],
        ]$collection->getCustomFieldsValues());

        // no exception should occur         (new EntityCollection())->setCustomFields([]);

        $collection = new EntityCollection([
            new ArrayEntity(['id' => 'element-1', 'foo' => 1, 'bar' => 1]),
        ]);

        static::expectException(\RuntimeException::class);
        $collection->setCustomFields([
            'element-1' => ['foo' => 3, 'bar' => 3, 'baz' => 3],
        ]);
    }

    public function testGetCustomFieldsValue(): void
    {
        // no exception should occur
$route->prepareCriteria($criteria$salesChannel);
        static::assertTrue($criteria->hasEqualsFilter('active'));

        static::assertTrue($criteria->hasEqualsFilter('visibilities.salesChannelId'));
    }

    public function testMappingWithInvalidEntity(): void
    {
        $route = new ProductPageSeoUrlRoute($this->createMock(ProductDefinition::class));

        static::expectException(\InvalidArgumentException::class);
        $route->getMapping(new ArrayEntity()new SalesChannelEntity());
    }

    public function testMapping(): void
    {
        $route = new ProductPageSeoUrlRoute($this->createMock(ProductDefinition::class));

        $product = new ProductEntity();
        $product->setId('test');
        $data = $route->getMapping($productnew SalesChannelEntity());

        static::assertNull($data->getError());
        


        $product = new ProductEntity();
        $product->internalSetEntityData('product', new FieldVisibility([]));

        $manufacturer = (new ProductManufacturerEntity())->assign(['name' => 'foo']);
        $product->addExtension('exposedExtension', $manufacturer);
        $product->addExtension('notExposedExtension', $manufacturer);
        $product->setName('test');

        $product->addExtension('foreignKeys', new ArrayStruct(['exposedFk' => 'exposed', 'notExposedFk' => 'not_exposed'], 'product'));
        $product->addExtension('search', new ArrayEntity(['score' => 2000]));

        $serializer = new Serializer([new StructNormalizer()][new JsonEncoder()]);

        $encoded = (new StructEncoder($this->getChainRegistry($registry)$serializer))->encode($productnew ResponseFields(null));

        static::assertArrayHasKey('extensions', $encoded);
        static::assertArrayHasKey('exposedExtension', $encoded['extensions']);
        static::assertArrayHasKey('search', $encoded['extensions']);
        static::assertArrayNotHasKey('notExposedExtension', $encoded['extensions']);
        static::assertArrayHasKey('foreignKeys', $encoded['extensions']);

        
static::assertNotNull($mappingCollection->getMapped('bar'));
        static::assertNotNull($mappingCollection->getMapped('zxcv'));

        static::assertSame($mappingFoo$mappingCollection->getMapped('bar'));
        static::assertSame($mappingAsdf$mappingCollection->getMapped('zxcv'));
    }

    public function testInvalidElement(): void
    {
        $this->expectException(\InvalidArgumentException::class);
        /** @phpstan-ignore-next-line intentionally wrong parameter provided */
        new MappingCollection([new ArrayEntity()]);
    }

    public function testFromIterableMappingCollection(): void
    {
        $mappingFoo = new Mapping('foo', 'bar');
        $mappingAsdf = new Mapping('asdf', 'zxcv');
        $mappingCollection = new MappingCollection([$mappingFoo$mappingAsdf]);

        static::assertSame($mappingCollection, MappingCollection::fromIterable($mappingCollection));
    }

    
/** * @internal */
class EntitySearchResultTest extends TestCase
{
    /** * @dataProvider resultPageCriteriaDataProvider */
    public function testResultPage(Criteria $criteria, int $page): void
    {
        $entity = new ArrayEntity(['id' => Uuid::randomHex()]);
        $entityCollection = new EntityCollection([$entity]);
        $result = new EntitySearchResult(
            ArrayEntity::class,
            100,
            $entityCollection,
            null,
            $criteria,
            Context::createDefaultContext()
        );

        static::assertSame($page$result->getPage());
    }
if (!\array_key_exists($element->getUniqueIdentifier()$search)) {
                continue;
            }

            $data = $search[$element->getUniqueIdentifier()];
            unset($data['id']);

            if (empty($data)) {
                continue;
            }

            $element->addExtension('search', new ArrayEntity($data));
        }

        $result = new EntitySearchResult($this->definition->getEntityName()$ids->getTotal()$entities$aggregations$criteria$context);
        $result->addState(...$ids->getStates());

        $event = new EntitySearchResultLoadedEvent($this->definition, $result);
        $this->eventDispatcher->dispatch($event$event->getName());

        return $result;
    }
}
use Shopware\Core\Framework\DataAbstractionLayer\Entity;
use Shopware\Core\Framework\DataAbstractionLayer\EntityCollection;
use Shopware\Core\Framework\Struct\ArrayEntity;

/** * @internal */
class TestBasicWithExtension extends SerializationFixture
{
    public function getInput(): EntityCollection|Entity
    {
        $extendable = new ArrayEntity([
            'id' => '1d23c1b015bf43fb97e89008cf42d6fe',
            'createdAt' => new \DateTime('2018-01-15T08:01:16.000+00:00'),
        ]);

        $extendable->addExtension('toOne', new ArrayEntity([
            'id' => '6f51622eb3814c75ae0263cece27ce72',
            'name' => 'toOne',
        ]));

        $extendable->addExtension('toOneWithoutApiAware', new ArrayEntity([
            'id' => '6f51622eb3814c75ae0263cece27ce72',
            


        if (isset($data['quantity'])) {
            $lineItem->setQuantity((int) $data['quantity']);
        }

        if (isset($data['priceDefinition']) && !$context->hasPermission(ProductCartProcessor::ALLOW_PRODUCT_PRICE_OVERWRITES)) {
            throw CartException::insufficientPermission();
        }

        if (isset($data['priceDefinition'])) {
            $lineItem->addExtension(ProductCartProcessor::CUSTOM_PRICE, new ArrayEntity());
            $lineItem->setPriceDefinition($this->priceDefinitionFactory->factory($context->getContext()$data['priceDefinition']$data['type']));
        }
    }
}
$criteriaCollection = $this->flattenCriteriaCollections($criteriaCollections);

        foreach ($criteriaCollection as $definition => $criteriaObjects) {
            $directReads[$definition] = [[]];
            $searches[$definition] = [];

            foreach ($criteriaObjects as $criteria) {
                if ($this->canBeMerged($criteria)) {
                    $directReads[$definition][] = $criteria->getIds();
                } else {
                    $criteriaHash = $this->hash($criteria);
                    $criteria->addExtension('criteriaHash', new ArrayEntity(['hash' => $criteriaHash]));
                    $searches[$definition][$criteriaHash] = $criteria;
                }
            }
        }

        foreach ($directReads as $definition => $idLists) {
            /** @var array<string, array<string>> $directReads */
            $directReads[$definition] = array_merge(...$idLists);
        }

        return [
            
use Shopware\Core\Framework\DataAbstractionLayer\Entity;
use Shopware\Core\Framework\DataAbstractionLayer\EntityCollection;
use Shopware\Core\Framework\Struct\ArrayEntity;

/** * @internal */
class TestBasicWithToManyExtension extends SerializationFixture
{
    public function getInput(): EntityCollection|Entity
    {
        $extendable = new ArrayEntity([
            'id' => '1d23c1b015bf43fb97e89008cf42d6fe',
            'createdAt' => new \DateTime('2018-01-15T08:01:16.000+00:00'),
        ]);

        $collection = new EntityCollection([
            new ArrayEntity([
                'id' => '548faa1f7846436c85944f4aea792d96',
                'name' => 'toMany#1',
            ]),
        ]);

        

    public function sync(array $operations, Context $context, SyncBehavior $behavior): SyncResult
    {
        ReplicaConnection::ensurePrimary();

        $context = clone $context;

        $this->loopOperations($operations$context);

        if (\count($behavior->getSkipIndexers())) {
            $context->addExtension(EntityIndexerRegistry::EXTENSION_INDEXER_SKIP, new ArrayEntity(['skips' => $behavior->getSkipIndexers()]));
        }

        if (
            $behavior->getIndexingBehavior() !== null
            && \in_array($behavior->getIndexingBehavior()[EntityIndexerRegistry::DISABLE_INDEXING, EntityIndexerRegistry::USE_INDEXING_QUEUE], true)
        ) {
            $context->addState($behavior->getIndexingBehavior());
        }

        $result = $this->writer->sync($operations, WriteContext::createFromContext($context));

        


            // 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)));
        }
    }
}

                ->build(),
            (new ProductBuilder($ids, 'product-2'))
                ->price(1.0)
                ->build(),
            (new ProductBuilder($ids, 'product-3'))
                ->price(1.0)
                ->build(),
        ];

        $context = Context::createDefaultContext();
        $context->addExtension(EntityIndexerRegistry::EXTENSION_INDEXER_SKIP, new ArrayEntity(['skips' => [ProductIndexer::STATES_UPDATER]]));

        $this->productRepository->create($products$context);

        $this->connection->executeStatement(
            'UPDATE `product` SET `states` = :states WHERE `id` IN (:ids)',
            [
                'states' => json_encode([State::IS_PHYSICAL]),
                'ids' => Uuid::fromHexToBytesList([$ids->get('product-1')$ids->get('product-2')]),
            ],
            ['ids' => ArrayParameterType::STRING]
        );
    }
if (!\array_key_exists($element->getUniqueIdentifier()$search)) {
                continue;
            }

            $data = $search[$element->getUniqueIdentifier()];
            unset($data['id']);

            if (empty($data)) {
                continue;
            }

            $element->addExtension('search', new ArrayEntity($data));
        }

        $result = new EntitySearchResult($this->definition->getEntityName()$ids->getTotal()$entities$aggregations$criteria$salesChannelContext->getContext());
        $result->addState(...$ids->getStates());

        $event = new EntitySearchResultLoadedEvent($this->definition, $result);
        $this->eventDispatcher->dispatch($event$event->getName());

        $event = new SalesChannelEntitySearchResultLoadedEvent($this->definition, $result$salesChannelContext);
        $this->eventDispatcher->dispatch($event$event->getName());

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