In some lower-value currencies like 'Iranian Rials' (IRR)
Some products may have a price of 30,000,000.00 Rials or even greater.

This amount can not be stored in int(11) field in sql
so we need a bigger field like biggint

This issue causes some critical errors on the site

Another solution would be to use a different currency instead of Rials such as Tomans (but that isn't ISO standard)

Comments

rszrama’s picture

Title: price amount is limited to int(11) » How can I support price amounts greater than 11 digits?
Category: bug » feature
Priority: Critical » Normal

This isn't a bug so much as by design. I'm not sure there's a great way for us to make this editable via the UI, but at least in your case you can edit the database and change it to a bigInt or something similar.

hejazee’s picture

Anyway I think we should have at least a form validation callback
that prevents the user from entering very big numbers
Otherwise, the user will see WSOD or an ugly db error message

hejazee’s picture

Title: How can I support price amounts greater than 11 digits? » How can I support price amounts greater than 2147483647 (int(11))
Category: feature » bug

Now this is a bug!
missing form validation

rszrama’s picture

Title: How can I support price amounts greater than 2147483647 (int(11)) » How can I support price amounts greater than 11 digits?
Category: bug » feature

Let's leave this issue categorized as such; there's a separate issue for fixing validation.

hejazee’s picture

But it isn't 11 digits, I say :)

hejazee’s picture

Status: Active » Needs review
StatusFileSize
new423 bytes

I solved this issue by setting decimals to 0 for IRR currency
I think this patch should be ported !
Because there is no product ever that costs lower than a Rial, so we will never need decimal letters for this currency.
And also, showing decimals for Rials is annoying for users.

rszrama’s picture

Ahh, great. That would be a great fix; also, my bad, it isn't 11 digits - it's an 11 character display width that has no bearing on the size of the integer itself. n00b mistake: http://everythingmysql.ning.com/profiles/blogs/data-type-confusion-what-...

hejazee’s picture

Note that we also need an update function in commerce.install file

We need to divide all prices by 100 (Because we removed decimals)

Only products that have a price in IRR will need to be updated

hejazee’s picture

It seems that removing extra decimal places causes some errors in commerce !
Maybe some modules are used to add double 0 at the end of price
For example when I make a new invoice with commerce_invoices module
the amount of the invoice is multiplied by 100

And also, I can't pay for a product. I get an error (Maybe that's due to inequality of price when paying and when confirming it)

hejazee’s picture

Status: Needs review » Needs work
hejazee’s picture

Related: I created this sandbox module
http://drupal.org/sandbox/hejazee/1861440
which makes a new 'Toman' currency to be used instead of 'Rials' (IRR) without applying a patch.

leksat’s picture

My quick workaround to set commerce_price fields type to bigint:

/**
 * Implements hook_field_create_field().
 */
function MYMODULE_field_create_field($field) {
  // This will update type of newly created field.
  if ($field['module'] == 'commerce_price'
      && $field['type'] == 'commerce_price'
      && isset($field['columns']['amount']['type'])
      && $field['columns']['amount']['type'] == 'int'
      && (!isset($field['columns']['amount']['type']) || $field['columns']['amount']['type'] != 'big')) {
    $spec = $field['columns']['amount'];
    $spec['size'] = 'big';
    foreach (array('field_data_', 'field_revision_') as $prefix) {
      $table = $prefix . $field['field_name'];
      $column = $field['field_name'] . '_amount';
      db_change_field($table, $column, $column, $spec);
    }
  }
}

For updating all existing fields:
drush eval 'foreach (field_info_fields() as $field) { MYMODULE_field_create_field($field); }'

foopang’s picture

Hi Leksat, thanks for your workaround. But I get an error message below after applying your code above. It's weird that I still get the error message even I took off the hook function and cleared cache. Any way to fix it? Thanks.

Notice: Undefined index: bigint:normal in DatabaseSchema_mysql->processField() (line 205 of /var/www/test/includes/database/mysql/schema.inc).
There was a problem creating field Price: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'NOT NULL DEFAULT 0 COMMENT 'The price amount.', `field_price_currency_co' at line 9

Workaround solution from Leksat is perfect! Thanks.

donquixote’s picture

#2084171: Custom module to have prices and amounts in the database stored as BIGINT instead of INT

@Leksat:
This is nice, but are there not more tables and columns that need to be changed?
(see the linked issue)

dgtlmoon’s picture

[comment deleted, realised this is covered in another issue] :)

amankanoria’s picture

Issue summary: View changes
StatusFileSize
new822 bytes

If in case any 1 is looking for price validation so as to avoid mysql error for value limit I have added a short patch for it
PS: Validation is in context with int(11) field

rszrama’s picture

Status: Needs work » Closed (duplicate)

I'm going to go ahead and close this as either fixed by the workaround above or else pending resolution of #2084171: Custom module to have prices and amounts in the database stored as BIGINT instead of INT. I was originally interested in the idea of adding the validation from #16, but then I realized that doing so would make it more difficult for sites that actually want to support bigger numbers since they'd have to figure out how to work around this core validation. While ugly, the existing error is at least sufficient enough to show that big numbers aren't supported imo.