问题
my client want to be able to buy products with decimal quantity, like 1.5 or 3.5, is there any way to codeigniter’s Shopping Cart class can handle this?
Because right now if i try to put and decimal quantity it remover the comas, exemple, if i type 1.5, it goes as 15.
Thanks for the attention
EDIT: I FIXED IT BY GOING TO 'SYSTEM\LIBRARIES\CART.PHP' AND CHANGING THE LINE 161:
from this:
$items['qty'] = trim(preg_replace('/([^0-9])/i', '', $items['qty']));
to this:
$items['qty'] = trim(preg_replace('/([^0-9\.])/i', '', $items['qty']));
Doing this, you can add decimals on quantity.
回答1:
Are you using any kind of database for that shopping cart. I've created a shopping cart using codeigniter and have never had problems like that. If anything, you must set the proper field type in your DB for price - which I use decimal field type.
回答2:
Try extending the Cart library. Read more here:
http://forrst.com/posts/Extending_the_codeigniter_cart_library-NXv
来源:https://stackoverflow.com/questions/17754145/decimal-quantity-in-codeigniters-shopping-cart