16 replies [Last post]
cYu
cYu's picture
Offline
Bug FinderGetting busy with the Ubercode.
Joined: 11/19/2007
Juice: 852
Was this information Helpful?

Does anyone see any value to allowing a quantity such as .5 or 6.25 for cart items? I'm running into a situation where this makes sense, but I'm wondering how horrible of a hack it would take to make that work.

Lyle's picture
Offline
AdministratoreLiTe!
Joined: 08/07/2007
Juice: 6855
Re: Quantity as Decimal

It'd be a pretty major change. First you have to update the database columns, then you have to change the SQL statements to insert the numbers as floats (%f) instead of integers (%d). Then you get into the issue of figuring out just how small a quantity you will allow to be entered. Comparing floats is never exact, especially when one of them is 0.

cYu
cYu's picture
Offline
Bug FinderGetting busy with the Ubercode.
Joined: 11/19/2007
Juice: 852
Re: Re: Quantity as Decimal

Ah...right, I had thought of the database column but not the SQL statement changes. That would be fairly messy. Thanks for the response Lyle, I think I'll avoid this altogether. My alternative isn't going to be as neat of a solution, but I think I should be able to copy cart items and adjust the price so that I can keep all of the quantities at 1 and be fine.

The basic example I want to accommodate is having 2 customers split the cost of 1 product. Having each buy .5 quantity would be a cool way to do this, but instead I'll have each buy 1 product that has the cost split in half.

cYu
cYu's picture
Offline
Bug FinderGetting busy with the Ubercode.
Joined: 11/19/2007
Juice: 852
Re: Re: Re: Quantity as Decimal

Or.....I could divide the price of the product by 100 and switch the quantity label to percent, making the default quantity equal to 100 or allowing a 50/50 split that way. That might end up being a better fit for what I want.

robdinardo's picture
Offline
Joined: 02/01/2009
Juice: 27
a possible suggestion to Ubercart Core

I came up with some changes to Ubercart core to allow for fractional quatities. Have a look at this post: http://www.ubercart.org/issue/6044/abiility_have_decimal_quantities

See attached PDF

AttachmentSize
Ubercart - Fractional Quantities.pdf 110.28 KB
j.mead's picture
Offline
Joined: 07/27/2009
Juice: 385
trying this out gives me...

testing the changes out on a test site brings up this error code:

Fatal error: Unsupported operand types in /xxxxx/18/xxxx/xxxxx/drupal_6/modules/ubercart/uc_order/uc_order.module on line 1459

taken from the module it looks like:

1453 $total += uc_line_items_calculate($order);
1454
1455  foreach (module_list() as $module) {
1456    $function = $module .'_order';
1457    // $order must be passed by reference.
1458    if (function_exists($function) && ($value = $function('total', $order, NULL))) {
1459      $total += $value;
1460    }
1461  }

any ideas from here? edit the uc_order.line_item.inc maybe?
would love to figure these decimals out + avoid the pending divorce (i'm only sort of kidding)
sorry figured i should add some more info to this
Ubercart 6.x-2.0
Drupal 6.14
everything came out up to date on the most recent check

either a whole number or a 1.5 quantity throws up this error.
the price calculated fine and i can ignore weight calculations and do a flate rate for shipping, but i really would love to sell a 1.5 unit, or a 2.5 unit

the sites i'm always breaking.... www.sew-la-fabric.com
http://lostpetsla.com (though i hope i never break this one too bad)

j.mead's picture
Offline
Joined: 07/27/2009
Juice: 385
Re: trying this out gives me...

updated to most recent UC dev. release
made some changes in the integer handling in the stock module and stock.install
changed the database for the stock units
no more errors being thrown at the cart pages
the price reflects the decimal quantity
stock level did not decrease by the decimal amount, it rounded 1.5 to 1
can't put in a decimal stock level yet.

it might help if i knew some php, but it seems to be possible for simple decimal amounts
any guidance or suggestions as to where to go from here would be great.

from the uc_stock.install i see -

85 function uc_stock_update_6000() {
86  $ret = array();
87
88  db_drop_index($ret, 'uc_product_stock', 'nid');
89  db_change_field($ret, 'uc_product_stock', 'nid', 'nid', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0), array('indexes' => array('nid' => array('nid'))));
90  db_change_field($ret, 'uc_product_stock', 'active', 'active', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0));

this seems to need some adjusting, but i'm not sure exactly
once it works than i assume making a module or something would be much easier. it would also be better than changing the core files

the sites i'm always breaking.... www.sew-la-fabric.com
http://lostpetsla.com (though i hope i never break this one too bad)

robdinardo's picture
Offline
Joined: 02/01/2009
Juice: 27
no stock for me

I guess I do not get the error because I do not have the Stock module installed. Thanks for pointing that out!

hjelkris's picture
Offline
Joined: 11/05/2010
Juice: 5
Product quantity changes after checkout

Hi, I tried the changes according to robdinardos pdf. It works like a charm, ALMOST...

I have a meat shop, where I allow customers to buy i.e. 1.2 kg. It looks ok until the user sends the order, then the quantity have changed for all products. When I look in table uc_order_products, it is float, 1.0, but it will never become 1.2.

I think it's something in uc_order.module, but I cannot find the right line to change.

I would highly appreciate your suggestions!

Best Regards

Kristoffer

hjelkris's picture
Offline
Joined: 11/05/2010
Juice: 5
Got it working!

I figured it out after a couple of hours of trial and error... I think it was these lines in order.install that did the trick:

'qty' => array(
'description' => 'The number of the same product ordered.',
'type' => 'float',
'precision' => 6,
'scale' => 1,
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 1.0,

Kristoffer

mstrelan's picture
Offline
Joined: 12/02/2009
Juice: 73
decimal quantities

if it doesnt work for you try my module - http://www.ubercart.org/project/uc_decimal_quantities
you'll have to chnage the first couple lines in the module because it is intended for buying fabric by the meter. just change the words and change 100 to 1000

interactivex's picture
Offline
Joined: 05/17/2011
Juice: 9
Same problem

I've got the same problem. When the order is sent the amount changes to a round number again. I ordered something with an amount of 1.5 and when I look in orders (after ordering it) it's 1.0.
But I dont know how to solve this. Can someone help me solve this?

mstrelan's picture
Offline
Joined: 12/02/2009
Juice: 73
Re: Quantity as Decimal

I have posted the beginnings of a module at http://www.ubercart.org/issue/6044/abiility_have_decimal_quantities
Feel free to comment. I have been working on additional changes like modifying the cart review pane.

interactivex's picture
Offline
Joined: 05/17/2011
Juice: 9
Re: Quantity as Decimal

Thanks RobDinardo! You really smashed it and it helped me out a lot!

To complete the PDF made by robdinardo I have posted some additional code that should be changed. The PDF only changes the decimal stuff on the frontend and not on the order side (backend). With other words, the order still was saved as a round number and not with decimals.

In addition to the PDF (please do the changes that are written in the PDF some post above my post):

uc_order.install
Change:
'qty' => array(
'description' => 'The number of the same product ordered.',
'type' => 'int',
'size' => 'small',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),

To:
'qty' => array(
'description' => 'The number of the same product ordered.',
'type' => 'float',
'precision' => 6,
'scale' => 1,
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 1.0,
),

And change
db_change_field($ret, 'uc_order_products', 'qty', 'qty', array('type' => 'int', 'unsigned' => TRUE, 'size' => 'small', 'not null' => TRUE, 'default' => 0));

to:

db_change_field($ret, 'uc_order_products', 'qty', 'qty', array('type' => 'float', 'precision' => 6, 'scale' => 1, 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 1.0));

uc_order.install

Change this:
$product->qty = intval($_POST['qty']);

To:
$product->qty = $_POST['qty'];

I didn't add line numbers, because I found out that it's not correct by everyone (different ubercart 2 updates).

Good luck!

mydmitry's picture
Offline
Joined: 05/19/2011
Juice: 4
Re: Quantity as Decimal

I'm using AJAX CART and done as written in "Ubercart - Fractional Quantities.pdf" - it's work fine when I set better than 1 for example 1.7 tons or 20.11 tons, but when I set less than 1 it throw out product from cart.
20.11 -> 20.11 - work fine
1.7 -> 1.7 - work fine
0.7 -> 0 - don't work
0.3 -> 0 - don't work
0.99 -> 0 - don't work

Any suggestions?

Wombasta's picture
Offline
Joined: 07/19/2012
Juice: 16
Re: Quantity as Decimal

Just in case somebody will need the solution for drupal 7, ubercart 3 - I described what had worked for me in Ubercart 3.1 here:
http://www.ubercart.org/project/uc_decimal_quantities#comment-68750

tcclindy's picture
Offline
Joined: 05/10/2008
Juice: 32
Could decimal quantitys be added to the core

I like many other need to see items using fractional quantities, 1/4 yard, 1/2 yard, in the prior version i was using uc_decimal_quantities but that appears to not work anymore, what are the chances of ever getting this feature into your core functionality?

With decimal quantities I was able to enter 1.25 yards which really worked well.