fetchAllKeyValue example

'host' => 'localhost',
            'schema' => 'https',
            'basePath' => '/shop',
            'blueGreenDeployment' => true,
        ]$connection);

        // assert that system language was updated         static::assertSame('Deutsch', $connection->fetchOne('SELECT `name` from `language` WHERE `id` = ?', [Uuid::fromHexToBytes(Defaults::LANGUAGE_SYSTEM)]));
        // assert that default currency was updated         static::assertSame('USD', $connection->fetchOne('SELECT `iso_code` from `currency` WHERE `id` = ?', [Uuid::fromHexToBytes(Defaults::CURRENCY)]));

        $currencies = $connection->fetchAllKeyValue('SELECT `id`, `iso_code` from `currency`');
        // assert that not configured currencies are deleted         static::assertEqualsCanonicalizing(['USD', 'EUR', 'CHF']array_values($currencies));

        // assert that sales channel was created         $id = $connection->fetchOne('SELECT `sales_channel_id` FROM `sales_channel_translation` WHERE `name` = ?', ['test-shop']);
        static::assertIsString($id);

        $salesChannel = $connection->fetchAssociative('SELECT * FROM `sales_channel` WHERE `id` = ?', [$id]);
        static::assertIsArray($salesChannel);
        static::assertSame(Uuid::fromHexToBytes(Defaults::CURRENCY)$salesChannel['currency_id']);
        static::assertSame(Uuid::fromHexToBytes(Defaults::LANGUAGE_SYSTEM)$salesChannel['language_id']);

        
#[Package('core')] class FlowEventPersister
{
    public function __construct(
        private readonly EntityRepository $flowEventsRepository,
        private readonly Connection $connection
    ) {
    }

    public function updateEvents(Event $flowEvent, string $appId, Context $context, string $defaultLocale): void
    {
        $existingFlowEvents = $this->connection->fetchAllKeyValue('SELECT name, LOWER(HEX(id)) FROM app_flow_event WHERE app_id = :appId;', [
            'appId' => Uuid::fromHexToBytes($appId),
        ]);

        $flowEvents = $flowEvent->getCustomEvents()?->getCustomEvents() ?? [];
        $upserts = [];
        foreach ($flowEvents as $event) {
            $payload = array_merge([
                'appId' => $appId,
            ]$event->toArray($defaultLocale));

            $existing = $existingFlowEvents[$event->getName()] ?? null;
            

        $this->connection = $this->getContainer()->get(Connection::class);
        $this->keyValueStorage = new MySQLKeyValueStorage($this->connection);
    }

    public function testSet(): void
    {
        $this->keyValueStorage->set('key-1', 'value-1');
        $this->keyValueStorage->set('key-2', null);
        $this->keyValueStorage->set('key-3', ['a' => 'b']);

        $value = $this->connection->fetchAllKeyValue('SELECT `key`, `value` FROM `app_config` WHERE `key` IN (:keys) ORDER BY `key` ASC', [
            'keys' => ['key-1', 'key-2', 'key-3'],
        ][
            'keys' => ArrayParameterType::STRING,
        ]);

        static::assertEquals([
            'key-1' => 'value-1',
            'key-2' => '',
            'key-3' => json_encode(['a' => 'b']),
        ]$value);
    }

    
if (isset($this->ids[$name])) {
            return $this->ids[$name];
        }

        $this->ids = $this->load();

        return $this->ids[$name];
    }

    private function load(): array
    {
        return $this->cache->get(self::CACHE_KEY, fn () => $this->connection->fetchAllKeyValue(
            'SELECT technical_name, LOWER(HEX(`initial_state_id`)) as initial_state_id FROM state_machine'
        ));
    }
}

    public function resolve(array $map): array
    {
        $numbers = \array_map(fn ($id) => $id->value, $map);

        $numbers = \array_filter(\array_unique($numbers));

        if (empty($numbers)) {
            return $map;
        }

        $hash = $this->connection->fetchAllKeyValue(
            'SELECT product_number, LOWER(HEX(id)) FROM product WHERE product_number IN (:numbers) AND version_id = :version',
            ['numbers' => $numbers, 'version' => Uuid::fromHexToBytes(Defaults::LIVE_VERSION)],
            ['numbers' => ArrayParameterType::STRING]
        );

        foreach ($map as $reference) {
            $reference->resolved = $hash[$reference->value];
        }

        return $map;
    }
}
static::assertNull($customer->getVatIds());
        static::assertEquals($changeData['company']$customer->getCompany());
        static::assertEquals($changeData['firstName']$customer->getFirstName());
        static::assertEquals($changeData['lastName']$customer->getLastName());
    }

    public function testChangeProfileWithExistingNotSpecifiedSalutation(): void
    {
        $connection = KernelLifecycleManager::getConnection();

        $salutations = $connection->fetchAllKeyValue('SELECT salutation_key, id FROM salutation');
        static::assertArrayHasKey(SalutationDefinition::NOT_SPECIFIED, $salutations);

        $this->browser
            ->request(
                'POST',
                '/store-api/account/change-profile',
                [
                    'firstName' => 'Max',
                    'lastName' => 'Mustermann',
                ]
            );

        
->build(),
            (new ProductBuilder($ids, 'p2'))
                ->price(100)
                ->build(),
        ];

        $this->getContainer()->get('product.repository')->create($products, Context::createDefaultContext());

        $criteria = new Criteria($ids->getList(['p1', 'p2']));
        $result = $this->getContainer()->get('product.repository')->searchIds($criteria, Context::createDefaultContext());

        $increments = $this->getContainer()->get(Connection::class)->fetchAllKeyValue(
            'SELECT LOWER(HEX(id)) as id, auto_increment FROM product WHERE id IN (:ids)',
            ['ids' => $ids->getByteList(['p1', 'p2'])],
            ['ids' => ArrayParameterType::STRING]
        );

        $data = $result->getData();
        static::assertArrayHasKey($ids->get('p1')$data);
        static::assertArrayHasKey('productNumber', $data[$ids->get('p1')]);
        static::assertArrayHasKey('autoIncrement', $data[$ids->get('p1')]);

        static::assertArrayHasKey($ids->get('p2')$data);
        
continue;
            }

            $changes[$id] = $lineItem->getDataTimestamp()->format(Defaults::STORAGE_DATE_TIME_FORMAT);
        }

        if (empty($changes)) {
            return $ids;
        }

        $updates = $this->connection->fetchAllKeyValue(
            'SELECT LOWER(HEX(id)) as id, updated_at FROM product WHERE id IN (:ids) AND version_id = :liveVersionId',
            [
                'ids' => Uuid::fromHexToBytesList(array_keys($changes)),
                'liveVersionId' => Uuid::fromHexToBytes(Defaults::LIVE_VERSION),
            ],
            [
                'ids' => ArrayParameterType::STRING,
            ]
        );

        foreach ($changes as $id => $timestamp) {
            
$countryId = $connection->fetchOne('SELECT id FROM country WHERE iso = :iso AND iso3 = :iso3', ['iso' => 'VA', 'iso3' => 'VAT']);
        if ($countryId === false) {
            return;
        }

        $sql = 'SELECT locale.code, country_translation.name FROM country_translation LEFT JOIN country ON country.id = country_translation.country_id LEFT JOIN language ON language.id = country_translation.language_id LEFT JOIN locale ON locale.id = language.locale_id WHERE country.iso = :iso AND country.iso3 = :iso3';

        $currentTranslations = $connection->fetchAllKeyValue($sql['iso' => 'VA', 'iso3' => 'VAT']);
        if (empty($currentTranslations)) {
            return;
        }

        $replacements = [];
        if (($currentTranslations['en-GB'] ?? null) === 'Holy See') {
            $replacements['en-GB'] = 'Vatican City';
        }
        if (($currentTranslations['de-DE'] ?? null) === 'Heiliger Stuhl') {
            $replacements['de-DE'] = 'Staat Vatikanstadt';
        }
        
protected function assertMailSent(MailEventListener $listener, string $type): void
    {
        static::assertTrue($listener->sent($type), \sprintf('Mail with type %s was not sent', $type));
    }

    /** * @return mixed */
    protected function mailListener(\Closure $closure)
    {
        $mapping = $this->getContainer()->get(Connection::class)
            ->fetchAllKeyValue('SELECT LOWER(HEX(id)), technical_name FROM mail_template_type');

        $listener = new MailEventListener($mapping);

        $dispatcher = $this->getContainer()->get('event_dispatcher');

        $dispatcher->addListener(FlowSendMailActionEvent::class$listener);

        $result = $closure($listener);

        $dispatcher->removeListener(FlowSendMailActionEvent::class$listener);

        


    /** * @return array<string> */
    private function getCustomFields(): array
    {
        if ($this->customFields !== null) {
            return $this->customFields;
        }

        $this->customFields = $this->connection->fetchAllKeyValue('SELECT `name`, `type` FROM `custom_field` WHERE `active` = 1');

        return $this->customFields;
    }
}
public function getEntityDefinition(): EntityDefinition
    {
        return $this->definition;
    }

    /** * {@inheritdoc} */
    public function getMapping(Context $context): array
    {
        $languages = $this->connection->fetchAllKeyValue(
            'SELECT LOWER(HEX(language.`id`)) as id, locale.code FROM language INNER JOIN locale ON locale_id = locale.id'
        );

        $languageFields = [];
        $customFieldsProperties = [];

        foreach ($languages as $languageId => $code) {
            $parts = explode('-', $code);
            $locale = $parts[0];

            
$query
                ->andWhere('sales_channel_id IS NULL');
        } else {
            $query->andWhere('sales_channel_id = :salesChannelId OR system_config.sales_channel_id IS NULL');
            $query->setParameter('salesChannelId', Uuid::fromHexToBytes($salesChannelId));
        }

        $query->addOrderBy('sales_channel_id', 'ASC');

        $result = $query->executeQuery();

        return $this->buildSystemConfigArray($result->fetchAllKeyValue());
    }

    private function buildSystemConfigArray(array $systemConfigs): array
    {
        $configValues = [];

        foreach ($systemConfigs as $key => $value) {
            $keys = \explode('.', (string) $key);

            if ($value !== null) {
                $value = \json_decode((string) $value, true, 512, \JSON_THROW_ON_ERROR);

                

            [
                'salesChannelId' => Uuid::fromHexToBytes($salesChannelId),
                'languageId' => Uuid::fromHexToBytes($languageId),
            ]
        );

        if ($snippetSetId) {
            return $snippetSetId;
        }

        $sets = $this->connection->fetchAllKeyValue(
            'SELECT iso, LOWER(HEX(id)) FROM snippet_set WHERE iso IN (:locales) LIMIT 2',
            ['locales' => array_unique([$locale, 'en-GB'])],
            ['locales' => ArrayParameterType::STRING]
        );

        if (isset($sets[$locale])) {
            return $sets[$locale];
        }

        return array_pop($sets);
    }

    


    /** * @param array<string, array{gross:float, net:float, linked?:bool, currencyId?:string}> $prices * * @return array<string, array{gross:float, net:float, linked?:bool, currencyId?:string}> */
    private function resolveIsoCodes(array $prices): array
    {
        if (empty($this->currencies)) {
            /** @var array<string, string> $currencies */
            $currencies = $this->connection->fetchAllKeyValue('SELECT iso_code, LOWER(HEX(id)) FROM currency');
            $this->currencies = $currencies;
        }

        $mapped = [];
        foreach ($prices as $iso => $value) {
            if ($iso === 'default') {
                $mapped[Defaults::CURRENCY] = $value;

                continue;
            }

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