Search

Hello everyone, I’m trying to do an extension field of currency, but I’m still new to the symphony, and do not have much idea how to do.

the idea is to use a floating number field, with settings for currency (prefix i.e. $ or R$) and number format (like “#.###,00”).

The objective of this is show data formatted as currency in publish, as it was desired by the customer. and being numeric field, it is possible to use the field for reflection summations.

example: number (int) * value (float) = total (reflection field, {(number(entry/number) * number(entry/value))} ) and maybe show the ‘total’ result as currency too.

I made some changes in the existing text field, but it is not something I am proud. worked for my particular case, but does not work generic.

if anyone has any ideas, is entirely welcome

the changes I made are:

public function displayPublishPanel(...){
$value = General::sanitize('R$ '.number_format($data['value'], 2, ',', '.'));
(...)
}

and

public function processRawFieldData(...) {
(...)
$result = array(
'value' => trim(str_replace(',','.',str_replace('.',',',str_replace('R$','',$data))))
);
(...)
}

in my case, I use brazilian Real (i.e. R$ 1500,30)

Hello germchaos,

You can start by extending the fieldInput class and just change a few methods. Have a look at field.input.php. In this case you might use money_format function.

I hope that helps.

Hmm, this helped a lot! Ty rainerborene!

Yes definitely look at a few of the existing field type extensions. They’ll get you going…

I would like to do something similar;
Have a currencyfield that automagically converts is value in Euro into other currencies, based on the life rss currency feed from the european central bank.
Now I wonder wether the conversion would best be calculated at php level, or at xslt level. Can the reflection field be actually used for such calculations?

regarding all the parameters needed; countrycode to country to currency to currencycode to currencysymbol can al be fetched from webservicex, dynamically , or just once and stored as static xml.

Now I wonder wether the conversion would best be calculated at php level, or at xslt level. Can the reflection field be actually used for such calculations?

Don’t you just have to divide by the rate? In this case XSLT is well suited for that (one Dynamic XML DS and your regular DS, rate conversion is done by XSLT).

The reflection field is not suited for those tasks as it will only refresh the values upon saving (and not by itself as the fluctuating nature of exchange rates would require). Additionally you would be limited to only a fixed number of currencies per item.

the idea is to use a floating number field, with settings for currency (prefix i.e. $ or R$) and number format (like “#.###,00”).

I don’t think there is a need for a new field at all. XSLT has a function called number-format() wich can do what you’re after. Provided that the values you’re entering in the field are all in the same currency.

If not: Create a new field, add a dropdown to select the currency and leave out the whole comma-period-logic-stuff. That’s purely presentational and can be done in the XSLT.

thanks phoque, that rules out the reflection field. But the ‘life’ conversion wouldn’t better done in pure php in an extension? Isn’t converting your DS Euro with xslt into Dollars a bit ‘hackish’ or would you argue that currency is a layer of presentation, not content, and thus makes sense to do it on thelast level, and not lower level php?

thanks phoque, that rules out the reflection field. But the ‘life’ conversion wouldn’t better done in pure php in an extension? Isn’t converting your DS Euro with xslt into Dollars a bit ‘hackish’ […]

Not at all. That’s what XSLT was made for. :-) Besides: the extension would have to provide the external XML, replicating the functionality of the Dynamic XML DS itself, making it a lot more messy than it had to be.

If not: Create a new field, add a dropdown to select the currency and leave out the whole comma-period-logic-stuff. That’s purely presentational and can be done in the XSLT.

Actually, that was nonsense… Add two fields to your section:

  • Text Intput “Price”
  • Select Box “Currency”

And do all the calculations and transformations in the XSLT. :-)

Anyone any advice on where to find what currency has what notation of points and commas?

I know of floating point position ea 1.000,00 like used in the dojo i18n toolkit only

My guess about doing an extension, and not just use XSLT, the reason is for the values are well presented in the administration. I could just use a numeric field, but customers like the details, you know?

Unless I make a unique administration panel to manage the sales. In this case would work just using XSLT, but I see this as an unnecessary work.

The solution I found was simple, just add a prefix to the numeric field and do the conversion using number_format() in PHP. The field is saved only with the numeric value. But as I said, is a particular solution. And not very appropriate I would say.

What I did is more like a mask …

I couldn’t resist to write an XSLT utility that does currency conversion. :-)

My guess about doing an extension, and not just use XSLT, the reason is for the values are well presented in the administration. I could just use a numeric field, but customers like the details, you know?

Good for you if your customer is willing to pay you for such a minor detail. :-)

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details