I noticed the same issue in the original screen cast.

It may be worth considering replacing the integer field type with a float. This will allow pennies / cents to be added.

Potentially useful if you're doing a charity website where the total order comes to £14.43 (or whatever) and you can suggest a donation of 57p to round it up to a whole number. Small increase for the customer, but adds up for the charity.

Comments

stella’s picture

That's a nice feature. How are you doing the suggestion to round it up? a custom checkout pane? I'll change it to a float over the weekend.

sagraham’s picture

At the moment I've not actually got anything up and running, but I was trying to think of a way to hook into the Select (or other) options and add the 'round up' value as a radio box. Not sure of effort vs reward, but it would make sense for the customer.

stella’s picture

I'll see if I can build that as an option into the module too then.

sagraham’s picture

Many thanks for creating the module. Timing was excellent as I was going to have to make an attempt at a similar module myself.

Very grateful that you've done the hard work for me!

aaronbauman’s picture

I think you'll probably want a decimal, actually.
Might run into rounding errors with a float, and we don't actually need to worry about floating precision.

aaronbauman’s picture

Version: 7.x-1.0-beta1 » 7.x-1.x-dev

bumped version

stella’s picture

Status: Active » Fixed

This feature is available in the latest dev version.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

tmsimont’s picture

Status: Closed (fixed) » Active

what about sites that have data before this update? With the commit to change the field, shouldn't there have been an update function added?

I have an amount field that has data -- I'm now unable to change the field type in the Drupal UI. Do you know how I could update this integer field to decimal?

tmsimont’s picture

Basically what needs to be done is an alteration of the database in an update function. I did this all manually in phpMyAdmin:

  1. Change `field_data_commerce_donate_amount.commerce_donate_amount_value` type to be decimal(10,2)
  2. Change `field_revision_commerce_donate_amount.commerce_donate_amount_value` type to be decimal(10,2)
  3. Change `field_config.type` = "number_decimal" WHERE `field_name` = 'commerce_donate_amount'
  4. Change `field_config.data` BLOB value to include this in the serialized array:
[settings] => Array
(
  [precision] => 10
  [scale] => 2
  [decimal_separator] => .
)

That last part is a little tricky if you're doing this manually.. I had to download the BLOB file from phpMyAdmin and edit the serialized array by hand in a text editor... Basically you need to find this:
s:8:"settings";a:0:{}
and replace with this:
s:8:"settings";a:3:{s:9:"precision";s:2:"10";s:5:"scale";s:1:"2";s:17:"decimal_separator";s:1:".";}

I wouldn't do that unless you really know what you're doing...

yaworsk’s picture

I tried your updates but screwed something up along the way - likely the blob changes. Can you be more specific on how you did them? I downloaded the bin file, changed it in eclipse but got errors. When I redownloaded the file again (via phpmyadmin) i noticed a bunch of lines were duplicated (it went from something like a 10 line file to 18 line file - under 1kb to appoximately 10kb).

On another note, uninstalling/reinstalling the module to get this working doesn't work because tables / content are not properly removed from the database in the event anyone else is trying that. I've posted the issue here: https://drupal.org/node/1681234#comment-7935989

lsolesen’s picture

Title: Replace integer with float? » Replace integer with float? Add update function for older sites.
Issue summary: View changes
Status: Active » Needs review
theamoeba’s picture

@yaworsk, for the BLOB changes I put this into a small tweaks module.

function tweaks_donate_int_dec() {
  // Fetch the blob from the DB.
  $blob = db_select('field_config', 'f')
    ->fields('f')
    ->condition('field_name', 'commerce_donate_amount')
    ->execute()
    ->fetchAssoc();

  // Unserialize the blob data and then add the extra bits.
  $data = unserialize($blob['data']);
  $data['settings']['precision'] = 10;
  $data['settings']['scale'] = 2;
  $data['settings']['decimal_separator'] = '.';

  // Do some printing out to make sure everythign works
  drupal_set_message('<pre>'. print_r($blob, true) .'</pre>');
  drupal_set_message('<pre>'. print_r($data, true) .'</pre>');

  // Reserialize the new data and then copy and paste into the table.
  // I could do a db_update here but I didn't fell like it.
  return serialize($data);
}

That should help. Using the above with db_change_field would work fairly well in an update function. I am happy to write a patch if necessary.

lsolesen’s picture

Status: Needs review » Needs work

A patch for the update would be very nice.

lswhitehead’s picture

+1

richH’s picture

Priority: Normal » Major

Hi,

there are so many patches outstanding for this module. Can you update it please? I have the problem with the latest DEV version, that if the user enters the value 100.00 into the "other amount" field, that the page won't move forward to the checkout. I've already patched the module twice and really don't want to start hacking around again.

Thanks
Rich

stella’s picture

Status: Needs work » Fixed

Unfortunately Drupal's field CRUD API doesn't support the changing of field types (in this instance number_integer to number_decimal), so using field_update_field() isn't an option. The only option is to manually force it by updating the individual database tables as referred to above.

I've added an update hook which makes the required db changes now.

  • stella committed f5b8e76 on 7.x-1.x
    Issue #1680842 by stella: added update hook - Replace integer with float...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.