Jump to:

3460 Posts in 1064 Topics by 739 members

Data Model Questions

SilverStripe Forums » Data Model Questions » How do I configure Money objects?

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1479 Views
  • baba-papa
    Avatar
    Community Member
    279 Posts

    How do I configure Money objects? Link to this post

    I noticed that a class Money exists, which has much more to offer than the class Currency. But how do I configure an object of the class Money? For example where do I call the method setAllowedCurrencies()? I would have expected some static methods which could be called in the _config.php.

  • Willr
    Avatar
    Forum Moderator
    5502 Posts

    Re: How do I configure Money objects? Link to this post

    You use the setAllowedCurrencies() function http://api.silverstripe.org/2.4/sapphire/model/Money.html#methodsetAllowedCurrencies. It's not a static but instance level function now so you can configure it on a per field type or define your own statics for it.

  • baba-papa
    Avatar
    Community Member
    279 Posts

    Re: How do I configure Money objects? Link to this post

    Thanks for your help willr.
    I found a bug concerning the money class. I have a class "Order" which has a relation and an attribute with similar name:

    public static $db = array(
    'AmountTotal' => 'Money',
    'ShippingFee' => 'Money'
    );
    public static $has_one = array(
    'shippingFee' => 'ShippingFee'
    );


    If I call $ShippingFee.Nice in a template I never get results. I presume it has something to do with UpperCamelCase/lowerCamelCase. As I renamed the property to 'ShippingFeeTotal' it worked.

  • baba-papa
    Avatar
    Community Member
    279 Posts

    Re: How do I configure Money objects? Link to this post

    Money-Objects that have no Currency set will never end up in the frontend. I learned this the hard way ;) The amount is set with setAmount($someFloat) the objects needs a currency set to. If it is euro like in my case: setCurrency('EUR'). I had setCurrency('eur') before and it did not return any currency to the frontend when i called my Money object like $Price.Nice. Furthermore I had to tweek a core class to get our euro character displayed:
    sapphire/thirdparty/zend/locale/data/de.xml

    <currency type="EUR">
          <displayName>Euro</displayName>
          <displayName count="other">Euro</displayName>
    <symbol>€</symbol>
    </currency>

    1479 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.