From e686526db022bdb22bc4286905213b40a14161d3 Mon Sep 17 00:00:00 2001
From: Eduardo Pulpillo <7486607+edupulpillo@users.noreply.github.com>
Date: Mon, 27 Apr 2026 19:29:32 +0800
Subject: [PATCH 01/12] Calculate potential kits stock from components
Added calculation for potential kits stock based on component quantities and available stock displayed at the bottom of the components list
---
htdocs/product/composition/card.php | 25 ++++++++++++++++++++++++-
1 file changed, 24 insertions(+), 1 deletion(-)
diff --git a/htdocs/product/composition/card.php b/htdocs/product/composition/card.php
index 758a4e21c8de4..2ba6444827570 100644
--- a/htdocs/product/composition/card.php
+++ b/htdocs/product/composition/card.php
@@ -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']);
@@ -681,7 +682,20 @@
if (isModEnabled('stock')) {
print '
'.$value['stock'].' | '; // Real stock
}
-
+ // Check if the component has a required quantity and stock.
+ 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
@@ -795,6 +809,15 @@
// Stock
if (isModEnabled('stock')) {
+ // Add a new row for the potential kits stock.
+ $colspan_counter = 0;
+ print '';
+ print ' | | | ';
+ print '' . $langs->trans("PotentialKitsFromStock") . ' | ';
+ // 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 '' . price($stock_to_display) . ' | ';
+ print '
';
print ' | ';
}
From 201e143f88d83af2ecfeb8a02a237456c3aebe0b Mon Sep 17 00:00:00 2001
From: Eduardo Pulpillo <7486607+edupulpillo@users.noreply.github.com>
Date: Mon, 27 Apr 2026 19:57:16 +0800
Subject: [PATCH 02/12] Fix stock display logic in card.php
---
htdocs/product/composition/card.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/htdocs/product/composition/card.php b/htdocs/product/composition/card.php
index 2ba6444827570..d436fee35d6f9 100644
--- a/htdocs/product/composition/card.php
+++ b/htdocs/product/composition/card.php
@@ -681,7 +681,7 @@
// Stock
if (isModEnabled('stock')) {
print ''.$value['stock'].' | '; // Real stock
- }
+ }
// Check if the component has a required quantity and stock.
if ($value['nb'] > 0 && is_numeric($value['stock'])) {
// Calculate how many full kits this component can support.
From b2fedbb9ddde9c7ed5550bf12ae13e5660b0424b Mon Sep 17 00:00:00 2001
From: Eduardo Pulpillo <7486607+edupulpillo@users.noreply.github.com>
Date: Mon, 27 Apr 2026 20:04:31 +0800
Subject: [PATCH 03/12] Update card.php
---
htdocs/product/composition/card.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/htdocs/product/composition/card.php b/htdocs/product/composition/card.php
index d436fee35d6f9..2ba6444827570 100644
--- a/htdocs/product/composition/card.php
+++ b/htdocs/product/composition/card.php
@@ -681,7 +681,7 @@
// Stock
if (isModEnabled('stock')) {
print ''.$value['stock'].' | '; // Real stock
- }
+ }
// Check if the component has a required quantity and stock.
if ($value['nb'] > 0 && is_numeric($value['stock'])) {
// Calculate how many full kits this component can support.
From d0218f0892b93790bc15b3d99ecd58ac2685e39c Mon Sep 17 00:00:00 2001
From: Eduardo Pulpillo <7486607+edupulpillo@users.noreply.github.com>
Date: Mon, 27 Apr 2026 22:38:08 +0800
Subject: [PATCH 04/12] Fix comment indentation in card.php
---
htdocs/product/composition/card.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/htdocs/product/composition/card.php b/htdocs/product/composition/card.php
index 2ba6444827570..110066892c791 100644
--- a/htdocs/product/composition/card.php
+++ b/htdocs/product/composition/card.php
@@ -814,7 +814,7 @@
print '';
print ' | | | ';
print '' . $langs->trans("PotentialKitsFromStock") . ' | ';
- // Calculate the value to display. If $potential_kit_stock is null or 0, show 0.
+ // 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 '' . price($stock_to_display) . ' | ';
print '
';
From 870269637a8b070ee8f1236ae10138a1236fe342 Mon Sep 17 00:00:00 2001
From: Eduardo Pulpillo <7486607+edupulpillo@users.noreply.github.com>
Date: Mon, 27 Apr 2026 23:13:02 +0800
Subject: [PATCH 05/12] Fix comment indentation in card.php
---
htdocs/product/composition/card.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/htdocs/product/composition/card.php b/htdocs/product/composition/card.php
index 110066892c791..77d0295b43360 100644
--- a/htdocs/product/composition/card.php
+++ b/htdocs/product/composition/card.php
@@ -684,7 +684,7 @@
}
// Check if the component has a required quantity and stock.
if ($value['nb'] > 0 && is_numeric($value['stock'])) {
- // Calculate how many full kits this component can support.
+ // 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) {
From 66a96e3f742d29a26eb0f4c9beacd5c3f4cf7bf8 Mon Sep 17 00:00:00 2001
From: Eduardo Pulpillo <7486607+edupulpillo@users.noreply.github.com>
Date: Tue, 28 Apr 2026 01:36:52 +0800
Subject: [PATCH 06/12] type mitsmatch fix
type mitsmatch fix
---
htdocs/product/composition/card.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/htdocs/product/composition/card.php b/htdocs/product/composition/card.php
index 77d0295b43360..7b7929bb7cc5b 100644
--- a/htdocs/product/composition/card.php
+++ b/htdocs/product/composition/card.php
@@ -810,7 +810,7 @@
// Stock
if (isModEnabled('stock')) {
// Add a new row for the potential kits stock.
- $colspan_counter = 0;
+ $colspan_counter = null;
print '';
print ' | | | ';
print '' . $langs->trans("PotentialKitsFromStock") . ' | ';
From d8cda78be2a94faa6321d4c04e1499704d1915ea Mon Sep 17 00:00:00 2001
From: Eduardo Pulpillo <7486607+edupulpillo@users.noreply.github.com>
Date: Tue, 28 Apr 2026 23:03:46 +0800
Subject: [PATCH 07/12] Initialize potential_kit_stock to zero
---
htdocs/product/composition/card.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/htdocs/product/composition/card.php b/htdocs/product/composition/card.php
index 7b7929bb7cc5b..80c5fcfeb7d37 100644
--- a/htdocs/product/composition/card.php
+++ b/htdocs/product/composition/card.php
@@ -613,7 +613,7 @@
$totalsell = 0;
$total = 0;
- $potential_kit_stock = null;
+ $potential_kit_stock = 0;
if (count($prods_arbo)) {
foreach ($prods_arbo as $value) {
$productstatic->fetch($value['id']);
From 1e365a5d03764f88c2c37d4035cf1e7cd5856c28 Mon Sep 17 00:00:00 2001
From: Eduardo Pulpillo <7486607+edupulpillo@users.noreply.github.com>
Date: Wed, 29 Apr 2026 01:02:09 +0800
Subject: [PATCH 08/12] Simplify condition for determining potential kit stock
---
htdocs/product/composition/card.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/htdocs/product/composition/card.php b/htdocs/product/composition/card.php
index 80c5fcfeb7d37..edf85926cc20e 100644
--- a/htdocs/product/composition/card.php
+++ b/htdocs/product/composition/card.php
@@ -687,7 +687,7 @@
// 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) {
+ if ($possible_with_this < $potential_kit_stock) {
$potential_kit_stock = $possible_with_this;
}
} else {
From dc21773babe9d64ec9b2f45df7b28c3aabe75b29 Mon Sep 17 00:00:00 2001
From: Eduardo Pulpillo <7486607+edupulpillo@users.noreply.github.com>
Date: Wed, 29 Apr 2026 01:26:46 +0800
Subject: [PATCH 09/12] Improve limiting factor check for kit stock calculation
---
htdocs/product/composition/card.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/htdocs/product/composition/card.php b/htdocs/product/composition/card.php
index edf85926cc20e..80c5fcfeb7d37 100644
--- a/htdocs/product/composition/card.php
+++ b/htdocs/product/composition/card.php
@@ -687,7 +687,7 @@
// 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 ($possible_with_this < $potential_kit_stock) {
+ if ($potential_kit_stock === null || $possible_with_this < $potential_kit_stock) {
$potential_kit_stock = $possible_with_this;
}
} else {
From a2ae972b2d1b3622bde847f80a5946465275aa05 Mon Sep 17 00:00:00 2001
From: Eduardo Pulpillo <7486607+edupulpillo@users.noreply.github.com>
Date: Wed, 29 Apr 2026 01:57:48 +0800
Subject: [PATCH 10/12] Fix colspan for Potential Kits From Stock display
---
htdocs/product/composition/card.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/htdocs/product/composition/card.php b/htdocs/product/composition/card.php
index 80c5fcfeb7d37..120d8ccc7b754 100644
--- a/htdocs/product/composition/card.php
+++ b/htdocs/product/composition/card.php
@@ -810,10 +810,10 @@
// Stock
if (isModEnabled('stock')) {
// Add a new row for the potential kits stock.
- $colspan_counter = null;
+ $colspan_counter = 4;
print '
';
print ' | | | ';
- print '' . $langs->trans("PotentialKitsFromStock") . ' | ';
+ print '' . $langs->trans("PotentialKitsFromStock") . ' | ';
// 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 '' . price($stock_to_display) . ' | ';
From 0791ec6c961d54bd85d3112c42ea969c9b09739a Mon Sep 17 00:00:00 2001
From: Eduardo Pulpillo <7486607+edupulpillo@users.noreply.github.com>
Date: Wed, 29 Apr 2026 03:42:29 +0800
Subject: [PATCH 11/12] Modify stock display logic in card.php
Updated stock display logic to show potential kit stock directly.
---
htdocs/product/composition/card.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/htdocs/product/composition/card.php b/htdocs/product/composition/card.php
index 120d8ccc7b754..c81bd4943a17c 100644
--- a/htdocs/product/composition/card.php
+++ b/htdocs/product/composition/card.php
@@ -815,7 +815,7 @@
print ' | | | ';
print '' . $langs->trans("PotentialKitsFromStock") . ' | ';
// 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;
+ $stock_to_display = $potential_kit_stock;
print '' . price($stock_to_display) . ' | ';
print '
';
print ' | ';
From 10021297d85ef461f81e356fb69d67198fb3aef8 Mon Sep 17 00:00:00 2001
From: Eduardo Pulpillo <7486607+edupulpillo@users.noreply.github.com>
Date: Wed, 29 Apr 2026 04:22:13 +0800
Subject: [PATCH 12/12] Fix condition for determining potential kit stock
---
htdocs/product/composition/card.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/htdocs/product/composition/card.php b/htdocs/product/composition/card.php
index c81bd4943a17c..99a7e6d888afa 100644
--- a/htdocs/product/composition/card.php
+++ b/htdocs/product/composition/card.php
@@ -687,7 +687,7 @@
// 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) {
+ if ($potential_kit_stock === 0 || $possible_with_this < $potential_kit_stock) {
$potential_kit_stock = $possible_with_this;
}
} else {