Skip to content

Commit

Permalink
dev
Browse files Browse the repository at this point in the history
  • Loading branch information
skeeks-semenov committed May 20, 2018
1 parent b9291cb commit 95f130a
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/Currency.php
Original file line number Diff line number Diff line change
Expand Up @@ -1297,4 +1297,14 @@ public function getCrossCourse($currencyTo)

return 1;
}


/**
* @return array|string
* @deprecated
*/
public function getCurrencyCode()
{
return $this->code;
}
}
25 changes: 24 additions & 1 deletion src/Money.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*
* @author Semenov Alexander <[email protected]>
*/
class Money extends BaseObject
class Money extends BaseObject implements \JsonSerializable
{
/**
* @var string
Expand Down Expand Up @@ -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 <b>json_encode</b>,
* @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;
}
}
10 changes: 10 additions & 0 deletions src/MoneyComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
namespace skeeks\cms\money;

use skeeks\cms\base\Component;
use skeeks\cms\money\models\MoneyCurrency;
use yii\helpers\ArrayHelper;

/**
Expand Down Expand Up @@ -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();
}


}

0 comments on commit 95f130a

Please sign in to comment.