Cent value is gone away after saving (at admin order)
humble92 opened this issue · comments
Describe the bug
After adding new products in admin order page, cent value is deleted.
To Reproduce
/order/detail/
Add product with cent value
Expected behavior
Cent value should be kept
In the above capture:
1st row: the result after saving
2nd row: the exact price of the above product (before saving)
Total/Subtotal page has the same problem.
Additional context
commit 087099d (HEAD -> master, tag: v6.0.5, origin/master, origin/HEAD)
Merge: 48d4933 c7dd3fc
I found one of the reasons. DB cannot support USD because of their type. It needs to be corrected. After that it is still needed to accept/handle/present decimal value at UI level.
These queries are what can be fixed in DB schema:
ALTER TABLE sc_shop_product
CHANGE price
price
DECIMAL(7,2) NOT NULL DEFAULT '0', CHANGE cost
cost
DECIMAL(7,2) NOT NULL DEFAULT '0';
ALTER TABLE sc_shop_order_detail
CHANGE price
price
DECIMAL(7,2) NOT NULL DEFAULT '0', CHANGE total_price
total_price
DECIMAL(7,2) NOT NULL DEFAULT '0';
ALTER TABLE sc_shop_order
CHANGE subtotal
subtotal
DECIMAL(7,2) NULL DEFAULT '0', CHANGE discount
discount
DECIMAL(7,2) NULL DEFAULT '0', CHANGE tax
tax
DECIMAL(7,2) NULL DEFAULT '0', CHANGE total
total
DECIMAL(7,2) NULL DEFAULT '0', CHANGE received
received
DECIMAL(7,2) NULL DEFAULT '0', CHANGE balance
balance
DECIMAL(7,2) NULL DEFAULT '0';
If you are pleased, could you add them into DB migration?
e.g. sc_tax_price:
This function should be more flexible according to currency setting in admin page. I guess such as
$price = $price * (100 + $tax) /100;
$price = number_format((float)$price, THE_GENETATED_VALUE_FROM_CURRENCY_SETTING, '.', ''); // can be 100 or 100.50
/*
Return price with tax
*/
if (!function_exists('sc_tax_price')) {
function sc_tax_price($price, $tax)
{
return floor($price * (100 + $tax) /100);
}
}
Finally found out sc_currency_format, but not easy to override ShopCurrency::precision, which is hard-coded now. It should be set from admin currency setting, I guess.
$price = sc_currency_format($price * (100 + $tax) /100);
return $price;
Currently S-Cart calculations only support integers :)
Thanks for the clarification. I hope that to be updated soon.
Can I ask one thing to you? To accept float value here, which part should be modified?
It is a little bit difficult for me to find that out. The code snippet below seems not a proper place.
Never mind. Found it.
Thanks a lot.
$('.edit-item-detail').editable({
type: "number",
min: 0,
step: 0.1,
ajaxOptions: {
type: 'post',
dataType: 'json'
},
validate: function(value) {
if (value == '') {
return '{{ trans('admin.not_empty') }}';
}
if (!$.isNumeric(value)) {
return '{{ trans('admin.only_numeric') }}';
}
},
success: function(response,newValue) {
if(response.error ==0){
$('.data-shipping').html(response.detail.shipping);
$('.data-received').html(response.detail.received);
$('.data-subtotal').html(response.detail.subtotal);
$('.data-tax').html(response.detail.tax);
$('.data-total').html(response.detail.total);
$('.data-shipping').html(response.detail.shipping);
$('.data-discount').html(response.detail.discount);
$('.item_id_'+response.detail.item_id).html(response.detail.item_total_price);
var objblance = $('.data-balance').eq(0);
objblance.before(response.detail.balance);
objblance.remove();
alertJs('success', response.msg);
} else {
alertJs('error', response.msg);
}
}
});