diff --git a/modules/price/commerce_price.module b/modules/price/commerce_price.module index 77f65fd..0468c68 100644 --- a/modules/price/commerce_price.module +++ b/modules/price/commerce_price.module @@ -741,10 +741,17 @@ function commerce_price_field_data_property_info($name = NULL) { 'amount' => array( 'label' => t('Amount'), 'description' => !empty($name) ? t('Amount value of field %name', array('%name' => $name)) : '', - 'type' => 'decimal', + 'type' => 'integer', 'getter callback' => 'entity_property_verbatim_get', 'setter callback' => 'entity_property_verbatim_set', ), + 'amount_float' => array( + 'label' => t('Amount (float)'), + 'description' => !empty($name) ? t('Amount value of field %name (as a float)', array('%name' => $name)) : '', + 'type' => 'decimal', + 'getter callback' => 'commerce_price_amount_float_get', + 'setter callback' => 'commerce_price_amount_float_set', + ), 'currency_code' => array( 'label' => t('Currency'), 'description' => !empty($name) ? t('Currency code of field %name', array('%name' => $name)) : '', @@ -764,6 +771,25 @@ function commerce_price_field_data_property_info($name = NULL) { } /** + * Property getter callback returing the amount (as a float). + */ +function commerce_price_amount_float_get($data, array $options, $name, $type, $info) { + if (isset($data['amount']) && isset($data['currency_code'])) { + return commerce_currency_amount_to_decimal($data['amount'], $data['currency_code']); + } + return NULL; +} + +/** + * Sets the property to the given value. + */ +function commerce_price_amount_float_set(&$data, $name, $value, $langcode, $type, $info) { + if ($name == 'amount_float') { + $data['amount'] = commerce_currency_decimal_to_amount($value, $data['currency_code']); + } +} + +/** * Returns the data array of a single value price field from a wrapped entity, * using an optional default value if the entity does not have data in the field. *