1

I added a new column to my sales order grid and it works perfectly. If I go the the recent orders grid from the customer view it doesn't work . I got an error message: Column not found: 1054 Unknown column 'c.increment_id' in 'field list'.

This is how I added the new column to my sales order grid:

public function beforeBlockToHtml(Varien_Event_Observer $observer)
    {
        $grid = $observer->getBlock();
        /**
         * Mage_Adminhtml_Block_Sales_Order_Grid
         */
        if ($grid instanceof Mage_Adminhtml_Block_Sales_Order_Grid) {
            $grid->addColumnAfter(
                'customer_increment_id',
                [
                    'header' => Mage::helper('ffm_codebin')->__('Customer Inc.'),
                    'index'  => 'customer_increment_id',
                    'filter_index' => 'c.increment_id'
                ],
                'entity_id'
            );
        }
    }
public function beforeCollectionLoad(Varien_Event_Observer $observer)
    {
        $collection = $observer->getCollection();
        if(!isset($collection)){
            return;
        }
        if($collection instanceof Mage_Sales_Model_Resource_Order_Grid_Collection){

            $collection->getSelect()->join(['c' => $collection->getTable('customer/entity')]
                ,'main_table.customer_id = c.entity_id', ['customer_increment_id' => 'increment_id']
            );
        }
    }

These are the events which I used: core_block_abstract_to_html_before and core_collection_abstract_load_before. Please note that I do not want to add a new column for the recent orders grid just for the sales order grid. What should I change in my code ?

Thx

  • what is you column name in 'customer/entity' table. because the right now it is looking for column name increment_id – Qaisar Satti May 3 '17 at 7:12
  • increment_id. But be aware there are orders increment_id and customer increment_id with the same column name. – Attila Naghi May 3 '17 at 7:14
  • try with c.increment_id they are not conflict but column name not correct. or did you create attribute for customer? – Qaisar Satti May 3 '17 at 7:16
  • doesnt work. Is there a way to somehow make a difference between the 2 grids ? – Attila Naghi May 3 '17 at 7:18
0

Not the best option, but it works (temporal coupling):

 private $grid;

 public function beforeBlockToHtml(Varien_Event_Observer $observer)
    {
        $this->grid = $observer->getBlock();
        /**
         * Mage_Adminhtml_Block_Sales_Order_Grid
         */
        if ($this->grid instanceof Mage_Adminhtml_Block_Sales_Order_Grid) {
            $this->grid ->addColumnAfter(
                'customer_increment_id',
                [
                    'header' => Mage::helper('ffm_codebin')->__('Customer Inc.'),
                    'index'  => 'customer_increment_id',
                    'filter_index' => 'c.increment_id'
                ],
                'entity_id'
            );
        }
    }
 public function beforeCollectionLoad(Varien_Event_Observer $observer)
    {
        $collection = $observer->getCollection();
        if(!isset($collection)){
            return;
        }

        if($collection instanceof Mage_Sales_Model_Resource_Order_Grid_Collection && $this->grid instanceof Mage_Adminhtml_Block_Sales_Order_Grid){
            $collection->getSelect()->join(['c' => $collection->getTable('customer/entity')]
                ,'main_table.customer_id = c.entity_id', ['customer_increment_id' => 'c.increment_id']
            );
        }
    }
| improve this answer | |

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.