For every time a money field is displayed on my site I would like to convert the value to the user's preferred currency and I have built a function to do this. This function requires the country code of the original amount.

Trouble is when a View is used there seems to be no way of accessing the country code...

Is this right? If not how do I go about getting this info? I don't have to use a patch do I (I never have much luck with patches!!)

Many thanks,

Ben Jackson

Comments

markus_petrux’s picture

Have you tried overriding the theme function used to format the money field?

bentonboomslang’s picture

Hi Markus,
Thanks for the reply. I'm not quite sure what you mean: Do you mean alter the money.module file or something else entirely?
Ben

markus_petrux’s picture

Nope. You don't need to alter money.module.

On the other hand, you can override theme functions implemented in money.module. These are those functions that start with "theme_". This is a standard Drupal method that can be used to adapt the output of almost anything to suit your needs.

Money fields have a display format that you can select in "Display fields" screen. Each display format has a theme function that is implemented as a CCK field formatter. Just browse the money.module code to figure it out. Look at functions theme_money_formatter_unformatted() and theme_money_formatter_generic(). Each one is related to a field formatter. You can copy anyone of these functions to your theme's template.php and change the prefix "theme" by "mytheme" in the function name. For example, if your theme is garland, then use "garland_money_formatter_generic" for the function name. Now, you can modify the contents of this function to suit your needs, and here you cannot only change the look, but also implement whatever else you may need. You have all the releant information here to perform additional conversions.

http://drupal.org/theme-guide

An alternative to overriding theme functions is that CCK allows you to implement additional field formatters from custom modules. You have an example of this in several contrib modules:

http://drupal.org/project/cck_formatters
http://drupal.org/project/textformatter
http://drupal.org/project/nodereference_formatters

In summary, your request can be solved altering the presentation layer of money fields, and you do not need to modify the money module at all.

markus_petrux’s picture

Status: Active » Fixed
markus_petrux’s picture

BTW, the money_conversion_dialog submodule in this package is implemented as an additional formatter for money fields. This is another example you may want to look at.

Status: Fixed » Closed (fixed)

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