mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge pull request #4206 from gregsmirnov/pulls/localised-moneyfield-fix
BUG Fixed handling of numbers in certain locales
This commit is contained in:
commit
e733efa195
@ -106,12 +106,12 @@ class MoneyField extends FormField {
|
|||||||
$fieldName = $this->name;
|
$fieldName = $this->name;
|
||||||
if($dataObject->hasMethod("set$fieldName")) {
|
if($dataObject->hasMethod("set$fieldName")) {
|
||||||
$dataObject->$fieldName = DBField::create_field('Money', array(
|
$dataObject->$fieldName = DBField::create_field('Money', array(
|
||||||
"Currency" => $this->fieldCurrency->Value(),
|
"Currency" => $this->fieldCurrency->dataValue(),
|
||||||
"Amount" => $this->fieldAmount->Value()
|
"Amount" => $this->fieldAmount->dataValue()
|
||||||
));
|
));
|
||||||
} else {
|
} else {
|
||||||
$dataObject->$fieldName->setCurrency($this->fieldCurrency->Value());
|
$dataObject->$fieldName->setCurrency($this->fieldCurrency->dataValue());
|
||||||
$dataObject->$fieldName->setAmount($this->fieldAmount->Value());
|
$dataObject->$fieldName->setAmount($this->fieldAmount->dataValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,7 +155,7 @@ class MoneyField extends FormField {
|
|||||||
$this->allowedCurrencies = $arr;
|
$this->allowedCurrencies = $arr;
|
||||||
|
|
||||||
// @todo Has to be done twice in case allowed currencies changed since construction
|
// @todo Has to be done twice in case allowed currencies changed since construction
|
||||||
$oldVal = $this->fieldCurrency->Value();
|
$oldVal = $this->fieldCurrency->dataValue();
|
||||||
$this->fieldCurrency = $this->FieldCurrency($this->name);
|
$this->fieldCurrency = $this->FieldCurrency($this->name);
|
||||||
$this->fieldCurrency->setValue($oldVal);
|
$this->fieldCurrency->setValue($oldVal);
|
||||||
|
|
||||||
|
@ -14,13 +14,13 @@ class MoneyFieldTest extends SapphireTest {
|
|||||||
$o = new MoneyFieldTest_Object();
|
$o = new MoneyFieldTest_Object();
|
||||||
|
|
||||||
$m = new Money();
|
$m = new Money();
|
||||||
$m->setAmount(1.23);
|
$m->setAmount(123456.78);
|
||||||
$m->setCurrency('EUR');
|
$m->setCurrency('EUR');
|
||||||
$f = new MoneyField('MyMoney', 'MyMoney', $m);
|
$f = new MoneyField('MyMoney', 'MyMoney', $m);
|
||||||
|
|
||||||
$f->saveInto($o);
|
$f->saveInto($o);
|
||||||
$this->assertEquals($o->MyMoney->getAmount(), 1.23);
|
$this->assertEquals(123456.78, $o->MyMoney->getAmount());
|
||||||
$this->assertEquals($o->MyMoney->getCurrency(), 'EUR');
|
$this->assertEquals('EUR', $o->MyMoney->getCurrency());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSetValueAsMoney() {
|
public function testSetValueAsMoney() {
|
||||||
@ -29,13 +29,13 @@ class MoneyFieldTest extends SapphireTest {
|
|||||||
$f = new MoneyField('MyMoney', 'MyMoney');
|
$f = new MoneyField('MyMoney', 'MyMoney');
|
||||||
|
|
||||||
$m = new Money();
|
$m = new Money();
|
||||||
$m->setAmount(1.23);
|
$m->setAmount(123456.78);
|
||||||
$m->setCurrency('EUR');
|
$m->setCurrency('EUR');
|
||||||
$f->setValue($m);
|
$f->setValue($m);
|
||||||
|
|
||||||
$f->saveInto($o);
|
$f->saveInto($o);
|
||||||
$this->assertEquals($o->MyMoney->getAmount(), 1.23);
|
$this->assertEquals(123456.78, $o->MyMoney->getAmount());
|
||||||
$this->assertEquals($o->MyMoney->getCurrency(), 'EUR');
|
$this->assertEquals('EUR', $o->MyMoney->getCurrency());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSetValueAsArray() {
|
public function testSetValueAsArray() {
|
||||||
@ -43,11 +43,11 @@ class MoneyFieldTest extends SapphireTest {
|
|||||||
|
|
||||||
$f = new MoneyField('MyMoney', 'MyMoney');
|
$f = new MoneyField('MyMoney', 'MyMoney');
|
||||||
|
|
||||||
$f->setValue(array('Currency'=>'EUR','Amount'=>1.23));
|
$f->setValue(array('Currency'=>'EUR','Amount'=>123456.78));
|
||||||
|
|
||||||
$f->saveInto($o);
|
$f->saveInto($o);
|
||||||
$this->assertEquals($o->MyMoney->getAmount(), 1.23);
|
$this->assertEquals(123456.78, $o->MyMoney->getAmount());
|
||||||
$this->assertEquals($o->MyMoney->getCurrency(), 'EUR');
|
$this->assertEquals('EUR', $o->MyMoney->getCurrency());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -59,12 +59,13 @@ class MoneyFieldTest extends SapphireTest {
|
|||||||
$o = new MoneyFieldTest_CustomSetter_Object();
|
$o = new MoneyFieldTest_CustomSetter_Object();
|
||||||
|
|
||||||
$f = new MoneyField('CustomMoney', 'Test Money Field');
|
$f = new MoneyField('CustomMoney', 'Test Money Field');
|
||||||
$f->setValue(array('Currency'=>'EUR','Amount'=>1.23));
|
$f->setValue(array('Currency'=>'EUR','Amount'=>123456.78));
|
||||||
|
|
||||||
$f->saveInto($o);
|
$f->saveInto($o);
|
||||||
$this->assertEquals($o->MyMoney->getAmount(), (2 * 1.23) );
|
$this->assertEquals((2 * 123456.78), $o->MyMoney->getAmount());
|
||||||
$this->assertEquals($o->MyMoney->getCurrency(), 'EUR');
|
$this->assertEquals('EUR', $o->MyMoney->getCurrency());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class MoneyFieldTest_Object extends DataObject implements TestOnly {
|
class MoneyFieldTest_Object extends DataObject implements TestOnly {
|
||||||
|
Loading…
Reference in New Issue
Block a user