diff --git a/htdocs/product/admin/price_rules.php b/htdocs/product/admin/price_rules.php
index 64fa982fff1..e284572e7e7 100644
--- a/htdocs/product/admin/price_rules.php
+++ b/htdocs/product/admin/price_rules.php
@@ -52,10 +52,10 @@ if ($_POST) {
continue;
}
+ $i_var_percent = 0;
+
if ($i != 1) {
$i_var_percent = (float) price2num($var_percent[$i]);
- } else {
- $i_var_percent = 0;
}
$i_var_min_percent = (float) price2num($var_min_percent[$i]);
@@ -72,15 +72,15 @@ if ($_POST) {
if (!$check1 || !$check2) {
//If the level is between range but percent fields are empty, then we ensure it does not exist in DB
- if ($check1 && !$check2) {
+ if ($check1) {
$db->query("DELETE FROM ".MAIN_DB_PREFIX."product_pricerules WHERE level = ".(int) $i);
}
continue;
}
- $sql = "INSERT INTO ".MAIN_DB_PREFIX."product_pricerules
- SET level = ".(int) $i.", fk_level = ".$db->escape($i_fk_level).", var_percent = ".$i_var_percent.", var_min_percent = ".$i_var_min_percent;
+ $sql = "INSERT INTO ".MAIN_DB_PREFIX."product_pricerules (level, fk_level, var_percent, var_min_percent) VALUES (
+ ".(int) $i.", ".$db->escape($i_fk_level).", ".$i_var_percent.", ".$i_var_min_percent.")";
if (!$db->query($sql)) {
@@ -166,7 +166,7 @@ $genPriceOptions = function($level) use ($price_options) {
| trans('SellingPrice') ?> 1 |
|
- trans('PercentDiscountOver', $langs->trans('SellingPrice').' 1') ?> |
+ trans('PercentDiscountOver', $langs->trans('SellingPrice').' 1') ?> |
global->PRODUIT_MULTIPRICES_LIMIT; $i++): ?>
@@ -179,11 +179,11 @@ $genPriceOptions = function($level) use ($price_options) {
?>
|
-
+
trans('PercentVariationOver', Form::selectarray("fk_level[$i]", $genPriceOptions($i), (isset($rules[$i]) ? $rules[$i]->fk_level : null))) ?>
|
-
+
trans('PercentDiscountOver', $langs->trans('SellingPrice').' '.$i) ?>
|
diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php
index 90b7f3cd994..66fe6edb19a 100644
--- a/htdocs/product/class/product.class.php
+++ b/htdocs/product/class/product.class.php
@@ -4108,13 +4108,12 @@ class Product extends CommonObject
for ($i = 1; $i <= $conf->global->PRODUIT_MULTIPRICES_LIMIT; $i++) {
$price = $baseprice;
- $price_min = 0;
+ $price_min = $baseprice;
- if ($i > 1) {
- //We have to make sure it does exist and it is > 0
- if (isset($rules[$i]->var_percent) && $rules[$i]->var_percent) {
- $price = $prices[$rules[$i]->fk_level] * (1 + ($rules[$i]->var_percent/100));
- }
+ //We have to make sure it does exist and it is > 0
+ //First price level only allows changing min_price
+ if ($i > 1 && isset($rules[$i]->var_percent) && $rules[$i]->var_percent) {
+ $price = $prices[$rules[$i]->fk_level] * (1 + ($rules[$i]->var_percent/100));
}
$prices[$i] = $price;
diff --git a/htdocs/product/price.php b/htdocs/product/price.php
index b6cf03fc837..cfdcfd33db7 100644
--- a/htdocs/product/price.php
+++ b/htdocs/product/price.php
@@ -194,7 +194,7 @@ if (empty($reshook))
$newlocaltax2_type = GETPOST('localtax2_type', 'array');
//Shall we generate prices using price rules?
- $object->price_autogen = GETPOST('usePriceRules') == 'on' ? true : false;
+ $object->price_autogen = GETPOST('usePriceRules') == 'on';
for ($i = 1; $i <= $conf->global->PRODUIT_MULTIPRICES_LIMIT; $i ++)
{