ElasticsearchProductCustomFieldsMappingEvent example

/** @var array<string, string> $mappings */
        $mappings = $this->connection->fetchAllKeyValue(' SELECT custom_field.`name`, custom_field.type FROM custom_field_set_relation INNER JOIN custom_field ON(custom_field.set_id = custom_field_set_relation.set_id) WHERE custom_field_set_relation.entity_name = "product" ') + $this->customMapping;

        $event = new ElasticsearchProductCustomFieldsMappingEvent($mappings$context);
        $this->eventDispatcher->dispatch($event);

        $this->customFieldsTypes = $event->getMappings();

        return $this->customFieldsTypes;
    }

    /** * @param array<mixed> $items * * @return mixed|null */


    /** * @return array<string, string> */
    private function getCustomFieldTypes(Context $context): array
    {
        if ($this->customFieldsTypes !== null) {
            return $this->customFieldsTypes;
        }

        $event = new ElasticsearchProductCustomFieldsMappingEvent($this->customMapping, $context);
        $this->eventDispatcher->dispatch($event);

        $this->customFieldsTypes = $event->getMappings();

        return $this->customFieldsTypes;
    }
}
/** * @internal * * @covers \Shopware\Elasticsearch\Product\Event\ElasticsearchProductCustomFieldsMappingEvent */
class ElasticsearchProductCustomFieldsMappingEventTest extends TestCase
{
    public function testEvent(): void
    {
        $context = Context::createDefaultContext();
        $event = new ElasticsearchProductCustomFieldsMappingEvent(['field1' => 'text']$context);
        static::assertSame($context$event->getContext());

        static::assertSame('text', $event->getMapping('field1'));

        static::assertNull($event->getMapping('field2'));

        $event->setMapping('field2', 'text');

        static::assertSame('text', $event->getMapping('field2'));

        $event->removeMapping('field2');

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