Product text import from agency XLSX workbooks
VITEC Import module: Products tab is now a searchable/sortable product overview. "Edit Product" opens an XLSX upload with per-field source mapping (component + cell), old/new preview and checkbox apply via DataHandler; the mapping and manual matches are persisted and preselect the next workbook. Category workbooks are detected and rejected. - new: ProductXlsxReader (PhpSpreadsheet), ProductTextImportController, Products/ProductTexts templates, 4 module routes - related products: per-pair card text in new side table tx_vitec_product_related_text (survives MM rewrites), emitted as `cardtext` in the product JSON; missing MM relations added add-only - card copy read from Body Copy (D) with fallback to CTA/Card Copy (E) - the workbooks fill either depending on row type - product detail page <title> now uses seotitle with title fallback (provider made singleton and fed from the JSON renderer) - per-user recent-search badges; last loaded workbook stored per product (tx_vitec_product_workbook), Edit Product reopens on it - composer: add phpoffice/phpspreadsheet ^5.9 - diagnostics: migrations/check_workbook.php
This commit is contained in:
@@ -22,8 +22,10 @@ use Evomedien\Vitec\UserFunc\CustomerlogosJsonRenderer;
|
||||
use Evomedien\Vitec\UserFunc\FormsJsonRenderer;
|
||||
use Evomedien\Vitec\UserFunc\ModelcardJsonRenderer;
|
||||
use Evomedien\Vitec\UserFunc\NewsJsonRenderer;
|
||||
use Evomedien\Vitec\UserFunc\ContainerBackgroundRenderer;
|
||||
use TYPO3\CMS\Core\Database\ConnectionPool;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
|
||||
|
||||
/**
|
||||
* Resolves a TYPO3 typolink string (as stored by `inputLink` fields like
|
||||
@@ -38,6 +40,12 @@ use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
* just like container children, so a referenced productlist / productshow /
|
||||
* usecaselist / usecaseshow appears with its full headless JSON in `data`.
|
||||
*
|
||||
* A linked CONTAINER (vitec_container, vitec_cols_*, vitec_cards_carousel)
|
||||
* additionally carries its resolved `background` and its children under
|
||||
* `items` - the exact shape ContainerChildrenProcessor emits for page-level
|
||||
* containers, so the frontend reuses its container component. Nested
|
||||
* containers recurse, depth-capped and cycle-safe.
|
||||
*
|
||||
* Exception-safe: every public entry point returns `null` on any failure
|
||||
* so the surrounding JSON output stays clean.
|
||||
*/
|
||||
@@ -71,6 +79,38 @@ final class ContentElementResolver
|
||||
|
||||
private const KEEP_IF_ZERO = ['header_layout'];
|
||||
|
||||
/**
|
||||
* Container-level fields - stripped from CHILD `data` like the page-level
|
||||
* ContainerChildrenProcessor does (they carry non-empty defaults and
|
||||
* belong to the parent). The linked container itself keeps them.
|
||||
*/
|
||||
private const CONTAINER_FIELDS = [
|
||||
'tx_vitec_gap',
|
||||
'tx_vitec_bg_variant', 'tx_vitec_bg_image', 'tx_vitec_bg_size',
|
||||
'tx_vitec_bg_size_percent', 'tx_vitec_bg_position',
|
||||
'tx_vitec_bg_pos_top', 'tx_vitec_bg_pos_bottom',
|
||||
'tx_vitec_bg_pos_left', 'tx_vitec_bg_pos_right',
|
||||
'tx_vitec_col1_align', 'tx_vitec_col1_justify',
|
||||
'tx_vitec_col2_align', 'tx_vitec_col2_justify',
|
||||
'tx_vitec_col3_align', 'tx_vitec_col3_justify',
|
||||
'tx_vitec_col4_align', 'tx_vitec_col4_justify',
|
||||
];
|
||||
|
||||
/**
|
||||
* Per container CType: colPos value => 1-based column number, for the
|
||||
* parent's tx_vitec_col{N}_align/justify - same map as the processor.
|
||||
*/
|
||||
private const COLPOS_TO_COLUMN = [
|
||||
'vitec_cols_50_50' => [211 => 1, 212 => 2],
|
||||
'vitec_cols_33_66' => [251 => 1, 252 => 2],
|
||||
'vitec_cols_66_33' => [241 => 1, 242 => 2],
|
||||
'vitec_cols_33_33_33' => [221 => 1, 222 => 2, 223 => 3],
|
||||
'vitec_cols_25_25_25_25' => [231 => 1, 232 => 2, 233 => 3, 234 => 4],
|
||||
];
|
||||
|
||||
/** Recursion cap for nested containers. */
|
||||
private const MAX_CONTAINER_DEPTH = 5;
|
||||
|
||||
private const PLUGIN_RENDERERS = [
|
||||
'vitec_productlist' => [ProductListJsonRenderer::class, 'products'],
|
||||
'vitec_productshow' => [ProductShowJsonRenderer::class, 'product'],
|
||||
@@ -143,7 +183,10 @@ final class ContentElementResolver
|
||||
return null;
|
||||
}
|
||||
|
||||
return self::normaliseRecord($row);
|
||||
$element = self::normaliseRecord($row);
|
||||
self::attachContainerPayload($row, $element, [$uid => true], 0);
|
||||
|
||||
return $element;
|
||||
} catch (\Throwable $e) {
|
||||
return null;
|
||||
}
|
||||
@@ -156,9 +199,12 @@ final class ContentElementResolver
|
||||
* resolved to their headless JSON.
|
||||
*
|
||||
* @param array<string,mixed> $record
|
||||
* @param bool $isContainerChild strip container-level fields (bg, gap,
|
||||
* col flex) like the page-level processor
|
||||
* does for its children
|
||||
* @return array<string,mixed>
|
||||
*/
|
||||
public static function normaliseRecord(array $record): array
|
||||
public static function normaliseRecord(array $record, bool $isContainerChild = false): array
|
||||
{
|
||||
$data = [];
|
||||
foreach ($record as $field => $value) {
|
||||
@@ -168,6 +214,9 @@ final class ContentElementResolver
|
||||
if (in_array($field, self::SYSTEM_FIELDS, true)) {
|
||||
continue;
|
||||
}
|
||||
if ($isContainerChild && in_array($field, self::CONTAINER_FIELDS, true)) {
|
||||
continue;
|
||||
}
|
||||
if (self::isEmpty($value) && !in_array($field, self::KEEP_IF_ZERO, true)) {
|
||||
continue;
|
||||
}
|
||||
@@ -279,6 +328,107 @@ final class ContentElementResolver
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* If the element has container children (tx_container_parent), attach the
|
||||
* resolved `background` and the children as `items` in the page-level
|
||||
* shape: [{config: {colPos, align?, justify?}, contentElements: [...]}].
|
||||
* Recurses into nested containers; $visited guards against cycles.
|
||||
*
|
||||
* @param array<string,mixed> $record raw tt_content row
|
||||
* @param array<string,mixed> $element normalised element, modified in place
|
||||
* @param array<int,bool> $visited uids already on this path
|
||||
*/
|
||||
private static function attachContainerPayload(array $record, array &$element, array $visited, int $depth): void
|
||||
{
|
||||
$background = self::resolveContainerBackground($record);
|
||||
if ($background !== null) {
|
||||
$element['background'] = $background;
|
||||
}
|
||||
|
||||
if ($depth >= self::MAX_CONTAINER_DEPTH) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$qb = GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
->getQueryBuilderForTable('tt_content');
|
||||
$rows = $qb
|
||||
->select('*')
|
||||
->from('tt_content')
|
||||
->where(
|
||||
$qb->expr()->eq('tx_container_parent', $qb->createNamedParameter((int)$record['uid'], ParameterType::INTEGER)),
|
||||
$qb->expr()->eq('pid', $qb->createNamedParameter((int)($record['pid'] ?? 0), ParameterType::INTEGER)),
|
||||
$qb->expr()->eq('sys_language_uid', $qb->createNamedParameter((int)($record['sys_language_uid'] ?? 0), ParameterType::INTEGER))
|
||||
)
|
||||
->orderBy('colPos')
|
||||
->addOrderBy('sorting')
|
||||
->executeQuery()
|
||||
->fetchAllAssociative();
|
||||
} catch (\Throwable $e) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($rows === []) {
|
||||
return;
|
||||
}
|
||||
|
||||
$byColPos = [];
|
||||
foreach ($rows as $childRow) {
|
||||
$childUid = (int)$childRow['uid'];
|
||||
$child = self::normaliseRecord($childRow, true);
|
||||
if (!isset($visited[$childUid])) {
|
||||
$childVisited = $visited;
|
||||
$childVisited[$childUid] = true;
|
||||
self::attachContainerPayload($childRow, $child, $childVisited, $depth + 1);
|
||||
}
|
||||
$byColPos[(int)$childRow['colPos']][] = $child;
|
||||
}
|
||||
ksort($byColPos);
|
||||
|
||||
$colMap = self::COLPOS_TO_COLUMN[(string)($record['CType'] ?? '')] ?? [];
|
||||
$items = [];
|
||||
foreach ($byColPos as $colPos => $contentElements) {
|
||||
$config = ['colPos' => $colPos];
|
||||
$columnNo = $colMap[$colPos] ?? null;
|
||||
if ($columnNo !== null) {
|
||||
$config['align'] = (string)($record['tx_vitec_col' . $columnNo . '_align'] ?? 'stretch');
|
||||
$config['justify'] = (string)($record['tx_vitec_col' . $columnNo . '_justify'] ?? 'flex-start');
|
||||
}
|
||||
$items[] = [
|
||||
'config' => $config,
|
||||
'contentElements' => $contentElements,
|
||||
];
|
||||
}
|
||||
|
||||
$element['items'] = $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolved {image, size, position} of a container row - the same payload
|
||||
* ContainerBackgroundRenderer emits in the page JSON. Null without image.
|
||||
*
|
||||
* @param array<string,mixed> $record
|
||||
* @return array<string,mixed>|null
|
||||
*/
|
||||
private static function resolveContainerBackground(array $record): ?array
|
||||
{
|
||||
try {
|
||||
$cObj = GeneralUtility::makeInstance(ContentObjectRenderer::class);
|
||||
$cObj->start($record, 'tt_content');
|
||||
$renderer = GeneralUtility::makeInstance(ContainerBackgroundRenderer::class);
|
||||
$renderer->setContentObjectRenderer($cObj);
|
||||
$json = $renderer->render('', []);
|
||||
if ($json === '') {
|
||||
return null;
|
||||
}
|
||||
$decoded = json_decode($json, true);
|
||||
|
||||
return is_array($decoded) ? $decoded : null;
|
||||
} catch (\Throwable $e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static function isEmpty(mixed $value): bool
|
||||
{
|
||||
return $value === null || $value === '' || $value === 0 || $value === '0';
|
||||
|
||||
Reference in New Issue
Block a user