
Product ' . $slug . '
$10.00
diff --git a/php-transformer/src/WordPressSitePlan/SitePlanRun.php b/php-transformer/src/WordPressSitePlan/SitePlanRun.php index 372831aec..415264e32 100644 --- a/php-transformer/src/WordPressSitePlan/SitePlanRun.php +++ b/php-transformer/src/WordPressSitePlan/SitePlanRun.php @@ -367,6 +367,7 @@ public function plan(): array $runtimeDeclarations = $shellDeclarations; $this->timer?->start('compose.site_plan.templates'); $runtimeDeclarations = $this->entityBindings->canonical($runtimeDeclarations, $runtimeEntityRecords, $this->references, $pages, array_merge($parts, $bindingTemplates), $paginationOwners); + $runtimeDeclarations = $this->productDescriptionLinks($runtimeDeclarations); BindingAnchors::assertAnchored($runtimeDeclarations, $pages, array_merge($parts, $bindingTemplates), $assets); $pages = $this->postChrome->extractCommentForms($pages); $blockThemeChrome = $this->postChrome->extractBlockThemeChrome($pages, $runtimeDeclarations, $runtimeEntityRecords); @@ -1029,4 +1030,26 @@ private static function markups(array $documents): array { return array_values(array_filter(array_column($documents, 'canonical_block_markup'), 'is_string')); } + + /** + * Product descriptions are source HTML like page content: their links to + * captured routes resolve through the same route table, against the + * product's own page or, for catalog-only rows, the entrypoint. + */ + private function productDescriptionLinks(array $declarations): array + { + $entry = ''; + foreach ($this->initialDocuments as $document) if (!empty($document['entrypoint'])) $entry = (string) $document['source_path']; + foreach ($declarations as $index => $declaration) { + if ('entity_collection' !== ($declaration['kind'] ?? null) || 'products' !== ($declaration['type'] ?? null)) continue; + foreach ($declaration['payload']['entities'] ?? array() as $row => $product) { + foreach (array('description', 'short_description') as $field) { + if (!is_array($product) || !is_string($product[$field] ?? null) || '' === $product[$field]) continue; + $origin = is_string($product['source_path'] ?? null) && '' !== $product['source_path'] ? $product['source_path'] : $entry; + $declarations[$index]['payload']['entities'][$row][$field] = $this->links->markup($product[$field], $origin); + } + } + } + return $declarations; + } } diff --git a/php-transformer/tests/contract/caller-products-catalog.php b/php-transformer/tests/contract/caller-products-catalog.php index 49b2ba6c4..31274163e 100644 --- a/php-transformer/tests/contract/caller-products-catalog.php +++ b/php-transformer/tests/contract/caller-products-catalog.php @@ -14,12 +14,13 @@ $catalog[] = array('slug' => $slug, 'name' => 'Catalog ' . strtoupper($slug), 'regular_price' => '99.00', 'sale_price' => '89.00', 'sku' => 'CAT-' . $slug, 'image' => 'https://example.test/catalog.jpg', 'description' => 'Catalog description', 'images' => array(array('src' => 'https://example.test/catalog.jpg', 'alt' => 'Catalog')), 'tags' => array('catalog'), 'category' => 'Catalog category', 'categories' => array('Catalog category', 'Sale'), 'brands' => array('Acme'), 'category_paths' => array(array('Shop', 'Drives', 'SAS'), array('Shop', 'Sale')), 'stock_status' => 'outofstock', 'variants' => array()); } $catalog[0]['currency'] = 'PEN'; +$catalog[2]['description'] = '
'; $card = static fn (string $slug): string => '
$10.00
Detail page