getBaseConfig example


        }

        return $parentThemes;
    }

    /** * @return array<string, mixed> */
    private function getConfigInheritance(ThemeEntity $mainTheme): array
    {
        if (\is_array($mainTheme->getBaseConfig())
            && \array_key_exists('configInheritance', $mainTheme->getBaseConfig())
            && \is_array($mainTheme->getBaseConfig()['configInheritance'])
            && !empty($mainTheme->getBaseConfig()['configInheritance'])
        ) {
            return $mainTheme->getBaseConfig()['configInheritance'];
        }

        return [];
    }

    /** * @return array<string, mixed> */
$id = Uuid::randomHex();
        $this->themeRepository->create(
            [
                [
                    'id' => $id,
                    'parentThemeId' => $parentTheme->getId(),
                    'name' => $name,
                    'technicalName' => $name,
                    'createdAt' => (new \DateTimeImmutable())->format(Defaults::STORAGE_DATE_TIME_FORMAT),
                    'configValues' => $parentTheme->getConfigValues(),
                    'baseConfig' => array_merge($parentTheme->getBaseConfig() ?? []$config->getThemeConfig() ?? []),
                    'description' => $parentTheme->getDescription(),
                    'author' => $parentTheme->getAuthor(),
                    'labels' => $parentTheme->getLabels(),
                    'customFields' => $parentTheme->getCustomFields(),
                    'previewMediaId' => $parentTheme->getPreviewMediaId(),
                    'active' => true,
                    'salesChannels' => [],
                ],
            ],
            $this->context
        );

        
$configuredTheme = [];

        $pluginConfig = null;
        if ($theme->getTechnicalName()) {
            $pluginConfig = $this->extensionRegistry->getConfigurations()->getByTechnicalName($theme->getTechnicalName());
        }

        if ($pluginConfig !== null) {
            $configuredTheme = $pluginConfig->getThemeConfig() ?? [];
        }

        if ($theme->getBaseConfig() !== null) {
            $configuredTheme = array_replace_recursive($configuredTheme$theme->getBaseConfig());
        }

        if ($theme->getConfigValues() === null) {
            return $configuredTheme;
        }

        foreach ($theme->getConfigValues() as $fieldName => $configValue) {
            if (isset($configValue['value'])) {
                $configuredTheme['fields'][$fieldName]['value'] = $configValue['value'];
            }
        }
$this->documentConfigLoader = $this->getContainer()->get(DocumentConfigLoader::class);
    }

    protected function tearDown(): void
    {
        $this->documentConfigLoader->reset();
    }

    public function testLoadGlobalConfig(): void
    {
        $base = $this->getBaseConfig('invoice');
        $globalConfig = $base === null ? [] : $base->getConfig();
        $globalConfig['companyName'] = 'Test corp.';
        $globalConfig['displayCompanyAddress'] = true;
        $this->upsertBaseConfig($globalConfig, 'invoice');

        $salesChannelId = $this->salesChannelContext->getSalesChannel()->getId();
        $config = $this->documentConfigLoader->load('invoice', $salesChannelId$this->context);

        $config = $config->jsonSerialize();

        static::assertEquals('Test corp.', $config['companyName']);
        
$filePath = $urlGenerator->getRelativeMediaUrl($document->getDocumentMediaFile());

        $fileSystem->write($filePath, 'test123');

        static::assertTrue($fileSystem->has($filePath));

        $this->documentGenerator->readDocument($document->getId()$this->context, 'wrong code');
    }

    public function testConfigurationWithSalesChannelOverride(): void
    {
        $base = $this->getBaseConfig(InvoiceRenderer::TYPE);
        $globalConfig = $base instanceof DocumentBaseConfigEntity ? $base->getConfig() : [];
        $globalConfig['companyName'] = 'Test corp.';
        $globalConfig['displayCompanyAddress'] = true;
        $this->upsertBaseConfig($globalConfig, InvoiceRenderer::TYPE);

        $salesChannelConfig = [
            'companyName' => 'Custom corp.',
            'displayCompanyAddress' => false,
        ];
        $this->upsertBaseConfig($salesChannelConfig, InvoiceRenderer::TYPE, $this->salesChannelContext->getSalesChannel()->getId());

        
$operation = new DocumentGenerateOperation($orderId, FileTypes::PDF, $config);
        $operations[$orderId] = $operation;

        return $this->getContainer()->get(DocumentGenerator::class)->generate($documentType$operations$context)->getSuccess();
    }

    /** * @param array<string|bool, string|bool|int> $config */
    private function upsertBaseConfig(array $config, string $documentType, ?string $salesChannelId = null): void
    {
        $baseConfig = $this->getBaseConfig($documentType$salesChannelId);

        /** @var EntityRepository $documentTypeRepository */
        $documentTypeRepository = $this->getContainer()->get('document_type.repository');
        $documentTypeId = $documentTypeRepository->searchIds(
            (new Criteria())->addFilter(new EqualsFilter('technicalName', $documentType)),
            Context::createDefaultContext()
        )->firstId();

        if ($baseConfig === null) {
            $documentConfigId = Uuid::randomHex();
        } else {
            
$media[$path] = $mediaItem;
            }
        }

        $baseConfig = $pluginConfiguration->getThemeConfig() ?? [];
        $installedBaseConfig = $installedConfiguration?->getThemeConfig() ?? [];

        $currentThemeMedia = null;
        $currentMediaIds = null;
        $toDeleteIds = null;
        // get existing MediaFiles         if ($theme !== null && \array_key_exists('fields', $theme->getBaseConfig() ?? [])) {
            foreach ($theme->getBaseConfig()['fields'] as $key => $field) {
                if ($this->hasOldMedia($field) === false) {
                    continue;
                }
                $currentMediaIds[$key] = $field['value'];
            }

            if (!empty($currentMediaIds)) {
                $currentThemeMedia = $this->mediaRepository->search(new Criteria($currentMediaIds)$context);
            }
        }

        
$config->set('Cache.SerializerPermissions', 0775 & ~umask());

        return $config;
    }

    /** * @param array<string, array<string>> $options */
    private function getConfig(array $options, bool $override, ?string $field): \HTMLPurifier_Config
    {
        $config = $this->getBaseConfig();

        $allowedElements = [];
        $allowedAttributes = [];
        $customAttributes = [];

        foreach ($options as $element => $attributes) {
            if ($element !== '*') {
                $allowedElements[] = $element;
            }

            foreach ($attributes as $attr) {
                
Home | Imprint | This part of the site doesn't use cookies.