/** * This UT tests if saveInto used customised getters/setters correctly. * Saving values for CustomMoney shall go through the setCustomMoney_Test * setter method and double the value. */ public function testSetValueViaSetter() { $o = new MoneyFieldTest_CustomSetter_Object(); $f = new MoneyField('CustomMoney', 'Test Money Field'); $f->setValue(array('Currency' => 'EUR', 'Amount' => 123456.78)); $f->saveInto($o); $this->assertEquals(2 * 123456.78, $o->MyMoney->getAmount()); $this->assertEquals('EUR', $o->MyMoney->getCurrency()); }
/** * Set the Money value * * @param mixed $val Value to set * * @return void */ public function setValue($val) { $defaultCurrency = SilvercartConfig::DefaultCurrency(); if (is_array($val)) { if (empty($val['Currency'])) { $val['Currency'] = $defaultCurrency; } if (!empty($val['Amount'])) { $val['Amount'] = $this->prepareAmount($val['Amount']); } } elseif ($val instanceof Money) { if ($val->getCurrency() != $defaultCurrency && $this->getCurrencyIsReadonly()) { $val->setCurrency($defaultCurrency); } if ($val->getAmount() != '') { $val->setAmount($this->prepareAmount($val->getAmount())); } } parent::setValue($val); }