Skip to content
Open
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion htdocs/product/composition/card.php
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,7 @@

$totalsell = 0;
$total = 0;
$potential_kit_stock = null;
if (count($prods_arbo)) {
foreach ($prods_arbo as $value) {
$productstatic->fetch($value['id']);
Expand Down Expand Up @@ -681,7 +682,20 @@
if (isModEnabled('stock')) {
print '<td class="right">'.$value['stock'].'</td>'; // Real stock
}

// Check if the component has a required quantity and stock.
Comment thread
edupulpillo marked this conversation as resolved.
if ($value['nb'] > 0 && is_numeric($value['stock'])) {
// Calculate how many full kits this component can support.
$possible_with_this = floor($value['stock'] / $value['nb']);
// Keep the smallest value across all components (the limiting factor).
if ($potential_kit_stock === null || $possible_with_this < $potential_kit_stock) {
$potential_kit_stock = $possible_with_this;
}
} else {
// If a component has no required quantity or its stock is not available, no kit can be made.
$potential_kit_stock = 0;
// Optionally, break the loop early for efficiency.
break;
}
// Hook fields
$parameters = array();
$reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $productstatic); // Note that $action and $object may have been modified by hook
Expand Down Expand Up @@ -795,6 +809,15 @@

// Stock
if (isModEnabled('stock')) {
// Add a new row for the potential kits stock.
$colspan_counter = null;
print '<tr class="total-row right">';
print '<td></td><td></td><td></td>';
print '<td colspan="' . ($colspan_counter + 4) . '" class="titlefield">' . $langs->trans("PotentialKitsFromStock") . '</td>';

Check warning on line 816 in htdocs/product/composition/card.php

View workflow job for this annotation

GitHub Actions / phan / Run phan

card.php: PhanTypeInvalidLeftOperandOfAdd: Invalid operator: left operand of + is null (expected array or number)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI: there are several methods to potentially fix the phan error

card.php: PhanTypeInvalidLeftOperandOfAdd: Invalid operator: left operand of + is null (expected array or number)

You could use The PHP ternary operator to make a 1 liner, and I would make that line just before using the variable `colspan_counter``

Something like

$colspan_counter = (is_null($colspan_counter) ? (0) : ($colspan_counter);
print '<td colspan="' . ($colspan_counter + 4) . '" class="titlefield">' . $langs->trans("PotentialKitsFromStock") . '</td>';

But it may just be much more interesting to figure out why $colspan_counter was null to begin with.

Copy link
Copy Markdown
Contributor Author

@edupulpillo edupulpillo Apr 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$colspan_counter in null only about my ignorance. Should i assign a value = 0 (integer) am i right ?
So now your review is not needed anymore. Kindly accept the latest version, it pased already allt he tests of code.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@edupulpillo I am not sure what the colspan_counter is for, but if you want to do addition, then starting with 0 is a good bet, but if you only do the addition once - why even have a variable?

Copy link
Copy Markdown
Contributor Author

@edupulpillo edupulpillo Apr 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are right, better to use a constant

So now your review is not needed anymore. Kindly accept the latest version, it pased already allt he tests of code. Please complete your review is not possible to cancel a request review accidentally requested

// Calculate the value to display. If $potential_kit_stock is null or 0, show 0.
$stock_to_display = ($potential_kit_stock !== null && $potential_kit_stock > 0) ? $potential_kit_stock : 0;
print '<td class="total-value">' . price($stock_to_display) . '</td>';
print '</tr>';
print '<td class="liste_total right">&nbsp;</td>';
}

Expand Down
Loading