Implement a basic price field to store a price (defined as an amount and a currency code). The price field needs to store these two values separately, and we've discussed using an integer column instead of a decimal for storing the amount. That decision needs to be finalized.

The widget for the price field should have settings so the user can choose to display it with one of these simple configurations:

  1. A textfield for the amount and a select list for the currency (with options displayed as the currency code).
  2. A textfield with a single currency enforced, meaning the currency code will be displayed as a suffix of the textfield. If the store only has a single currency, this should be the only option available.

This ticket can be closed when two basic display formatters are included:

  1. Base price (raw) - Display the price values as a number without currency formatting.
  2. Base price (formatted) - Display the base price values as a number with currency formatting.

Other display formatters depend on the completion of the price handling object. If possible, include settings for an additional prefix / suffix to the price.

Comments

rszrama’s picture

fwiw, this article also specifies a BigInt for monetary values.

rszrama’s picture

Status: Active » Needs work

While the basic price field has been implemented, it does need to be updated to use integer storage instead of decimal storage.

rszrama’s picture

See also this article: http://www.codeproject.com/KB/recipes/MoneyTypeForCLR.aspx

It advocates storing all price values in fixed base 10 numbers.

rszrama’s picture

Status: Needs work » Fixed

Finished this off with a few commits this evening:

  1. https://github.com/rszrama/drupalcommerce/commit/e8519b7fb8dcb3ede6363af... - Added API functions for converting price amounts to integers and back again.
  2. https://github.com/rszrama/drupalcommerce/commit/8b237180afe51abf03eaaae... - Swap the order of presave operations; hook_field_presave() was getting invoked first, which is where the Price field needs to transform its data for insert / update (i.e. convert to integer)... but this change was being seen by the Cart module as a substantive change to line items and causing some nasty recursion. Took me hours to debug. :-/
  3. https://github.com/rszrama/drupalcommerce/commit/a1fc05a3873434e2c952360... - Convert the Price field schema and presave / load hooks to store price amounts as integers and perform decimal conversion on load if necessary. This is currently based on the number of decimals a particular currency says it should be expressed in.
  4. https://github.com/rszrama/drupalcommerce/commit/eeefd354d168686c3e7d643... - Updated pre-calculated prices and payment transactions to also store amount values as integers.
spydmobile’s picture

Stupid question does this ongoing work have anything to do with an error like this when clicking store->products:

'Missing handler: field_data_purchase_price entity_id field'
in views_get_handler() (line 841 of /home/kitchens/drupal/sites/all/modules/views/views.module).
rszrama’s picture

It shouldn't... I'd guess first you need to update to the dev version of Views.

spydmobile’s picture

Hi Ryan, um, this *IS* the dev of views.
from Drush:

 Views               7.x-3.x-dev        7.x-3.x-dev       Up to date         

EDIT: Should I open a new issue instead?

rszrama’s picture

Nah, I don't think we need a new issue... we see a lot of entity_id bug reports having to do with folks using Views 3.0-alpha1, but your problem seems to be that you have a View expecting to find the field_data_purchase_price handler. However, as of the most recent dev of Commerce, the purchase_price field has been renamed to commerce_price, which is why it's showing up as missing. Can you rebuild your site?

spydmobile’s picture

Sure will a full disabling/uninstall/removal of all commerce be enough or do I need to startover from scratch and start over with D7? I think I need to be running dev commerce but have alpha5 installed....

rszrama’s picture

Uninstall doesn't work for Commerce right now anyways, so just rebuild the whole site. You might also give the latest dev a shot. : )

Status: Fixed » Closed (fixed)

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