SilverCart Forum

We moderate this Forum and we're here to help. Have you already run a forum search to check if your problem has already been solved?

You can help us helping you by providing detailed error messages, screenshots and logfile entries.

SebastianRamon

Page: 1 , 2
Topic [resolved] How to change the Euro sign to the Dollar sign? 5340 Views

[resolved] How to change the Euro sign to the Dollar sign?

8 October 2013 at 3:39pm Last edited: 8 October 2013 11:19pm

Hi,

How to change the Euro sign to the Dollar sign? I've been searching both the docs and the forum but cannot find the answer.

On the General SC Configuration's Prices panel I have already changed the string EUR to USD, but that does not change the signs displayed on the frontend.

Oh, and one more question :) How can I get rid of the decimal places? I only need whole numbers for the prices.

Please help :)

Re: [resolved] How to change the Euro sign to the Dollar sign?

9 October 2013 at 2:15pm Last edited: 9 October 2013 2:15pm

Hi szabesz,

we use the plain SilverStripe money object for the prices.

In the templates, the prices are called via $Price.Nice which calls the function Nice in the Money class (can be found under sapphire/core/model/fieldtypes/Money.php

The function uses an array for options:

function Nice($options = array()) {
      $amount = $this->getAmount();
      if(!isset($options['display'])) $options['display'] = Zend_Currency::USE_SYMBOL;
      if(!isset($options['currency'])) $options['currency'] = $this->getCurrency();
      if(!isset($options['symbol'])) $options['symbol'] = $this->currencyLib->getSymbol($this->getCurrency(), $this->getLocale());
      return (is_numeric($amount)) ? $this->currencyLib->toCurrency($amount, $options) : '';
   }

More documentation about the money class: http://api.silverstripe.org/2.4/class-Money.html

Here you should get rid of the decimal points as well (at least for frontend display)

Hope this helps.

Cheers
Ramon

Re: [resolved] How to change the Euro sign to the Dollar sign?

9 October 2013 at 2:31pm

Hello Ramon! Only a few parameters? That sounds easy :) Thank you again!

Re: [resolved] How to change the Euro sign to the Dollar sign?

9 October 2013 at 5:27pm

Well, I thought I could do it, but after trying to figure it out for about an hour I have give up :(
I "the meantime" the Euro sign changed to the Dollar sign, the only problem is, I do not know why... It is still $Price.Nice in the template, because I was unable to figure out how to pass arrays to it.
I understand that it is a SilverStripe issue and not a SilverCart one, but so far I have not seen any examples of passing arrays to a controller function via a template parameter. I could not even find examples googling for it.

I tried to do this: $Price.Nice(array("currency"=>"USD"))
but anyway it is !isset($options['currency']) in the if construct, that is if no currency is set, $this->getCurrency() is used.

The other thing is the decimals issue. I'm even more stuck with this. I cannot see how Money.Nice deals with it.

Could you please provide some examples? Thanx in advance.

Re: [resolved] How to change the Euro sign to the Dollar sign?

9 October 2013 at 5:46pm Last edited: 9 October 2013 5:47pm

Hi szabesz,

what is the locale you use?

The default currency_symbol depends on the locale.

If you have problems overriding it, maybe switching the locale of your installation might make more sense if you want to use it throughout your store.

To do that, you'd have to change the default locale in the _config.php and change the locale setting in the database for product language and site tree entries.

You could also decorate the SilvercartProduct class and create a new function, e.g. function NiceNoDecimals() to achieve the desired behaviour. There you could try to pull a quick&dirty cheap trick like

return str_replace(".00", "", $this->owner->Nice());

" to manipulate the string in the desired way.

Then, in the template, you use $Product.NiceNoDecimals

I am not quite sure on which track to put you, since I have no idea about your programming experience...

Cheers
Ramon

Re: [resolved] How to change the Euro sign to the Dollar sign?

9 October 2013 at 6:55pm

Hi Ramon,

In mysite/_config.php I have i18n::set_locale('en_US');
I do not know if have I changed it or not, and I have another SilverCart install that is "almost" a fresh install (just for reference purposes) with the same setting in _config.php.

And as I have the desired dollar sign already, I think I'm going to stop investigating this issue, as it appears to work as expected :)

As for the decimals, thanx again! Your function works fine, although you made a small typo with "SilvercartProduct" since the class to decorate is the Money, as you have already pointed out in your first reply.

Thank you very much, issues solved :)

cheers
szabesz

Re: [resolved] How to change the Euro sign to the Dollar sign?

9 October 2013 at 7:54pm

Hi szabesz,

I am happy to hear that this solution works for you.

Don't forget to show us the finished online store, I am very curious how it will turn out once it is done ;-)

Cheers
Ramon

Re: [resolved] How to change the Euro sign to the Dollar sign?

9 October 2013 at 9:42pm

Hi,

I'm definitely not going to forget to show you the finished store, as you have just started to provide your hosting services for it :) Sorry for using my nick here, I just got used to using it in forums.

best,
Gábor