Decimal quantity in Codeigniter's Shopping Cart?

久未见 提交于 2019-12-12 02:07:49

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!