Fixes a little problem with multiprice rules, now undefined ones evaluate to 0% variation
This commit is contained in:
parent
9865b0daa3
commit
d43d0bfec1
@ -52,10 +52,10 @@ if ($_POST) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$i_var_percent = 0;
|
||||||
|
|
||||||
if ($i != 1) {
|
if ($i != 1) {
|
||||||
$i_var_percent = (float) price2num($var_percent[$i]);
|
$i_var_percent = (float) price2num($var_percent[$i]);
|
||||||
} else {
|
|
||||||
$i_var_percent = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$i_var_min_percent = (float) price2num($var_min_percent[$i]);
|
$i_var_min_percent = (float) price2num($var_min_percent[$i]);
|
||||||
@ -72,15 +72,15 @@ if ($_POST) {
|
|||||||
if (!$check1 || !$check2) {
|
if (!$check1 || !$check2) {
|
||||||
|
|
||||||
//If the level is between range but percent fields are empty, then we ensure it does not exist in DB
|
//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);
|
$db->query("DELETE FROM ".MAIN_DB_PREFIX."product_pricerules WHERE level = ".(int) $i);
|
||||||
}
|
}
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."product_pricerules
|
$sql = "INSERT INTO ".MAIN_DB_PREFIX."product_pricerules (level, fk_level, var_percent, var_min_percent) VALUES (
|
||||||
SET level = ".(int) $i.", fk_level = ".$db->escape($i_fk_level).", var_percent = ".$i_var_percent.", var_min_percent = ".$i_var_min_percent;
|
".(int) $i.", ".$db->escape($i_fk_level).", ".$i_var_percent.", ".$i_var_min_percent.")";
|
||||||
|
|
||||||
if (!$db->query($sql)) {
|
if (!$db->query($sql)) {
|
||||||
|
|
||||||
@ -166,7 +166,7 @@ $genPriceOptions = function($level) use ($price_options) {
|
|||||||
<tr>
|
<tr>
|
||||||
<td class="fieldrequired" style="text-align: center"><?php echo $langs->trans('SellingPrice') ?> 1</td>
|
<td class="fieldrequired" style="text-align: center"><?php echo $langs->trans('SellingPrice') ?> 1</td>
|
||||||
<td></td>
|
<td></td>
|
||||||
<td style="text-align: center"><input type="text" style="text-align: right" name="var_min_percent[1]" size="5" value="<?php echo isset($rules[1]) ? price($rules[1]->var_min_percent, 2) : '' ?>"> <?php echo $langs->trans('PercentDiscountOver', $langs->trans('SellingPrice').' 1') ?></td>
|
<td style="text-align: center"><input type="text" style="text-align: right" name="var_min_percent[1]" size="5" value="<?php echo price(isset($rules[1]) ? $rules[1]->var_min_percent : 0, 2) ?>"> <?php echo $langs->trans('PercentDiscountOver', $langs->trans('SellingPrice').' 1') ?></td>
|
||||||
</tr>
|
</tr>
|
||||||
<?php for ($i = 2; $i <= $conf->global->PRODUIT_MULTIPRICES_LIMIT; $i++): ?>
|
<?php for ($i = 2; $i <= $conf->global->PRODUIT_MULTIPRICES_LIMIT; $i++): ?>
|
||||||
<tr>
|
<tr>
|
||||||
@ -179,11 +179,11 @@ $genPriceOptions = function($level) use ($price_options) {
|
|||||||
?>
|
?>
|
||||||
</td>
|
</td>
|
||||||
<td style="text-align: center">
|
<td style="text-align: center">
|
||||||
<input type="text" style="text-align: right" name="var_percent[<?php echo $i ?>]" size="5" value="<?php echo isset($rules[$i]) ? price($rules[$i]->var_percent, 2) : '' ?>">
|
<input type="text" style="text-align: right" name="var_percent[<?php echo $i ?>]" size="5" value="<?php echo price(isset($rules[$i]) ? $rules[$i]->var_percent : 0, 2) ?>">
|
||||||
<?php echo $langs->trans('PercentVariationOver', Form::selectarray("fk_level[$i]", $genPriceOptions($i), (isset($rules[$i]) ? $rules[$i]->fk_level : null))) ?>
|
<?php echo $langs->trans('PercentVariationOver', Form::selectarray("fk_level[$i]", $genPriceOptions($i), (isset($rules[$i]) ? $rules[$i]->fk_level : null))) ?>
|
||||||
</td>
|
</td>
|
||||||
<td style="text-align: center">
|
<td style="text-align: center">
|
||||||
<input type="text" style="text-align: right" name="var_min_percent[<?php echo $i ?>]" size="5" value="<?php echo isset($rules[$i]) ? price($rules[$i]->var_min_percent, 2) : '' ?>">
|
<input type="text" style="text-align: right" name="var_min_percent[<?php echo $i ?>]" size="5" value="<?php echo price(isset($rules[$i]) ? $rules[$i]->var_min_percent : 0, 2) ?>">
|
||||||
<?php echo $langs->trans('PercentDiscountOver', $langs->trans('SellingPrice').' '.$i) ?>
|
<?php echo $langs->trans('PercentDiscountOver', $langs->trans('SellingPrice').' '.$i) ?>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|||||||
@ -4108,14 +4108,13 @@ class Product extends CommonObject
|
|||||||
for ($i = 1; $i <= $conf->global->PRODUIT_MULTIPRICES_LIMIT; $i++) {
|
for ($i = 1; $i <= $conf->global->PRODUIT_MULTIPRICES_LIMIT; $i++) {
|
||||||
|
|
||||||
$price = $baseprice;
|
$price = $baseprice;
|
||||||
$price_min = 0;
|
$price_min = $baseprice;
|
||||||
|
|
||||||
if ($i > 1) {
|
|
||||||
//We have to make sure it does exist and it is > 0
|
//We have to make sure it does exist and it is > 0
|
||||||
if (isset($rules[$i]->var_percent) && $rules[$i]->var_percent) {
|
//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));
|
$price = $prices[$rules[$i]->fk_level] * (1 + ($rules[$i]->var_percent/100));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
$prices[$i] = $price;
|
$prices[$i] = $price;
|
||||||
|
|
||||||
|
|||||||
@ -194,7 +194,7 @@ if (empty($reshook))
|
|||||||
$newlocaltax2_type = GETPOST('localtax2_type', 'array');
|
$newlocaltax2_type = GETPOST('localtax2_type', 'array');
|
||||||
|
|
||||||
//Shall we generate prices using price rules?
|
//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 ++)
|
for ($i = 1; $i <= $conf->global->PRODUIT_MULTIPRICES_LIMIT; $i ++)
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user