Search code examples
phpmagento

Magento 1.9 string replace in grid


I have made a custom grid where i have an overview in columns of prices, discounts and amounts. The decimals are separated by a dot (32.400).

What is the best way to change the dot to a comma (32,400).

I have tried the properties (price, number, currency) but these doesn't change de dot.

SAMPLE:

$this->addColumn('price_total', array(
        'header' => $helper->__('Total'),
        'type'   => 'price',
        'index'  => 'Total'
    ));

EDIT:

Thank you Sunil, with your help i figured it out! Here is how i did it, if someone might be interested.

My class in (app/code/local/SML/Exportorders/Block/Adminhtml/Sales/Order/Grid.php) Grid.php

class SML_Exportorders_Block_Adminhtml_Sales_Order_Grid extends Mage_Adminhtml_Block_Widget_Grid
{
public function __construct()
{
    parent::__construct();
    $this->setId('sml_order_grid');
    $this->setDefaultSort('increment_id');
    $this->setDefaultDir('DESC');
    $this->setSaveParametersInSession(true);
    $this->setUseAjax(true);
}

protected function _prepareCollection()
{...

Defining column:

$this->addColumn('sub_total', array(
        'header' => $helper->__('Sub Total'),
        'type'   => 'text',
        'index'  => 'SubTotal',
        'renderer' => 'sml_exportorders/adminhtml_sales_order_renderer_replace'
    ));

Then i created a renderer file as suggested by Sunil.

app/code/local/SML/Exportorders/Block/Adminhtml/Sales/Order/Renderer/Replace.php

class SML_Exportorders_Block_Adminhtml_Sales_Order_Renderer_Replace extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract {
public function render(Varien_Object $row) {
$value =  $row->getData($this->getColumn()->getIndex());

return str_replace('.', ',', $value);

}}

Solution

  • Radia, please check following link of mine for options

    Magento: Decimal Price in spanish language display Dot instead comma

    this will change the . to , everywhere on the website, if needed only for this particular column you can use

    str_replace(',', '.', $form);
    

    in the renderer of the output