From 8aa4a515ddf4fd88c4d5cbf974d08ebadeb5915f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Fri, 12 Jan 2024 20:43:00 +0100 Subject: [PATCH] add hook getBuyPrice (#27420) --- htdocs/product/class/product.class.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index e3ba4563db4..5a7ae18ee1d 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -2088,7 +2088,24 @@ class Product extends CommonObject public function get_buyprice($prodfournprice, $qty, $product_id = 0, $fourn_ref = '', $fk_soc = 0) { // phpcs:enable - global $conf; + global $action, $hookmanager; + + // Call hook if any + if (is_object($hookmanager)) { + $parameters = array( + 'prodfournprice' => $prodfournprice, + 'qty' => $qty, + 'product_id' => $product_id, + 'fourn_ref' => $fourn_ref, + 'fk_soc' => $fk_soc, + ); + // Note that $action and $object may have been modified by some hooks + $reshook = $hookmanager->executeHooks('getBuyPrice', $parameters, $this, $action); + if ($reshook > 0) { + return $hookmanager->resArray; + } + } + $result = 0; // We do a first search with a select by searching with couple prodfournprice and qty only (later we will search on triplet qty/product_id/fourn_ref)