diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index 6c75e7d0fb2..fce56903456 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -15,7 +15,8 @@ * Copyright (C) 2016-2018 Ferran Marcet * Copyright (C) 2017 Gustavo Novaro * Copyright (C) 2019-2023 Frédéric France - * + * Copyright (C) 2023 Benjamin Falière + * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or @@ -4254,10 +4255,13 @@ class Product extends CommonObject * @param int $id_fils Id of child product/service * @param int $qty Quantity * @param int $incdec 1=Increase/decrease stock of child when parent stock increase/decrease + * @param int $notrigger Disable triggers * @return int < 0 if KO, > 0 if OK */ - public function add_sousproduit($id_pere, $id_fils, $qty, $incdec = 1) + public function add_sousproduit($id_pere, $id_fils, $qty, $incdec = 1, $notrigger = 0) { + global $user; + // phpcs:enable // Clean parameters if (!is_numeric($id_pere)) { @@ -4296,6 +4300,17 @@ class Product extends CommonObject dol_print_error($this->db); return -1; } else { + if (!$notrigger) { + // Call trigger + $result = $this->call_trigger('PRODUCT_SUBPRODUCT_ADD', $user); + if ($result < 0) { + $this->error = $this->db->lasterror(); + dol_syslog(get_class($this).'::addSubproduct error='.$this->error, LOG_ERR); + return -1; + } + } + // End call triggers + return 1; } } else { @@ -4313,10 +4328,13 @@ class Product extends CommonObject * @param int $id_fils Id of child product/service * @param int $qty Quantity * @param int $incdec 1=Increase/decrease stock of child when parent stock increase/decrease + * @param int $notrigger Disable triggers * @return int < 0 if KO, > 0 if OK */ - public function update_sousproduit($id_pere, $id_fils, $qty, $incdec = 1) + public function update_sousproduit($id_pere, $id_fils, $qty, $incdec = 1, $notrigger = 0) { + global $user; + // phpcs:enable // Clean parameters if (!is_numeric($id_pere)) { @@ -4341,6 +4359,17 @@ class Product extends CommonObject dol_print_error($this->db); return -1; } else { + if (!$notrigger) { + // Call trigger + $result = $this->call_trigger('PRODUCT_SUBPRODUCT_UPDATE', $user); + if ($result < 0) { + $this->error = $this->db->lasterror(); + dol_syslog(get_class($this).'::updateSubproduct error='.$this->error, LOG_ERR); + return -1; + } + // End call triggers + } + return 1; } } @@ -4351,10 +4380,13 @@ class Product extends CommonObject * * @param int $fk_parent Id of parent product (child will no more be linked to it) * @param int $fk_child Id of child product + * @param int $notrigger Disable triggers * @return int < 0 if KO, > 0 if OK */ - public function del_sousproduit($fk_parent, $fk_child) + public function del_sousproduit($fk_parent, $fk_child, $notrigger = 0) { + global $user; + // phpcs:enable if (!is_numeric($fk_parent)) { $fk_parent = 0; @@ -4391,6 +4423,18 @@ class Product extends CommonObject } } } + + if (!$notrigger) { + // Call trigger + $result = $this->call_trigger('PRODUCT_SUBPRODUCT_DELETE', $user); + if ($result < 0) { + $this->error = $this->db->lasterror(); + dol_syslog(get_class($this).'::delSubproduct error='.$this->error, LOG_ERR); + return -1; + } + // End call triggers + } + return 1; }