Merge pull request #10997 from altairis-tof/packbuyprice

NEW : use subproducts costprice and pmp if empty on father
This commit is contained in:
Laurent Destailleur 2022-01-23 19:54:06 +01:00 committed by GitHub
commit da4f139f48
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -95,11 +95,39 @@ if ($idprod > 0) {
if (!empty($conf->stock->enabled)) {
// Add price for pmp
$price = $producttmp->pmp;
$prices[] = array("id" => 'pmpprice', "price" => price2num($price), "label" => $langs->trans("PMPValueShort").': '.price($price, 0, $langs, 0, 0, -1, $conf->currency), "title" => $langs->trans("PMPValueShort").': '.price($price, 0, $langs, 0, 0, -1, $conf->currency)); // For price field, we must use price2num(), for label or title, price()
if (empty($price) && !empty($conf->global->PRODUCT_USE_SUB_COST_PRICES_IF_COST_PRICE_EMPTY)) {
// get pmp for subproducts if any
$producttmp->get_sousproduits_arbo();
$prods_arbo=$producttmp->get_arbo_each_prod();
if (!empty($prods_arbo)) {
$price = 0;
foreach ($prods_arbo as $child) {
$sousprod = new Product($db);
$sousprod->fetch($child['id']);
$price += $sousprod->pmp;
}
}
}
$prices[] = array("id" => 'pmpprice', "price" => price2num($price), "label" => $langs->trans("PMPValueShort").': '.price($price, 0, $langs, 0, 0, -1, $conf->currency), "title" => $langs->trans("PMPValueShort").': '.price($price, 0, $langs, 0, 0, -1, $conf->currency)); // For price field, we must use price2num(), for label or title, price()
}
// Add price for costprice (at end)
$price = $producttmp->cost_price;
if (empty($price) && ! empty($conf->global->PRODUCT_USE_SUB_COST_PRICES_IF_COST_PRICE_EMPTY)) {
// get costprice for subproducts if any
$producttmp->get_sousproduits_arbo();
$prods_arbo=$producttmp->get_arbo_each_prod();
if (!empty($prods_arbo)) {
$price = 0;
foreach ($prods_arbo as $child) {
$sousprod = new Product($db);
$sousprod->fetch($child['id']);
$price += $sousprod->cost_price;
}
}
}
$prices[] = array("id" => 'costprice', "price" => price2num($price), "label" => $langs->trans("CostPrice").': '.price($price, 0, $langs, 0, 0, -1, $conf->currency), "title" => $langs->trans("PMPValueShort").': '.price($price, 0, $langs, 0, 0, -1, $conf->currency)); // For price field, we must use price2num(), for label or title, price()
}