/** * Process cost * * @param float|integer $cost * @param boolean $rounding * @return string */ public function __invoke($cost, $rounding = false) { $exchangeRates = PaymentService::getExchangeRates(); $activeShoppingCurrency = PaymentService::getShoppingCartCurrency(); // convert cost if (isset($exchangeRates[$activeShoppingCurrency])) { $cost = $cost * $exchangeRates[$activeShoppingCurrency]['rate']; } if ($rounding) { $cost = PaymentService::roundingCost($cost); } return $this->getView()->currencyFormat($cost, $activeShoppingCurrency); }
/** * Cost format * * @param float|integer|array $cost * @param array $options * @param boolean $rounding * @return string */ public function __invoke($cost, array $options = [], $rounding = true) { $value = null; $currency = null; // extract data from the array if (!is_numeric($cost)) { $value = !empty($cost['cost']) ? $cost['cost'] : null; $currency = !empty($cost['currency']) ? $cost['currency'] : null; } else { $value = $cost; } // get a currency code from the options if (!empty($options['currency'])) { $currency = $options['currency']; } if (!$value && !$currency) { return; } if ($rounding) { $value = PaymentService::roundingCost($value); } return $this->getView()->currencyFormat($value, $currency); }