From 990fbf3ef45a06577264f7ce6630964acdc9269c Mon Sep 17 00:00:00 2001 From: Sergio Sanchis Climent Date: Mon, 26 Oct 2015 14:00:43 +0100 Subject: [PATCH 1/2] hooks correctly implemented , printObjectLine, printObjectSubLine In hook can change correctly label and ref (for my module need if is posible) --- htdocs/core/class/commonobject.class.php | 12 ++++++++---- htdocs/core/class/hookmanager.class.php | 4 +++- htdocs/core/lib/pdf.lib.php | 6 ++++++ 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index d5dac206e15..1439915ebdb 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -3108,20 +3108,21 @@ abstract class CommonObject $var=!$var; - if (is_object($hookmanager) && (($line->product_type == 9 && ! empty($line->special_code)) || ! empty($line->fk_parent_line))) + //if (is_object($hookmanager) && (($line->product_type == 9 && ! empty($line->special_code)) || ! empty($line->fk_parent_line))) + if (is_object($hookmanager)) // Old code is commented on preceding line. { if (empty($line->fk_parent_line)) { $parameters = array('line'=>$line,'var'=>$var,'num'=>$num,'i'=>$i,'dateSelector'=>$dateSelector,'seller'=>$seller,'buyer'=>$buyer,'selected'=>$selected, 'extrafieldsline'=>$extrafieldsline); - $hookmanager->executeHooks('printObjectLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks + $reshook = $hookmanager->executeHooks('printObjectLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks } else { $parameters = array('line'=>$line,'var'=>$var,'num'=>$num,'i'=>$i,'dateSelector'=>$dateSelector,'seller'=>$seller,'buyer'=>$buyer,'selected'=>$selected, 'extrafieldsline'=>$extrafieldsline); - $hookmanager->executeHooks('printObjectSubLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks + $reshook = $hookmanager->executeHooks('printObjectSubLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks } } - else + if (empty($reshook)) { $this->printObjectLine($action,$line,$var,$num,$i,$dateSelector,$seller,$buyer,$selected,$extrafieldsline); } @@ -3171,6 +3172,9 @@ abstract class CommonObject { $product_static = new Product($this->db); $product_static->fetch($line->fk_product); + + $product_static->ref = $line->ref; //can change ref in hook + $product_static->label = $line->label; //can change label in hook $text=$product_static->getNomUrl(1); // Define output language and label diff --git a/htdocs/core/class/hookmanager.class.php b/htdocs/core/class/hookmanager.class.php index 249a6665a3f..a23977acebe 100644 --- a/htdocs/core/class/hookmanager.class.php +++ b/htdocs/core/class/hookmanager.class.php @@ -163,7 +163,9 @@ class HookManager 'printAddress', 'printSearchForm', 'formatEvent', - 'addCalendarChoice' + 'addCalendarChoice', + 'printObjectLine', + 'printObjectSubLine' ) )) $hooktype='addreplace'; // Deprecated hook types ('returnvalue') diff --git a/htdocs/core/lib/pdf.lib.php b/htdocs/core/lib/pdf.lib.php index 0d7f18e1c75..0bd13869ce8 100644 --- a/htdocs/core/lib/pdf.lib.php +++ b/htdocs/core/lib/pdf.lib.php @@ -1088,6 +1088,12 @@ function pdf_getlinedesc($object,$i,$outputlangs,$hideref=0,$hidedesc=0,$issuppl if ($idprod) { $prodser->fetch($idprod); + + //can change ref in hook + if(isset($object->lines[$i]->ref)){ + $prodser->ref = $object->lines[$i]->ref; + } + // If a predefined product and multilang and on other lang, we renamed label with label translated if (! empty($conf->global->MAIN_MULTILANGS) && ($outputlangs->defaultlang != $langs->defaultlang)) { From b1bc000bae790cdb6814147671f17dc3d0082f88 Mon Sep 17 00:00:00 2001 From: Sergio Sanchis Climent Date: Tue, 27 Oct 2015 09:19:39 +0100 Subject: [PATCH 2/2] standardize --- htdocs/core/lib/pdf.lib.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/htdocs/core/lib/pdf.lib.php b/htdocs/core/lib/pdf.lib.php index 0bd13869ce8..0d7f18e1c75 100644 --- a/htdocs/core/lib/pdf.lib.php +++ b/htdocs/core/lib/pdf.lib.php @@ -1088,12 +1088,6 @@ function pdf_getlinedesc($object,$i,$outputlangs,$hideref=0,$hidedesc=0,$issuppl if ($idprod) { $prodser->fetch($idprod); - - //can change ref in hook - if(isset($object->lines[$i]->ref)){ - $prodser->ref = $object->lines[$i]->ref; - } - // If a predefined product and multilang and on other lang, we renamed label with label translated if (! empty($conf->global->MAIN_MULTILANGS) && ($outputlangs->defaultlang != $langs->defaultlang)) {