Fix: problem to create hook object

This commit is contained in:
Regis Houssin 2011-04-10 07:24:11 +00:00
parent be28754feb
commit 84a5469693

View File

@ -241,8 +241,17 @@ if ($_POST['action'] == 'add' && $user->rights->commande->creer)
{
$lines = $srcobject->lines;
if (empty($lines) && method_exists($srcobject,'fetch_lines')) $lines = $srcobject->fetch_lines();
for ($i = 0 ; $i < sizeof($lines) ; $i++)
// Instantiate hooks of thirdparty module
if (is_array($conf->hooks_modules) && !empty($conf->hooks_modules))
{
$object->callHooks('objectcard');
}
$fk_parent_line=0;
$num=sizeof($lines);
for ($i=0;$i<$num;$i++)
{
$desc=($lines[$i]->desc?$lines[$i]->desc:$lines[$i]->libelle);
$product_type=($lines[$i]->product_type?$lines[$i]->product_type:0);
@ -255,6 +264,11 @@ if ($_POST['action'] == 'add' && $user->rights->commande->creer)
$date_end=$lines[$i]->date_fin_prevue;
if ($lines[$i]->date_fin_reel) $date_end=$lines[$i]->date_fin_reel;
if ($lines[$i]->date_end) $date_end=$lines[$i]->date_end;
// Reset fk_parent_line for no child products and special product
if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9) {
$fk_parent_line = 0;
}
$result = $object->addline(
$object_id,
@ -274,7 +288,8 @@ if ($_POST['action'] == 'add' && $user->rights->commande->creer)
$dateend,
$product_type,
$lines[$i]->rang,
$lines[$i]->special_code
$lines[$i]->special_code,
$fk_parent_line
);
if ($result < 0)
@ -282,6 +297,21 @@ if ($_POST['action'] == 'add' && $user->rights->commande->creer)
$error++;
break;
}
// Defined the new fk_parent_line
if ($result > 0 && $lines[$i]->product_type == 9) {
$fk_parent_line = $result;
}
}
// Hooks
if (! empty($object->hooks))
{
foreach($object->hooks as $module)
{
$res = $module->createfrom($srcobject,$object_id,$object->element);
if ($res < 0) $error++;
}
}
}
else