Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX display full tree on shipment card when a kit contains a same component in other sub-kit #33024

Merged
Changes from all 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
18 changes: 7 additions & 11 deletions htdocs/product/class/product.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -4966,8 +4966,6 @@ public function getFather()
*/
public function getChildsArbo($id, $firstlevelonly = 0, $level = 1, $parents = array())
{
global $alreadyfound;

if (empty($id)) {
return array();
}
Expand All @@ -4984,9 +4982,6 @@ public function getChildsArbo($id, $firstlevelonly = 0, $level = 1, $parents = a

dol_syslog(get_class($this).'::getChildsArbo id='.$id.' level='.$level. ' parents='.(is_array($parents)?implode(',', $parents):$parents), LOG_DEBUG);

if ($level == 1) {
$alreadyfound = array($id=>1); // We init array of found object to start of tree, so if we found it later (should not happened), we stop immediatly
}
// Protection against infinite loop
if ($level > 30) {
return array();
Expand All @@ -4995,14 +4990,16 @@ public function getChildsArbo($id, $firstlevelonly = 0, $level = 1, $parents = a
$res = $this->db->query($sql);
if ($res) {
$prods = array();
if ($this->db->num_rows($res) > 0) {
$parents[] = $id;
}

while ($rec = $this->db->fetch_array($res)) {
if (!empty($alreadyfound[$rec['rowid']])) {
if (in_array($rec['id'], $parents)) {
dol_syslog(get_class($this).'::getChildsArbo the product id='.$rec['rowid'].' was already found at a higher level in tree. We discard to avoid infinite loop', LOG_WARNING);
if (in_array($rec['id'], $parents)) {
continue; // We discard this child if it is already found at a higher level in tree in the same branch.
}
continue; // We discard this child if it is already found at a higher level in tree in the same branch.
}
$alreadyfound[$rec['rowid']] = 1;

$prods[$rec['rowid']] = array(
0=>$rec['rowid'],
1=>$rec['qty'],
Expand All @@ -5016,7 +5013,6 @@ public function getChildsArbo($id, $firstlevelonly = 0, $level = 1, $parents = a
//$prods[$this->db->escape($rec['label'])]= array(0=>$rec['id'],1=>$rec['qty'],2=>$rec['fk_product_type']);
//$prods[$this->db->escape($rec['label'])]= array(0=>$rec['id'],1=>$rec['qty']);
if (empty($firstlevelonly)) {
$parents[] = $rec['rowid'];
$listofchilds = $this->getChildsArbo($rec['rowid'], 0, $level + 1, $parents);
foreach ($listofchilds as $keyChild => $valueChild) {
$prods[$rec['rowid']]['childs'][$keyChild] = $valueChild;
Expand Down
Loading