Permalink
Browse files

API CHANGE: Added new config option Money.default_currency.

  • Loading branch information...
sminnee committed May 18, 2012
1 parent 7036abb commit 7201f0647631b0b6c903831aabc77f1e05032094
Showing with 5 additions and 3 deletions.
  1. +5 −3 model/fieldtypes/Money.php
@@ -106,9 +106,11 @@ function setValue($value, $record = null, $markChanged = true) {
$this->setCurrency($value->getCurrency(), $markChanged);
$this->setAmount($value->getAmount(), $markChanged);
if($markChanged) $this->isChanged = true;
- } else if($record && isset($record[$this->name . 'Currency']) && isset($record[$this->name . 'Amount'])) {
- if($record[$this->name . 'Currency'] && $record[$this->name . 'Amount']) {
- $this->setCurrency($record[$this->name . 'Currency'], $markChanged);
+ } else if($record && isset($record[$this->name . 'Amount'])) {
+ if($record[$this->name . 'Amount']) {
+ if(!empty($record[$this->name . 'Currency'])) $this->setCurrency($record[$this->name . 'Currency'], $markChanged);
+ else if($currency = (string)$this->config()->get('default_currency')) $this->setCurrency($currency, $markChanged);
+
$this->setAmount($record[$this->name . 'Amount'], $markChanged);
} else {
$this->value = $this->nullValue();

0 comments on commit 7201f06

Please sign in to comment.