*/ class Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Currency extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract { protected $_defaultWidth = 100; /** * Currency objects cache */ protected static $_currencies = array(); /** * Renders grid column * * @param Varien_Object $row * @return string */ public function render(Varien_Object $row) { if ($data = (string)$row->getData($this->getColumn()->getIndex())) { $currency_code = $this->_getCurrencyCode($row); if (!$currency_code) { return $data; } $data = floatval($data) * $this->_getRate($row); $sign = (bool)(int)$this->getColumn()->getShowNumberSign() && ($data > 0) ? '+' : ''; $data = sprintf("%f", $data); $data = Mage::app()->getLocale()->currency($currency_code)->toCurrency($data); return $sign . $data; } return $this->getColumn()->getDefault(); } /** * Returns currency code, false on error * * @param $row * @return string|false */ protected function _getCurrencyCode($row) { if ($code = $this->getColumn()->getCurrencyCode()) { return $code; } if ($code = $row->getData($this->getColumn()->getCurrency())) { return $code; } return false; } /** * Get rate for current row, 1 by default * * @param $row * @return float|int */ protected function _getRate($row) { if ($rate = $this->getColumn()->getRate()) { return floatval($rate); } if ($rate = $row->getData($this->getColumn()->getRateField())) { return floatval($rate); } return 1; } /** * Returns HTML for CSS * * @return string */ public function renderCss() { return parent::renderCss() . ' a-right'; } }