';
print '';
}
diff --git a/htdocs/product/admin/price_rules.php b/htdocs/product/admin/price_rules.php
index 5b5743a742b..a38245d32c7 100644
--- a/htdocs/product/admin/price_rules.php
+++ b/htdocs/product/admin/price_rules.php
@@ -15,8 +15,8 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*
- * Page to set how to autocalculate price for each level when option
- * PRODUCT_MULTIPRICE is on.
+ * Page to set how to autocalculate price for each level when option PRODUCT_MULTIPRICE is on.
+ * This page is a tab in the setup of module Product if option PRODUIT_MULTIPRICES_ALLOW_AUTOCALC_PRICELEVEL is set.
*/
require '../../main.inc.php';
@@ -32,6 +32,8 @@ $action = GETPOST('action', 'aZ09');
if (!$user->admin || (empty($conf->product->enabled) && empty($conf->service->enabled)))
accessforbidden();
+$error = 0;
+
/**
* Actions
@@ -55,6 +57,7 @@ if ($action == 'update') {
$i_var_percent = 0;
+ // Set $i_var_percent, the percent of price for level compared to an other level
if ($i != 1) {
$i_var_percent = (float) price2num($var_percent[$i]);
}
@@ -67,15 +70,12 @@ if ($action == 'update') {
$check2 = $i_var_min_percent;
} else {
$check1 = $i_fk_level >= 1 && $i_fk_level <= $conf->global->PRODUIT_MULTIPRICES_LIMIT;
- $check2 = $i_var_percent && $i_var_min_percent;
+ $check2 = $i_var_percent && ($i_var_min_percent || (string) $i_var_min_percent === '0');
}
- if (!$check1 || !$check2) {
+ if (empty($i_var_percent) && empty($i_var_min_percent)) {
//If the level is between range but percent fields are empty, then we ensure it does not exist in DB
- if ($check1) {
- $db->query("DELETE FROM ".MAIN_DB_PREFIX."product_pricerules WHERE level = ".((int) $i));
- }
-
+ $db->query("DELETE FROM ".MAIN_DB_PREFIX."product_pricerules WHERE level = ".((int) $i));
continue;
}
@@ -89,11 +89,14 @@ if ($action == 'update') {
if (!$db->query($sql)) {
setEventMessages($langs->trans('ErrorSavingChanges'), null, 'errors');
+ $error++;
}
}
}
- setEventMessages($langs->trans("RecordSaved"), null, 'mesgs');
+ if (!$error) {
+ setEventMessages($langs->trans("RecordSaved"), null, 'mesgs');
+ }
}
@@ -133,32 +136,19 @@ print '';
print '';
$head = product_admin_prepare_head();
-print dol_get_fiche_head($head, 'generator', $tab, 0, 'product');
+print dol_get_fiche_head($head, 'generator', $tab, -1, 'product');
-print $langs->trans("MultiPriceRuleDesc").'