0

I've been able to add a few custom attributes to the sales order grid (sku, custom name). I am able to filter correctly. When I add the customer email, I can add and filter it too, but then if I filter by a total (e.g. base grand total) I get the error above. Other solutions suggest using filter_index to remove this ambiguity but this hasn't helped, presumably because it's on a field I'm not adding (grand total) - so this is not due to ambiguous entity_id. How do I make it use the specific total field?

Here are the helpful parts:

Observer

 class Kaska_ExtendedGrid_Model_Observer
{

public function salesOrderGridCollectionLoadBefore($observer)
{

    $collection = $observer->getOrderGridCollection();
    $select = $collection->getSelect();

    $select->join('m_sales_flat_order', '`m_sales_flat_order`.entity_id = `main_table`.entity_id', array('email'  => new Zend_Db_Expr('`m_sales_flat_order`.customer_email')));

    $select->joinLeft(array('payment' => $collection->getTable('sales/order_payment')), 'payment.parent_id=main_table.entity_id', array('payment_method' => 'method'));

    $select->join('m_sales_flat_order_item','`m_sales_flat_order_item`.order_id=`main_table`.entity_id', array('sku' => new Zend_Db_Expr('`m_sales_flat_order_item`.sku'),'name'  => new Zend_Db_Expr('`m_sales_flat_order_item`.name') ));

    $select->join('m_catalog_product_entity_varchar', '`m_catalog_product_entity_varchar`.attribute_id=163 AND `m_catalog_product_entity_varchar`.entity_id = `m_sales_flat_order_item`.`product_id`', array('attr'  => new Zend_Db_Expr('`m_catalog_product_entity_varchar`.value')));

    $select->group('main_table.entity_id');


}


public function filterEmail($collection, $column)
{

    if (!$value = $column->getFilter()->getValue()) {
        return $this;
    }
    $collection->getSelect()->having(
        "`m_sales_flat_order`.customer_email like ?", "%$value%");
    return $this;
}


.... filterSku etc

layout.xml

<sales_order_grid_update_handle>
    <reference name="sales_order.grid">
        <action method="addColumnAfter">
            <columnId>payment_method</columnId>
            <arguments>
                <header>Payment Method</header>
                <index>payment_method</index>
                <filter_index>payment.method</filter_index>
                <type>text</type>
            </arguments>
            <after>shipping_name</after>
        </action>
        <action method="addColumnAfter">
            <columnId>email</columnId>
            <arguments helper="kaska_extendedgrid/getEmailColumnParams" />
            <after>payment_method</after>
        </action>

Helper file

public function getEmailColumnParams(){
    return array(
    'header'    => 'Customer Email',
    'index'     => 'email',
    'type'        => 'text',
    'filter_index'=>'m_sales_flat_order.customer_email',
}

I also tried locally overriding the _prepareColumns of Mage/Adminhtml/Block/Sales/Order/Grid.php

$this->addColumn('base_grand_total', array(
        'header' => Mage::helper('sales')->__('G.T. (Base)'),
        'index' => 'base_grand_total',
        'type'  => 'currency',
        'currency' => 'base_currency_code',
     'filter_index' => 'sales_flat_order.base_grand_total'
    ));

EDIT After some help from below, the culprit was another extension's overriding of the order grid preparecolumns

1

Try with this by using Zend_Db_Expr, not sure it will fix.

$this->addColumn('base_grand_total', array(
        'header' => Mage::helper('sales')->__('G.T. (Base)'),
        'index' => 'base_grand_total',
        'type'  => 'currency',
        'currency' => 'base_currency_code',
     'filter_index' => new Zend_Db_Expr("main_table.base_grand_total")
    ));
  • I added that line in app/local/Mage/Adminhtml/Block/Sales/Order/Grid.php but it didn't fix it. Thanks for the suggestion. – Michael Feb 23 '16 at 16:54
  • Question: Did you override _prepareColumns callinf parent::_prepareColumns() inside of it? – Phoenix128_RiccardoT Feb 23 '16 at 16:59
  • Because the way you used is the right one. Just make sure you are not adding the same column two times by calling the parent's method. – Phoenix128_RiccardoT Feb 23 '16 at 17:07
  • At the end of the local _prepareColumns is return parent::_prepareColumns();. Is that what you mean? – Michael Feb 23 '16 at 17:27
  • Yep, you are probably adding the same field two times. Try overriding the whole method by copying its content from the parent and without calling the parent. My idea is that you are calling the addColumn two times. And your error is coming from the parent's method. – Phoenix128_RiccardoT Feb 23 '16 at 17:28

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.