Render percentage discounts in configured locale (#3114)

This commit is contained in:
Jeroen Peelaerts
2021-04-06 15:21:51 +02:00
committed by jekkos
parent b400223c57
commit dfd19c38f2
13 changed files with 17 additions and 17 deletions

View File

@@ -5,6 +5,7 @@ const DEFAULT_LANGUAGE_CODE = 'en-US';
define('NOW', time());
define('MAX_PRECISION', 1e14);
define('DEFAULT_PRECISION', 2);
define('DEFAULT_DATE', mktime(0, 0, 0, 1, 1, 2010));
define('DEFAULT_DATETIME', mktime(0, 0, 0, 1, 1, 2010));
@@ -386,7 +387,7 @@ function to_quantity_decimals($number)
return to_decimals($number, 'quantity_decimals');
}
function to_decimals($number, $decimals, $type=\NumberFormatter::DECIMAL)
function to_decimals($number, $decimals=NULL, $type=\NumberFormatter::DECIMAL)
{
// ignore empty strings and return
// NOTE: do not change it to empty otherwise tables will show a 0 with no decimal nor currency symbol
@@ -397,8 +398,9 @@ function to_decimals($number, $decimals, $type=\NumberFormatter::DECIMAL)
$config = get_instance()->config;
$fmt = new \NumberFormatter($config->item('number_locale'), $type);
$fmt->setAttribute(\NumberFormatter::MIN_FRACTION_DIGITS, $config->item($decimals));
$fmt->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, $config->item($decimals));
$fmt->setAttribute(\NumberFormatter::MIN_FRACTION_DIGITS, 0);
$fmt->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, empty($decimals) ? DEFAULT_PRECISION : $config->item($decimals));
if(empty($config->item('thousands_separator')))
{
$fmt->setAttribute(\NumberFormatter::GROUPING_SEPARATOR_SYMBOL, '');
@@ -446,8 +448,6 @@ function parse_decimals($number, $decimals = NULL)
$fmt = new \NumberFormatter($config->item('number_locale'), \NumberFormatter::DECIMAL);
$fmt->setAttribute(\NumberFormatter::FRACTION_DIGITS, $decimals);
if(empty($config->item('thousands_separator')))
{
$fmt->setAttribute(\NumberFormatter::GROUPING_SEPARATOR_SYMBOL, '');

View File

@@ -167,7 +167,7 @@ if (isset($success))
?>
<td>
<div class="input-group">
<?php echo form_input(array('name'=>'discount', 'class'=>'form-control input-sm', 'value'=>$item['discount_type'] ? to_currency_no_money($item['discount']) : to_decimals($item['discount'], 0), 'onClick'=>'this.select();')); ?>
<?php echo form_input(array('name'=>'discount', 'class'=>'form-control input-sm', 'value'=>$item['discount_type'] ? to_currency_no_money($item['discount']) : to_decimals($item['discount']), 'onClick'=>'this.select();')); ?>
<span class="input-group-btn">
<?php echo form_checkbox(array('id'=>'discount_toggle', 'name'=>'discount_toggle', 'value'=>1, 'data-toggle'=>"toggle",'data-size'=>'small', 'data-onstyle'=>'success', 'data-on'=>'<b>'.$this->config->item('currency_symbol').'</b>', 'data-off'=>'<b>%</b>', 'data-line'=>$line, 'checked'=>$item['discount_type'])); ?>
</span>

View File

@@ -139,7 +139,7 @@ $(document).ready(function()
<td class="item-name"><?php echo ($item['is_serialized'] || $item['allow_alt_description']) && !empty($item['description']) ? $item['description'] : $item['name'] . ' ' . $item['attribute_values']; ?></td>
<td style='text-align:center;'><?php echo to_quantity_decimals($item['quantity']); ?></td>
<td><?php echo to_currency($item['price']); ?></td>
<td style='text-align:center;'><?php echo ($item['discount_type']==FIXED)?to_currency($item['discount']):$item['discount'] . '%';?></td>
<td style='text-align:center;'><?php echo ($item['discount_type']==FIXED)?to_currency($item['discount']):to_decimals($item['discount']) . '%';?></td>
<?php if($discount > 0): ?>
<td style='text-align:center;'><?php echo to_currency($item['discounted_total'] / $item['quantity']); ?></td>
<?php endif; ?>

View File

@@ -92,7 +92,7 @@ if(isset($error_message))
<td class="item-name"><?php echo $item['name']; ?></td>
<td><?php echo to_quantity_decimals($item['quantity']); ?></td>
<td><?php echo to_currency($item['price']); ?></td>
<td><?php echo ($item['discount_type']==FIXED)?to_currency($item['discount']):$item['discount'] . '%';?></td>
<td><?php echo ($item['discount_type']==FIXED)?to_currency($item['discount']):to_decimals($item['discount']) . '%';?></td>
<?php if ($item['discount'] > 0): ?>
<td><?php echo to_currency($item['discounted_total'] / $item['quantity']); ?></td>
<?php endif; ?>

View File

@@ -127,7 +127,7 @@ if (isset($error_message))
<td class="item-name"><?php echo $item['name']; ?></td>
<td style='text-align:center;'><?php echo to_quantity_decimals($item['quantity']); ?></td>
<td><?php echo to_currency($item['price']); ?></td>
<td style='text-align:center;'><?php echo ($item['discount_type']==FIXED)?to_currency($item['discount']):$item['discount'] . '%';?></td>
<td style='text-align:center;'><?php echo ($item['discount_type']==FIXED)?to_currency($item['discount']):to_decimals($item['discount']) . '%';?></td>
<?php if($discount > 0): ?>
<td style='text-align:center;'><?php echo to_currency($item['discounted_total'] / $item['quantity']); ?></td>
<?php endif; ?>

View File

@@ -95,7 +95,7 @@
<td class="item-name"><?php echo $item['name']; ?></td>
<td><?php echo to_quantity_decimals($item['quantity']); ?></td>
<td><?php echo to_currency($item['price']); ?></td>
<td><?php echo ($item['discount_type']==FIXED)?to_currency($item['discount']):$item['discount'] . '%';?></td>
<td><?php echo ($item['discount_type']==FIXED)?to_currency($item['discount']):to_decimals($item['discount']) . '%';?></td>
<?php if($discount > 0): ?>
<td><?php echo to_currency($item['discounted_total'] / $item['quantity']); ?></td>
<?php endif; ?>

View File

@@ -118,7 +118,7 @@
elseif($item['discount_type'] == PERCENT)
{
?>
<td colspan="3" class="discount"><?php echo number_format($item['discount'], 0) . " " . $this->lang->line("sales_discount_included") ?></td>
<td colspan="3" class="discount"><?php echo to_decimals($item['discount']) . " " . $this->lang->line("sales_discount_included") ?></td>
<?php
}
?>

View File

@@ -96,7 +96,7 @@
elseif($item['discount_type'] == PERCENT)
{
?>
<td colspan="3" class="discount"><?php echo number_format($item['discount'], 0) . " " . $this->lang->line("sales_discount_included") ?></td>
<td colspan="3" class="discount"><?php echo to_decimals($item['discount']) . " " . $this->lang->line("sales_discount_included") ?></td>
<?php
}
?>

View File

@@ -98,7 +98,7 @@
elseif($item['discount_type'] == PERCENT)
{
?>
<td colspan="2" class="discount"><?php echo number_format($item['discount'], 0) . " " . $this->lang->line("sales_discount_included") ?></td>
<td colspan="2" class="discount"><?php echo to_decimals($item['discount']) . " " . $this->lang->line("sales_discount_included") ?></td>
<?php
}
?>

View File

@@ -195,7 +195,7 @@ if(isset($success))
<td>
<div class="input-group">
<?php echo form_input(array('name'=>'discount', 'class'=>'form-control input-sm', 'value'=>$item['discount_type'] ? to_currency_no_money($item['discount']) : to_decimals($item['discount'], 0), 'tabindex'=>++$tabindex, 'onClick'=>'this.select();')); ?>
<?php echo form_input(array('name'=>'discount', 'class'=>'form-control input-sm', 'value'=>$item['discount_type'] ? to_currency_no_money($item['discount']) : to_decimals($item['discount']), 'tabindex'=>++$tabindex, 'onClick'=>'this.select();')); ?>
<span class="input-group-btn">
<?php echo form_checkbox(array('id'=>'discount_toggle', 'name'=>'discount_toggle', 'value'=>1, 'data-toggle'=>"toggle",'data-size'=>'small', 'data-onstyle'=>'success', 'data-on'=>'<b>'.$this->config->item('currency_symbol').'</b>', 'data-off'=>'<b>%</b>', 'data-line'=>$line, 'checked'=>$item['discount_type'])); ?>
</span>

View File

@@ -139,7 +139,7 @@ $(document).ready(function()
<td class="item-name"><?php echo $item['name']; ?></td>
<td style='text-align:center;'><?php echo to_quantity_decimals($item['quantity']); ?></td>
<td><?php echo to_currency($item['price']); ?></td>
<td style='text-align:center;'><?php echo $item['discount'] . '%'; ?></td>
<td style='text-align:center;'><?php echo ($item['discount_type']==FIXED)?to_currency($item['discount']):to_decimals($item['discount']) . '%';?></td>
<?php if($discount > 0): ?>
<td style='text-align:center;'><?php echo to_currency($item['discounted_total'] / $item['quantity']); ?></td>
<?php endif; ?>

View File

@@ -123,7 +123,7 @@ if(isset($error_message))
<td class="item-name"><?php echo $item['name']; ?></td>
<td style='text-align:center;'><?php echo to_quantity_decimals($item['quantity']); ?></td>
<td><?php if($print_price_info) echo to_currency($item['price']); ?></td>
<td style='text-align:center;'><?php echo ($item['discount_type']==FIXED)?to_currency($item['discount']):$item['discount'] . '%';?></td>
<td style='text-align:center;'><?php echo ($item['discount_type']==FIXED)?to_currency($item['discount']):to_decimals($item['discount']) . '%';?></td>
<td style='border-right: solid 1px; text-align:right;'><?php if($print_price_info) echo to_currency($item['discounted_total']); ?></td>
</tr>

View File

@@ -84,7 +84,7 @@
<td class="item-name"><?php echo $item['name']; ?></td>
<td><?php echo to_quantity_decimals($item['quantity']); ?></td>
<td><?php echo to_currency($item['price']); ?></td>
<td><?php echo ($item['discount_type']==FIXED)?to_currency($item['discount']):$item['discount'] . '%';?></td>
<td><?php echo ($item['discount_type']==FIXED)?to_currency($item['discount']):to_decimals($item['discount']) . '%';?></td>
<td class="total-line"><?php echo to_currency($item['discounted_total']); ?></td>
</tr>
<?php