Skip to content

Commit

Permalink
FIX : must not get full path with recursive query
Browse files Browse the repository at this point in the history
  • Loading branch information
atm-gauthier committed Oct 20, 2016
1 parent 9a3d403 commit 59941f9
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 7 deletions.
38 changes: 33 additions & 5 deletions htdocs/product/class/html.formproduct.class.php
Expand Up @@ -67,7 +67,7 @@ function loadWarehouses($fk_product=0, $batch = '', $status=null, $sumStock = tr

if (is_array($exclude)) $excludeGroups = implode("','",$exclude);

$sql = "SELECT e.rowid, e.label, e.description";
$sql = "SELECT e.rowid, e.label, e.description, e.fk_parent";
if (!empty($fk_product))
{
if (!empty($batch))
Expand Down Expand Up @@ -118,14 +118,19 @@ function loadWarehouses($fk_product=0, $batch = '', $status=null, $sumStock = tr
{
$obj = $this->db->fetch_object($resql);
if ($sumStock) $obj->stock = price2num($obj->stock,5);
$o = new Entrepot($this->db);
$o->fetch($obj->rowid);
$this->cache_warehouses[$obj->rowid]['id'] =$obj->rowid;
$this->cache_warehouses[$obj->rowid]['label']=$o->get_full_arbo();
$this->cache_warehouses[$obj->rowid]['label']=$obj->label;
$this->cache_warehouses[$obj->rowid]['parent_id']=$obj->fk_parent;
$this->cache_warehouses[$obj->rowid]['description'] = $obj->description;
$this->cache_warehouses[$obj->rowid]['stock'] = $obj->stock;
$i++;
}

// Full label init
foreach($this->cache_warehouses as $obj_rowid=>$tab) {
$this->cache_warehouses[$obj_rowid]['full_label'] = $this->get_parent_path($tab);
}

return $num;
}
else
Expand All @@ -134,6 +139,29 @@ function loadWarehouses($fk_product=0, $batch = '', $status=null, $sumStock = tr
return -1;
}
}

/**
* Return full path to current warehouse in $tab (recursive function)
*
* @param array $tab warehouse data in $this->cache_warehouses line
* @param String $final_label full label with all parents, separated by ' >> ' (completed on each call)
* @return String full label with all parents, separated by ' >> '
*/
private function get_parent_path($tab, $final_label='') {

if(empty($final_label)) $final_label = $tab['label'];

if(empty($tab['parent_id'])) return $final_label;
else {
if(!empty($this->cache_warehouses[$tab['parent_id']])) {
$final_label = $this->cache_warehouses[$tab['parent_id']]['label'].' >> '.$final_label;
return $this->get_parent_path($this->cache_warehouses[$tab['parent_id']], $final_label);
}
}

return $final_label;

}

/**
* Return list of warehouses
Expand Down Expand Up @@ -178,7 +206,7 @@ function selectWarehouses($selected='',$htmlname='idwarehouse',$filtertype='',$e
$out.='<option value="'.$id.'"';
if ($selected == $id || ($selected == 'ifone' && $nbofwarehouses == 1)) $out.=' selected';
$out.='>';
$out.=$arraytypes['label'];
$out.=$arraytypes['full_label'];
if (($fk_product || ($showstock > 0)) && ($arraytypes['stock'] != 0 || ($showstock > 0))) $out.=' ('.$langs->trans("Stock").':'.$arraytypes['stock'].')';
$out.='</option>';
}
Expand Down
2 changes: 1 addition & 1 deletion htdocs/product/stock/card.php
Expand Up @@ -646,7 +646,7 @@

// Parent entrepot
print '<tr><td>'.$langs->trans("AddIn").'</td><td>';
print $formproduct->selectWarehouses($object->fk_parent, 'fk_parent', '', 1, 0, 0, '', 0, 0, array(), 'minwidth200', array($object->id));
print $formproduct->selectWarehouses($object->fk_parent, 'fk_parent', '', 1);
print '</td></tr>';

// Description
Expand Down
2 changes: 1 addition & 1 deletion htdocs/product/stock/class/entrepot.class.php
Expand Up @@ -174,7 +174,7 @@ function update($id, $user)
{
// Check if new parent is already a child of current warehouse
if(!empty($this->fk_parent)) {
$TChildWarehouses = array();
$TChildWarehouses = array($id);
$TChildWarehouses = $this->get_children_warehouses($this->id, $TChildWarehouses);
if(in_array($this->fk_parent, $TChildWarehouses)) {
$this->error = 'ErrorCannotAddThisParentWarehouse';
Expand Down

0 comments on commit 59941f9

Please sign in to comment.