NEW Add option to include parent products too in stats of orders

This commit is contained in:
Laurent Destailleur 2016-11-11 14:17:11 +01:00
parent e2b7773353
commit 899ba6d90b

View File

@ -1988,28 +1988,26 @@ class Product extends CommonObject
$this->stats_commande['qty']=$obj->qty?$obj->qty:0; $this->stats_commande['qty']=$obj->qty?$obj->qty:0;
// if it's a virtual product, maybe it is in order by extension // if it's a virtual product, maybe it is in order by extension
$TFather = $this->getFather(); if (! empty($conf->global->ORDER_ADD_ORDERS_WITH_PARENT_PROD_IF_INCDEC))
if(is_array($TFather) && !empty($TFather)) { {
$TFather = $this->getFather();
if (is_array($TFather) && !empty($TFather)) {
foreach($TFather as &$fatherData) {
$pFather = new Product($this->db);
$pFather->id = $fatherData['id'];
$qtyCoef = $fatherData['qty'];
foreach($TFather as &$fatherData) { if ($fatherData['incdec']) {
$pFather->load_stats_commande($socid, $filtrestatut);
$pFather = new Product($this->db); $this->stats_commande['customers']+=$pFather->stats_commande['customers'];
$pFather->id = $fatherData['id']; $this->stats_commande['nb']+=$pFather->stats_commande['nb'];
$qtyCoef = $fatherData['qty']; $this->stats_commande['rows']+=$pFather->stats_commande['rows'];
$this->stats_commande['qty']+=$pFather->stats_commande['qty'] * $qtyCoef;
if($fatherData['incdec']) {
$pFather->load_stats_commande($socid, $filtrestatut);
$this->stats_commande['customers']+=$pFather->stats_commande['customers'];
$this->stats_commande['nb']+=$pFather->stats_commande['nb'];
$this->stats_commande['rows']+=$pFather->stats_commande['rows'];
$this->stats_commande['qty']+=$pFather->stats_commande['qty'] * $qtyCoef;
}
} }
} }
} }
return 1; return 1;