diff --git a/src/Currency.php b/src/Currency.php index 925bc1a..06eb9fa 100644 --- a/src/Currency.php +++ b/src/Currency.php @@ -1297,4 +1297,14 @@ public function getCrossCourse($currencyTo) return 1; } + + + /** + * @return array|string + * @deprecated + */ + public function getCurrencyCode() + { + return $this->code; + } } \ No newline at end of file diff --git a/src/Money.php b/src/Money.php index 6d7e677..ae08728 100644 --- a/src/Money.php +++ b/src/Money.php @@ -16,7 +16,7 @@ * * @author Semenov Alexander */ -class Money extends BaseObject +class Money extends BaseObject implements \JsonSerializable { /** * @var string @@ -202,4 +202,27 @@ public function convertToCurrency($currencyTo) throw new InvalidArgumentException(\Yii::t('skeeks/money', 'Unable to get the cross rate for the currency') . ' ' . $currencyTo->code); } } + + /** + * Specify data which should be serialized to JSON + * + * @return mixed data which can be serialized by json_encode, + * @link http://php.net/manual/en/jsonserializable.jsonserialize.php + */ + public function jsonSerialize() + { + return [ + 'amount' => $this->amount, + 'currency' => $this->currency->code + ]; + } + + /** + * @return string + * @deprecated + */ + public function getValue() + { + return $this->amount; + } } \ No newline at end of file diff --git a/src/MoneyComponent.php b/src/MoneyComponent.php index f6103da..8130bbf 100644 --- a/src/MoneyComponent.php +++ b/src/MoneyComponent.php @@ -9,6 +9,7 @@ namespace skeeks\cms\money; use skeeks\cms\base\Component; +use skeeks\cms\money\models\MoneyCurrency; use yii\helpers\ArrayHelper; /** @@ -60,4 +61,13 @@ public function newMoney() return new Money('0', $this->currencyCode); } + /** + * @return array|MoneyCurrency[] + */ + public function getActiveCurrencies() + { + return MoneyCurrency::find()->where(['is_active' => 1])->all(); + } + + } \ No newline at end of file