getSellPrice function needs explanation

Hello,
I discovered with ravishment the getSellPrice function in product.class.php but i dont understand what is the pqb parameter and where it comes from.
For instance, the function is called in facture/card.php with a pqb parameter from post, but never found where it is posted.

// Search the correct price into loaded array product_price_by_qty using id of array retrieved into POST['pqp'].
$pqp = (GETPOST('pbq', 'int') ? GETPOST('pbq', 'int') : 0);
$datapriceofproduct = $prod->getSellPrice($mysoc, $object->thirdparty, $pqp);

Furthermore, the function is not used in proposal card neither in order card (why ?).
I want to use this function in external module but i see that there is a test on this pqb feature that will leads to an empty price return if pqb is empty.

if ($priceforthequantityarray['rowid'] != $pqp) continue;

Sorry to post here but the dev mailing list is closed and i guess it is the best way to have an answer here by pinging @eldy :wink:

The getSellPrice is designed to get a price depending on the setup.
Among possible setup, you can have different prices per quantity (this is for the moment a hidden option called PRODUIT_CUSTOMER_PRICES_BY_QTY that is not yet fully implemented). With this mode you can have n different prices depending on quantity and this method return the price among the n. pqp is the id into the table that store the different prices per quantity.
When this mode is not enabled (for all stable version), pqp will always be 0. You don’t need it because you will always enter in portion of code that do not use it when using a stable version of dolibarr (The test you mention is inside another test if PRODUIT_CUSTOMER_PRICES_BY_QTY is on).

thanks @eldy for the answer; but for those who has the PRODUIT_CUSTOMER_PRICES_BY_QTY set to 1, it will be difficult to get the actual price from this getSellPrice function if called by external module.

i’ve just done more investigations, and found this pbq/pqb is set by javascript in the objectline_create.tpl.php with a value set in a data-pbq html attribute on the #idprod.

My goal is to have a getSellPrice function that can be called by an external module to easily get the price of a product depending on seller, buyer and configuration.

I was about to make a PR when i discover this getSellPrice function.

Now may i make a PR to get the price even if pbq/pqb is null ? EDIT : it seems difficult to do it

If you set PRODUIT_CUSTOMER_PRICES_BY_QTY to 1, it means you want different prices per quantity. And if you want to get 1 price, you must provide the ID of the one you want. Otherwise, you will get several results.
I’am afraid that if PRODUIT_CUSTOMER_PRICES_BY_QTY is 1, the only solution to get the price is to have the ID. If you don’t have the ID and need to get the list of different prices, another method, a dedicated API, would be better. This method is dedicated to get 1 and only 1 price.

ok thanks @eldy. i will use getSellPrice function anyway, and see later if someone use PRODUIT_CUSTOMER_PRICES_BY_QTY with my modules (relatedproducts and dolitools/updatelines) :wink:

A non-functional requirement will describe how a system should behave and what limits there are on its functionality!

@Gibso1n what do you mean ? do you mean that i should warn that a core unsupported constant is neither supported in my modules ?