I created a custom module to extend the sales order grid with a SKU column. It works well, until you search in that specific column.

Then I do receive a error message.

How can I solve this?

Then I got the following error message:

Uncaught Error: Using $this when not in object context in /app/code/local/Atwix/ExtendedGrid/Model/Observer.php:60 Stack trace: #0 /app/code/core/Mage/Adminhtml/Block/Widget/Grid.php(468): Atwix_ExtendedGrid_Model_Observer::filterSkus(Object(Atwix_ExtendedGrid_Model_Resource_Sales_Order_Grid_Collection), Object(Mage_Adminhtml_Block_Widget_Grid_Column)) #1 /app/code/core/Mage/Adminhtml/Block/Widget/Grid.php(457): Mage_Adminhtml_Block_Widget_Grid->_addColumnFilterToCollection(Object(Mage_Adminhtml_Block_Widget_Grid_Column)) #2 /app/code/core/Mage/Adminhtml/Block/Widget/Grid.php(534): Mage_Adminhtml_Block_Widget_Grid->_setFilterValues(Array) #3 /app/code/core/Mage/Adminhtml/Block/Sales/Order/Grid.php(61): Mage_Adminhtml_Block_Widget_Grid->_prepareCollection() #4 /app/code/local/Atwix/ExtendedGrid/Model/Observer.php on line 60

The file looks like this:

class Atwix_ExtendedGrid_Model_Observer
     * Joins extra tables for adding custom columns to Mage_Adminhtml_Block_Sales_Order_Grid
     * @param Varien_Object $observer
     * @return Atwix_Exgrid_Model_Observer
    public function salesOrderGridCollectionLoadBefore($observer)
        $collection = $observer->getOrderGridCollection();
        $select = $collection->getSelect();
        $select->joinLeft(array('payment' => $collection->getTable('sales/order_payment')), 'payment.parent_id=main_table.entity_id', array('payment_method' => 'method'));

                array('address' => $collection->getTable("sales/order_address")),
                'main_table.entity_id = address.parent_id AND address.address_type = "shipping"',

        $select->join('sales_flat_order_item', '`sales_flat_order_item`.order_id=`main_table`.entity_id', array('skus' => new Zend_Db_Expr('group_concat(`sales_flat_order_item`.sku SEPARATOR ", ")')));

     * callback function used to filter collection
     * @param $collection
     * @param $column
     * @return $this
    public function filterSkus($collection, $column)
        if (!$value = $column->getFilter()->getValue()) {
            return $this;

            "group_concat(`sales_flat_order_item`.sku SEPARATOR ', ') like ?", "%$value%");

        return $this;

I'm guessing at which line is line 60, but you can like just replace the two return $this; statements with return;.

| 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.