hooks correctly implemented , printObjectLine, printObjectSubLine

In hook can change correctly label and ref (for my module need if is posible)
This commit is contained in:
Sergio Sanchis Climent 2015-10-26 14:00:43 +01:00
parent 4b2db78c3a
commit 990fbf3ef4
3 changed files with 17 additions and 5 deletions

View File

@ -3108,20 +3108,21 @@ abstract class CommonObject
$var=!$var; $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)) 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); $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 else
{ {
$parameters = array('line'=>$line,'var'=>$var,'num'=>$num,'i'=>$i,'dateSelector'=>$dateSelector,'seller'=>$seller,'buyer'=>$buyer,'selected'=>$selected, 'extrafieldsline'=>$extrafieldsline); $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); $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 = new Product($this->db);
$product_static->fetch($line->fk_product); $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); $text=$product_static->getNomUrl(1);
// Define output language and label // Define output language and label

View File

@ -163,7 +163,9 @@ class HookManager
'printAddress', 'printAddress',
'printSearchForm', 'printSearchForm',
'formatEvent', 'formatEvent',
'addCalendarChoice' 'addCalendarChoice',
'printObjectLine',
'printObjectSubLine'
) )
)) $hooktype='addreplace'; )) $hooktype='addreplace';
// Deprecated hook types ('returnvalue') // Deprecated hook types ('returnvalue')

View File

@ -1088,6 +1088,12 @@ function pdf_getlinedesc($object,$i,$outputlangs,$hideref=0,$hidedesc=0,$issuppl
if ($idprod) if ($idprod)
{ {
$prodser->fetch($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 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)) if (! empty($conf->global->MAIN_MULTILANGS) && ($outputlangs->defaultlang != $langs->defaultlang))
{ {