35 lines
714 B
PHP
35 lines
714 B
PHP
<?php
|
|
// includes/quantity_helper.php
|
|
|
|
if (!function_exists('quantity_precision')) {
|
|
function quantity_precision(): int
|
|
{
|
|
return 2;
|
|
}
|
|
}
|
|
|
|
if (!function_exists('quantity_step')) {
|
|
function quantity_step(): string
|
|
{
|
|
return '0.01';
|
|
}
|
|
}
|
|
|
|
if (!function_exists('normalize_quantity')) {
|
|
function normalize_quantity($value): float
|
|
{
|
|
if ($value === null || $value === '') {
|
|
return 0.0;
|
|
}
|
|
|
|
return round((float)$value, quantity_precision());
|
|
}
|
|
}
|
|
|
|
if (!function_exists('format_quantity')) {
|
|
function format_quantity($value): string
|
|
{
|
|
return number_format(normalize_quantity($value), quantity_precision(), '.', '');
|
|
}
|
|
}
|