setCustomFields example

/** * @param array<string, mixed> $config * @param array<string, mixed> $existsData * @param array<string, mixed> $expected * * @dataProvider actionExecutedProvider */
    public function testExecutedAction(array $config, array $existsData, array $expected): void
    {
        $customer = new CustomerEntity();
        $customer->setCustomFields($existsData);

        $context = Context::createDefaultContext();
        $customerId = Uuid::randomHex();
        $flow = new StorableFlow('', $context[][CustomerAware::CUSTOMER_ID => $customerId]);
        $flow->setConfig($config);

        $this->entitySearchResult->expects(static::once())
            ->method('first')
            ->willReturn($customer);

        $this->repository->expects(static::once())
            
/** * @param array<string, mixed> $config * @param array<string, mixed> $existsData * @param array<string, mixed> $expected * * @dataProvider actionExecutedProvider */
    public function testExecutedAction(array $config, array $existsData, array $expected): void
    {
        $customerGroup = new CustomerGroupEntity();
        $customerGroup->setCustomFields($existsData);

        $context = Context::createDefaultContext();
        $customerGroupId = Uuid::randomHex();
        $flow = new StorableFlow('', $context[][CustomerGroupAware::CUSTOMER_GROUP_ID => $customerGroupId]);
        $flow->setConfig($config);

        $this->entitySearchResult->expects(static::once())
            ->method('first')
            ->willReturn($customerGroup);

        $this->repository->expects(static::once())
            
private function buildCustomerEntity(string $id): CustomerEntity
    {
        $customerEntity = new CustomerEntity();
        $customerEntity->setId($id);
        $customerEntity->setEmail('test@example.org');
        $customerEntity->setFirstName('Max');
        $customerEntity->setLastName('Smith');
        $customerEntity->setTitle('Dr.');
        $customerEntity->setCompany('Acme Inc.');
        $customerEntity->setCustomerNumber('ABC123XY');
        $customerEntity->setRemoteAddress('Test street 123, NY');
        $customerEntity->setCustomFields(['customerGroup' => 'premium', 'origin' => 'newsletter', 'active' => true]);

        return $customerEntity;
    }
}
/** @var TextStruct|null $textStruct */
        $textStruct = $slot->getData();
        static::assertInstanceOf(TextStruct::class$textStruct);
        static::assertSame($product->getDescription()$textStruct->getContent());
    }

    public function testWithStaticContentAndMappedCustomFieldVariable(): void
    {
        $product = new ProductEntity();
        $product->setName('TextProduct');
        $product->setCustomFields(['testfield' => 'testing123']);

        $resolverContext = new EntityResolverContext($this->createMock(SalesChannelContext::class)new Request()$this->createMock(ProductDefinition::class)$product);
        $result = new ElementDataCollection();

        $fieldConfig = new FieldConfigCollection();
        $fieldConfig->add(new FieldConfig('content', FieldConfig::SOURCE_STATIC, '<h1>Title {{ product.customFields.testfield }}</h1>'));

        $slot = new CmsSlotEntity();
        $slot->setUniqueIdentifier('id');
        $slot->setType('text');
        $slot->setConfig([]);
        
static::assertArrayHasKey('name', $encoded['translated']);
        static::assertArrayNotHasKey('description', $encoded['translated']);
    }

    public function testStructWithCustomFields(): void
    {
        $struct = new StructWithCustomFields();
        $response = $this->encoder->encode($structnew ResponseFields(null));
        static::assertNull($response['customFields']);

        $struct = new StructWithCustomFields();
        $struct->setCustomFields([]);
        $response = $this->encoder->encode($structnew ResponseFields(null));
        static::assertInstanceOf(\stdClass::class$response['customFields']);

        $struct = new StructWithCustomFields();
        $struct->setCustomFields(['bla' => 'test']);
        $response = $this->encoder->encode($structnew ResponseFields(null));
        static::assertSame(['bla' => 'test']$response['customFields']);
    }

    public function testStructWithCustomFieldsInTranslated(): void
    {
        
/** * @param array<string, mixed> $config * @param array<string, mixed> $existsData * @param array<string, mixed> $expected * * @dataProvider actionExecutedProvider */
    public function testExecutedAction(array $config, array $existsData, array $expected): void
    {
        $order = new OrderEntity();
        $order->setCustomFields($existsData);

        $context = Context::createDefaultContext();
        $orderId = Uuid::randomHex();
        $flow = new StorableFlow('', $context[][OrderAware::ORDER_ID => $orderId]);
        $flow->setConfig($config);

        $this->entitySearchResult->expects(static::once())
            ->method('first')
            ->willReturn($order);

        $this->repository->expects(static::once())
            

class EntityCollectionTest extends TestCase
{
    public function testSetCustomFields(): void
    {
        $collection = new EntityCollection([
            new MyCollectionEntity('element-1', ['foo' => 1, 'bar' => 1]),
            new MyCollectionEntity('element-2', ['foo' => 2, 'bar' => 2]),
        ]);

        $collection->setCustomFields([
            'element-1' => ['foo' => 3, 'bar' => 3, 'baz' => 3],
            'element-2' => ['foo' => 4, 'bar' => 4],
            'not-exists' => ['foo' => 5],
        ]);

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

        // no exception should occur
'tokenize' => true,
                'ranking' => 100,
            ],
            [
                'field' => 'customFields',
                'tokenize' => true,
                'ranking' => 100,
            ],
        ];

        $product = new ProductEntity();
        $product->setCustomFields([
            'field1' => 'searchable',
            'field2' => 'match',
            'field3' => ['array'],
            'field4' => 10000000,
            'field5' => false,
            'field6' => 10.99999,
            'nestedField' => [
                'value' => 'nested',
                'second' => 'ignored',
            ],
            'ignored' => 'ignored',
        ]);
Home | Imprint | This part of the site doesn't use cookies.