1

this is not the most constructive question for Magento development. But this is certainly one that keeps me boggled ...

On the magento order grid in the backed we see that an order takes up multiple lines of space. 3 instead of 1 [in column Purchased From (Store)]. This is because we have a multistore. The resukt is that we see 1/3rd of the normal number of orders on 1 screen. No biggie, but something I want to change.

My question: How can I change the text in the column Purchased From (Store)? I would like it to be store view name or store domain. And maybe on mouseover a title is shown that does show the whole sequence. Example below.

I am looking at /app/code/core/Mage/Adminhtml/Block/Sales/Order/Grid.php but dont know how to go from there and actually change this.

@Mage/Ebay: Also I think this should be something to set on/off in config for future versions.

enter image description here

  • for that first you have to create your create custom module and override the sales grid – Keyul Shah Feb 22 '14 at 15:26
1

You're in the right place to start your investigation at app/code/core/Mage/Adminhtml/Block/Sales/Order/Grid.php. A look at _prepareColumns() indicates the renderer for that column:

protected function _prepareColumns()
{
    //snip...

    if (!Mage::app()->isSingleStoreMode()) {
        $this->addColumn('store_id', array(
            'header'    => Mage::helper('sales')->__('Purchased From (Store)'),
            'index'     => 'store_id',
            'type'      => 'store',
            'store_view'=> true,
            'display_deleted' => true,
        ));
    }

    //snip...
}

The type will result in this column being rendered by the Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Store::render() method:

public function render(Varien_Object $row)
{
    $out = '';
    $skipAllStoresLabel = $this->_getShowAllStoresLabelFlag();
    $skipEmptyStoresLabel = $this->_getShowEmptyStoresLabelFlag();
    $origStores = $row->getData($this->getColumn()->getIndex());

    if (is_null($origStores) && $row->getStoreName()) {
        $scopes = array();
        foreach (explode("\n", $row->getStoreName()) as $k => $label) {
            $scopes[] = str_repeat(' ', $k * 3) . $label;
        }
        $out .= implode('<br/>', $scopes) . $this->__(' [deleted]');
        return $out;
    }

    if (empty($origStores) && !$skipEmptyStoresLabel) {
        return '';
    }
    if (!is_array($origStores)) {
        $origStores = array($origStores);
    }

    if (empty($origStores)) {
        return '';
    }
    elseif (in_array(0, $origStores) && count($origStores) == 1 && !$skipAllStoresLabel) {
        return Mage::helper('adminhtml')->__('All Store Views');
    }

    $data = $this->_getStoreModel()->getStoresStructure(false, $origStores);

    foreach ($data as $website) {
        $out .= $website['label'] . '<br/>';
        foreach ($website['children'] as $group) {
            $out .= str_repeat('&nbsp;', 3) . $group['label'] . '<br/>';
            foreach ($group['children'] as $store) {
                $out .= str_repeat('&nbsp;', 6) . $store['label'] . '<br/>';
            }
        }
    }

    return $out;
}

What a terrible method! At most, block classes should handle view logic and prepare the data for rendering in a template context. Here we see an inflexible mix of logic and markup. Therefore you have two options to customize this:

  1. rewrite this method with the output marked up the way you like, or
  2. rewrite the grid class to change the renderer type being used.

Either case could be justified. Option #1 is the most direct, but it is likely to impact other views which use this same render. If that's what you want universally then go for it. For the latter you would declare a custom module block class group, rewrite the sales order grid class, and point to your custom renderer in the type parameter.

You are not alone in asking that eBay/Magento make this more flexible. There is a hackathon project which made grids configurable in XML, and Magento 2 has this listed as a feature.

1

I set store_view to false in file /app/code/core/Mage/Adminhtml/Block/Sales/Order/Grid.php

Would be great if one could set this via config in backend

    if (!Mage::app()->isSingleStoreMode()) {
        $this->addColumn('store_id', array(
            'header'    => Mage::helper('sales')->__('Purchased From (Store)'),
            'index'     => 'store_id',
            'type'      => 'store',
            'store_view'=> false,
            'display_deleted' => true,
        ));
    }

and edit /app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer/Store.php

function render

/**        foreach ($data as $website) {
            $out .= $website['label'] . '<br/>';
            foreach ($website['children'] as $group) {
                $out .= str_repeat('&nbsp;', 3) . $group['label'] . '<br/>';
                foreach ($group['children'] as $store) {
                    $out .= str_repeat('&nbsp;', 6) . $store['label'] . '<br/>';
                }
            }
        }
**/

NEW LINE:

foreach ($data as $website) { $out .= $website['label'];}

And while at it changed the width of the date column $this->addColumn('created_at'

  • Our dateformat is not AM/PM and set to 24hr in config->catalog
  • and why would this date string be longer than the column width?
  • 1
    You should implement this as a proper rewrite. Upgrade Magento and your change is gone :-/ – benmarks Feb 22 '14 at 15:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.