From 543e6f186cdf03113f07b2d7b3ffbebadbda3afa Mon Sep 17 00:00:00 2001 From: Christophe Battarel Date: Wed, 27 Apr 2022 09:03:51 +0200 Subject: [PATCH 1/3] add hook to getSellPrice function --- htdocs/product/class/product.class.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index 84cc2454c21..cf9a0c3fa87 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -1804,6 +1804,16 @@ class Product extends CommonObject { global $conf, $db; + // call hook if any + $hookmanager->initHooks(array('productdao')); + $parameters = array('thirdparty_seller'=>$thirdparty_seller, 'thirdparty_buyer' => $thirdparty_buyer, 'pqp' => $pqp); + // Note that $action and $object may have been modified by some hooks + global $action; + $reshook = $hookmanager->executeHooks('getSellPrice', $parameters, $this, $action); + if ( ! empty($reshook)) { + return $hookmanager->resArray; + } + // Update if prices fields are defined $tva_tx = get_default_tva($thirdparty_seller, $thirdparty_buyer, $this->id); $tva_npr = get_default_npr($thirdparty_seller, $thirdparty_buyer, $this->id); From 25078b292d6996065fd265c678780584d86d8065 Mon Sep 17 00:00:00 2001 From: Christophe Battarel Date: Wed, 27 Apr 2022 09:40:09 +0200 Subject: [PATCH 2/3] fix hookmanager --- htdocs/product/class/product.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index cf9a0c3fa87..bb411d530c7 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -1802,7 +1802,7 @@ class Product extends CommonObject */ public function getSellPrice($thirdparty_seller, $thirdparty_buyer, $pqp = 0) { - global $conf, $db; + global $conf, $db, $hookmanager; // call hook if any $hookmanager->initHooks(array('productdao')); From 75f540c30cde44d9dc1eef300f44c319e29e7205 Mon Sep 17 00:00:00 2001 From: Christophe Battarel Date: Thu, 28 Apr 2022 11:49:15 +0200 Subject: [PATCH 3/3] fix for reshook when several module use the hook but only on is concerned --- htdocs/product/class/product.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index bb411d530c7..1bacf75c7d2 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -1810,7 +1810,7 @@ class Product extends CommonObject // Note that $action and $object may have been modified by some hooks global $action; $reshook = $hookmanager->executeHooks('getSellPrice', $parameters, $this, $action); - if ( ! empty($reshook)) { + if ( ! empty($hookmanager->resArray)) { return $hookmanager->resArray; }