Preventing decimals in quantity field
I have a shopping cart that sells items in bags of 50. If you need more than 50, you simply buy another bag.
My calculations work by multiplying the (bag qty) x (qty in bag) x (individual price). All works fine, but a customer figured out a way to buy 60 by entering 1.2 in the quantity.
I found one solution in a previous thread where Ray recommended changing floatval to intval for the $itemQuantity in the eCart object. This worked great but if I open and edit the eCart object interface at a later date, it resets the intval back to floatval. If I forget to go back and manually change it again, then we have the same issue.
Then I thought, why not try using floor() for my qty post value in the Add To Cart behavior. This works fine when adding a product to the cart. Is there any reason I can’t just use this method?
This is what I changed in the ATC behavior.
$ATC_itemQuantity = "".$_POST["eCart1_1_Quantity_Add"] ."";// column binding
$ATC_itemQuantity = "".floor($_POST["eCart1_1_Quantity_Add"]) ."";// column binding
Is this acceptable? I didn’t want to add this to the live site until I was certain it wouldn’t cause some other side affect.