Author Topic: add decimal quantity of product to cart  (Read 17520 times)

maikee

  • Beginner
  • *
  • Posts: 2
add decimal quantity of product to cart
« on: January 03, 2010, 20:00:04 pm »
Hello,
i need to put to cart decimal quantity of some product (eg 1,7 kg of Carrot). If I put there 1.7 into Add to cart form - it changes to 1 on next page. If put 1,7 - it asks to insert valid data.

How and where can I change the code to have decimal amounts? And not to change inserted value into integer values?

If I change the value directly in database - everything works fine. The problem is just inserting the number.
Thank You very much for help.

maikee

  • Beginner
  • *
  • Posts: 2
Re: add decimal quantity of product to cart
« Reply #1 on: January 04, 2010, 15:05:10 pm »
So i found out.
Need to change:
1) data type in database virtuemart - product - quantity - from integer to decimal (12,2)
2) cancel inval($quantity) in ps_cart.php and put round($quantity,2) instead
3) cancel (int)($quantity) in the same file somewhere  at row 296


rolevine

  • Beginner
  • *
  • Posts: 2
Re: add decimal quantity of product to cart
« Reply #2 on: April 15, 2010, 22:36:37 pm »
For 1.1.4 I did the following:

1. In sql table jos_vm_order_item, changed product_quantity to decimal(12,2) from int(11)
2. In ps_cart.php, changed the following:
  A. $total_quantity = 0; => $total_quantity = 0.0;
  B. $quantity = intval($quantity); => $quantity = round($quantity, 2);
  C. } elseif( $total_quantity == 0 ) { => } elseif( round($total_quantity) == 0 ) {
  D. if ($quantity == 0 && strtolower($func) == "cartupdate") { => if (round($quantity) == 0 && strtolower($func) == "cartupdate") {
  E. if ($quantity == 0) { => if (round($quantity) == 0) {

Regards,
Rob

P.S. Fwiw, I really think Virtuemart should implement this as a feature rather than a hack.  I've seen this same request in numerous forum posts.

phoebeb

  • Beginner
  • *
  • Posts: 3
Re: add decimal quantity of product to cart
« Reply #3 on: April 19, 2010, 22:13:32 pm »
I need to implement this hack. Can you give me a walk-through? In other words, where would I find the sql table etc, etc. I'm a verrrrry newbie. Phoebe

Phelan

  • Beginner
  • *
  • Posts: 30
Re: add decimal quantity of product to cart
« Reply #4 on: January 21, 2011, 11:04:19 am »
This function should be implemented since first Version, all other Shop products are able to handle decimal quantity.

I applied a hack in a shop. after upgrade function was lost and its not fun to to this all the time manually.

pelucre

  • Beginner
  • *
  • Posts: 7
Re: add decimal quantity of product to cart
« Reply #5 on: April 03, 2011, 14:56:35 pm »
Thanks for this tip

I followed the instructions for 1.1.4 and it works correctly for the 1.1.8 but there's an error that appears when  you add a decimal quantity with a product already in the cart.

For example : 1.5+1.5 =2.5 instead of 3.

have you found a solution ?

tj1771

  • Beginner
  • *
  • Posts: 1
Re: add decimal quantity of product to cart
« Reply #6 on: August 25, 2011, 19:08:58 pm »
It works correctly (1.5+1.5 =2.5) when you change in C:\xampp\htdocs\joomla\administrator\components\com_virtuemart\classes\ps_cart.php

$quantity = isset($d["quantity"]) ? (int)$d["quantity"] : 1;  =>   $quantity = isset($d["quantity"]) ? (float)$d["quantity"] : 1;

cuevision

  • Beginner
  • *
  • Posts: 22
Re: add decimal quantity of product to cart
« Reply #7 on: November 04, 2011, 20:23:43 pm »
Hi.

Please could you be of any help for me too?

As you can see on the attached images of the VM backend, I am strugglin wit the Decimals overthere. I have been searching for weeks, placed it on several forums, without any luck. As you know much about decimals, I hope you can help.

I like to have the notation like this €23.05 and not € 23,05335 or € 23,0533 but only two digits/ciphers

Thanks and regards,
Ed

[attachment cleanup by admin]

amet123

  • Beginner
  • *
  • Posts: 47
  • Amit Vaid
    • Gap Solution
Re: add decimal quantity of product to cart
« Reply #8 on: November 18, 2011, 10:11:06 am »
hi

but when i check invoice and total value show round figer


[attachment cleanup by admin]
Amit Vaid

Gap Solution
Web Development

Sammy

  • Beginner
  • *
  • Posts: 17
Re: add decimal quantity of product to cart
« Reply #9 on: September 28, 2012, 15:49:34 pm »
amet123 did you find a solution? Because I get an email saying 2 meter instead of 2.2. :(

amet123

  • Beginner
  • *
  • Posts: 47
  • Amit Vaid
    • Gap Solution
Re: add decimal quantity of product to cart
« Reply #10 on: September 29, 2012, 10:33:00 am »
Yes i done with some changes in code check it out buy subzi (dot) com In Joomla 1.5
Amit Vaid

Gap Solution
Web Development

Sammy

  • Beginner
  • *
  • Posts: 17
Re: add decimal quantity of product to cart
« Reply #11 on: November 23, 2012, 13:54:07 pm »
Do you know how to get 1.00 in stead of just 1 to show in the quantity box? Because I would like the people to know that they can order in decimals!

I did try to edit quantity_box_general.tpl.php but no succes yet...



[attachment cleanup by admin]