1

I need to display customer-email and product-name in admin panel order grid but my code return error.

2

How to add products to the order grid is out of scope for an answer here but there are extensions that already to this quite well.

I can recommend this one: http://www.xtento.com/magento-extensions/enhanced-order-grid.html

I am not affiliated with the vendor, but used it for a project, it was easy to integrate and the code quality was okay.

|improve this answer|||||
1

Declare a Module:

app/etc/modules/Namespace_Module.xml

Module declaration:

<?xml version="1.0"?>
<config>
    <modules>
        <Namespace_Module>
            <active>true</active>
            <codePool>local</codePool>
            <depends>
                <Mage_Adminhtml />
            </depends>
        </Namespace_Module>
    </modules>
</config>

Create module directory:

app/code/local/Namespace/Module

Create config file:

app/code/local/Namespace/Module/etc/config.xml

You will need to rewrite the Sales Order Grid block in the admin. You will also need to alter the collection to add customer emails to the collection.

Config:

<?xml version="1.0"?>
<config>
    <global>
        <blocks>
            <adminhtml>
                <rewrite>
                    <sales_order_grid>Namespace_Module_Block_Adminhtml_Sales_Order_Grid</sales_order_grid>
                </rewrite>
            </adminhtml>
        </blocks>
        <events>
            <sales_order_grid_collection_load_before>
                <observers>
                    <namespace_module>
                        <type>model</type>
                        <class>Namespace_Module_Model_Observer</class>
                        <method>salesOrderGridCollectionLoadBefore</method>
                    </namespace_module>
                </observers>
            </sales_order_grid_collection_load_before>
        </events>
    </global>
</config>

Now create the observer to alter the collection:

app/code/local/Namespace/Module/Model/Observer.php

Do a join of the collection before it is loaded:

<?php

class Namespace_Module_Model_Observer {

   public function salesOrderGridCollectionLoadBefore(Varien_Event_Observer $observer) {

       /** @var Mage_Sales_Model_Resource_Order_Grid_Collection $collection */
       $collection = $observer->getEvent()->getOrderGridCollection();

       $collection->getSelect()->join(
           array('customer_table' => $collection->getTable('customer/entity')),
           'main_table.customer_id = customer_table.entity_id',
           'email'
       );
   }
}

Rewrite the Grid block class to add a column:

app/code/local/Namespace/Module/Block/Adminhtml/Sales/Order/Grid.php

Block Class:

<?php

class Namespace_Module_Block_Adminhtml_Sales_Order_Grid extends Mage_Adminhtml_Block_Sales_Order_Grid {


    protected function _prepareColumns() {

        $this->addColumnAfter('customer_email', array(
                'header' => Mage::helper('customer')->__('Customer Email'),
                'index' => 'email',
                'type' => 'text',
                'width' => '100px',
        ), 'created_at');

        return parent::_prepareColumns();
    }

}

Now you will see the email of the customer who placed the order.

Products is a much different beast, but this gets you halfway there :)

|improve this answer|||||
  • 1
    Apparently it's not out of scope ;) – ladle3000 Feb 14 '15 at 2:36

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