From 77483b34115f0f6f71cfdea3069c4aca1bb30a7e Mon Sep 17 00:00:00 2001 From: Lester Caine Date: Fri, 12 Jun 2026 16:13:36 +0100 Subject: stock: BOM view uses linked_title/linked_data; loadXrefInfo only enriches part_size MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Component title and description in BOM view templates (view_xref_bom_item, view_xref_bomprt_item, print_bom) now use linked_title/linked_data from the lc_linked JOIN in loadContent() — same pattern as the supplier name fix. StockAssembly::loadXrefInfo() drops the title/data enrichment loop (now redundant) and only queries for part_size/part_size_ext from the PRT xref. array_column replaced with array_map to reliably call ArrayAccess offsetGet on LibertyXref objects. Co-Authored-By: Claude Sonnet 4.6 --- includes/classes/StockAssembly.php | 10 ++++++---- templates/print_bom.tpl | 4 ++-- templates/stockassembly/view_xref_bom_item.tpl | 4 ++-- templates/stockassembly/view_xref_bomprt_item.tpl | 4 ++-- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/includes/classes/StockAssembly.php b/includes/classes/StockAssembly.php index 4fe4bdc..c072c41 100755 --- a/includes/classes/StockAssembly.php +++ b/includes/classes/StockAssembly.php @@ -107,10 +107,14 @@ class StockAssembly extends StockBase { $bomGroup = $this->mXrefInfo->mGroups['quantity'] ?? null; if( !$bomGroup || empty( $bomGroup->mXrefs ) ) return; usort( $bomGroup->mXrefs, fn($a,$b) => ( $a['xorder'] <=> $b['xorder'] ) ?: strcmp( $a['item'], $b['item'] ) ); - $componentIds = array_values( array_unique( array_filter( array_column( $bomGroup->mXrefs, 'xref' ) ) ) ); + // title and data come from linked_title/linked_data (lc_linked JOIN in loadContent) + // only need a separate query for part_size/part_size_ext from the PRT xref + $componentIds = array_values( array_unique( array_filter( + array_map( fn($r) => $r['xref'], $bomGroup->mXrefs ) + ) ) ); if( !$componentIds ) return; $components = $this->mDb->getAssoc( - "SELECT lc.`content_id`, lc.`title`, lc.`data`, pck.`xkey` AS `part_size`, pck.`xkey_ext` AS `part_size_ext` + "SELECT lc.`content_id`, pck.`xkey` AS `part_size`, pck.`xkey_ext` AS `part_size_ext` FROM `".BIT_DB_PREFIX."liberty_content` lc LEFT JOIN `".BIT_DB_PREFIX."liberty_xref` pck ON pck.`content_id` = lc.`content_id` AND pck.`item` = 'PRT' WHERE lc.`content_id` IN (".implode( ',', array_fill( 0, count( $componentIds ), '?' ) ).")", @@ -118,8 +122,6 @@ class StockAssembly extends StockBase { ); foreach( $bomGroup->mXrefs as &$row ) { if( !empty( $row['xref'] ) && isset( $components[$row['xref']] ) ) { - $row['xref_title'] = $components[$row['xref']]['title']; - $row['xref_data'] = $components[$row['xref']]['data']; $row['part_size'] = $components[$row['xref']]['part_size']; $row['part_size_ext'] = $components[$row['xref']]['part_size_ext']; } diff --git a/templates/print_bom.tpl b/templates/print_bom.tpl index ece3cac..a98f4c1 100644 --- a/templates/print_bom.tpl +++ b/templates/print_bom.tpl @@ -34,12 +34,12 @@ {$posInGroup} {if $row.xref > 0} - {$row.xref_title|default:$row.xref|escape} + {$row.linked_title|default:$row.xref|escape} {else}   {/if} - {$row.xref_data|escape} + {$row.linked_data|escape} {$row.xkey|escape} {if $row.item eq 'PRT' && $row.part_size} of {$row.part_size|escape}{if $row.part_size_ext} {$row.part_size_ext|escape}{/if}{/if} diff --git a/templates/stockassembly/view_xref_bom_item.tpl b/templates/stockassembly/view_xref_bom_item.tpl index 1ed0a95..6dfd627 100644 --- a/templates/stockassembly/view_xref_bom_item.tpl +++ b/templates/stockassembly/view_xref_bom_item.tpl @@ -2,12 +2,12 @@ {if $xrefInfo.xref > 0} - {$xrefInfo.xref_title|default:$xrefInfo.xref|escape} + {$xrefInfo.linked_title|default:$xrefInfo.xref|escape} {else}   {/if} - {$xrefInfo.xref_data|escape} + {$xrefInfo.linked_data|escape} {$xrefInfo.xkey|escape} {$xrefInfo.xkey_ext|escape} {if $xrefAllowEdit} diff --git a/templates/stockassembly/view_xref_bomprt_item.tpl b/templates/stockassembly/view_xref_bomprt_item.tpl index 002ae89..c066678 100644 --- a/templates/stockassembly/view_xref_bomprt_item.tpl +++ b/templates/stockassembly/view_xref_bomprt_item.tpl @@ -2,12 +2,12 @@ {if $xrefInfo.xref > 0} - {$xrefInfo.xref_title|default:$xrefInfo.xref|escape} + {$xrefInfo.linked_title|default:$xrefInfo.xref|escape} {else}   {/if} - {$xrefInfo.xref_data|escape} + {$xrefInfo.linked_data|escape} {$xrefInfo.xkey|escape}{if $xrefInfo.part_size} of {$xrefInfo.part_size|escape}{if $xrefInfo.part_size_ext} {$xrefInfo.part_size_ext|escape}{/if}{/if} {$xrefInfo.xkey_ext|escape} {if $xrefAllowEdit} -- cgit v1.3