From b065cbc6f88023a7f6bef9a2c225bd3098c7a5e8 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 4 Jul 2019 12:09:04 +0200 Subject: [PATCH] FIX #11446 --- htdocs/product/class/product.class.php | 39 ++++++++++++++------------ test/phpunit/ProductTest.php | 27 +++++++++++++++++- 2 files changed, 47 insertions(+), 19 deletions(-) diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index 69cd6ba077c..c0038ac17d8 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -3716,7 +3716,7 @@ class Product extends CommonObject // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Fonction recursive uniquement utilisee par get_arbo_each_prod, recompose l'arborescence des sousproduits - * Define value of this->res + * Define value of this->res * * @param array $prod Products array * @param string $compl_path Directory path of parents to add before @@ -3730,7 +3730,7 @@ class Product extends CommonObject // phpcs:enable global $conf,$langs; - $product = new Product($this->db); + $tmpproduct = null; //var_dump($prod); foreach($prod as $id_product => $desc_pere) // $id_product is 0 (first call starting with root top) or an id of a sub_product { @@ -3746,23 +3746,26 @@ class Product extends CommonObject } //print "XXX We add id=".$id." - label=".$label." - nb=".$nb." - multiply=".$multiply." fullpath=".$compl_path.$label."\n"; - $this->fetch($id); // Load product - $this->load_stock('nobatch,novirtual'); // Load stock to get true this->stock_reel + if (is_null($tmpproduct)) $tmpproduct = new Product($this->db); // So we initialize tmpproduct only once for all loop. + $tmpproduct->fetch($id); // Load product to get ->ref + $tmpproduct->load_stock('nobatch,novirtual'); // Load stock to get true ->stock_reel + //$this->fetch($id); // Load product to get ->ref + //$this->load_stock('nobatch,novirtual'); // Load stock to get true ->stock_reel $this->res[]= array( - 'id'=>$id, // Id product - 'id_parent'=>$id_parent, - 'ref'=>$this->ref, // Ref product - 'nb'=>$nb, // Nb of units that compose parent product - 'nb_total'=>$nb*$multiply, // Nb of units for all nb of product - 'stock'=>$this->stock_reel, // Stock - 'stock_alert'=>$this->seuil_stock_alerte, // Stock alert - 'label'=>$label, - 'fullpath'=>$compl_path.$label, // Label - 'type'=>$type, // Nb of units that compose parent product - 'desiredstock'=>$this->desiredstock, - 'level'=>$level, - 'incdec'=>$incdec, - 'entity'=>$this->entity + 'id'=>$id, // Id product + 'id_parent'=>$id_parent, + 'ref'=>$tmpproduct->ref, // Ref product + 'nb'=>$nb, // Nb of units that compose parent product + 'nb_total'=>$nb*$multiply, // Nb of units for all nb of product + 'stock'=>$tmpproduct->stock_reel, // Stock + 'stock_alert'=>$tmpproduct->seuil_stock_alerte, // Stock alert + 'label'=>$label, + 'fullpath'=>$compl_path.$label, // Label + 'type'=>$type, // Nb of units that compose parent product + 'desiredstock'=>$tmpproduct->desiredstock, + 'level'=>$level, + 'incdec'=>$incdec, + 'entity'=>$tmpproduct->entity ); // Recursive call if there is childs to child diff --git a/test/phpunit/ProductTest.php b/test/phpunit/ProductTest.php index c57ef426d0b..782d5f076e8 100644 --- a/test/phpunit/ProductTest.php +++ b/test/phpunit/ProductTest.php @@ -45,7 +45,7 @@ $conf->global->MAIN_DISABLE_ALL_MAILS=1; * @backupStaticAttributes enabled * @remarks backupGlobals must be disabled to have db,conf,user and lang not erased. */ -class ProductTest extends PHPUnit_Framework_TestCase +class ProductTest extends PHPUnit\Framework\TestCase { protected $savconf; protected $savuser; @@ -168,6 +168,31 @@ class ProductTest extends PHPUnit_Framework_TestCase return $localobject; } + /** + * testProductGetArboEachProd + * + * @return void + */ + public function testProductGetArboEachProd() + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; + + /* + $localobject=new Product($db); + $localobject->fetch(208); + $localobject->get_sousproduits_arbo(); + $localobject->get_arbo_each_prod(); + + var_dump($localobject->res); print (json_encode($localobject->res)); exit; + */ + + return; + } + /** * testProductUpdate *