0

I'm using the code below to add an SKU field to the Orders page in the Magento Backend.

For the most part, the code works fine. SKU's are displayed in a column in the Orders page.

However, I've experienced an issue when searching orders using Magento's backend filter. When inputting a date and searching, the admin is redirected to the dashboard, and trying to access 'Sales > Orders' gives the following error:

There has been an error processing your request Exception printing is disabled by default for security reasons. Error log record number: 1404938437855

Code I'm using in grid.php (in app/code/core/mage/adminhtml/block/sales/order/grid.php - is this the right place for this code?)

public function callback_skus($value, $row, $column, $isExport) {
    $increment_id = $value;
    $_order = Mage::getModel('sales/order')->loadByIncrementId($increment_id);
    $_items = $_order->getAllItems();
    $skus="";
    foreach ($_items as $item) {
        $skus .= $item->getSku()."<br/>";
    }
    return $skus;
}

public function filter_skus($collection, $column) {
    if (!$value = $column->getFilter()->getValue()) {
        return $this;
    }

    $this->getCollection()->getSelect()->where(
        "sku like ?"
        , "%$value%");

    return $this;

}

and then

protected function _prepareCollection()
{

    $collection = Mage::getResourceModel($this->_getCollectionClass())
        ->join(
            'sales/order_item',
            '`sales/order_item`.order_id=`main_table`.entity_id',
            array(
                'skus'  => new Zend_Db_Expr('group_concat(`sales/order_item`.sku SEPARATOR ",")'),
            )
        );
    $collection->getSelect()->group('entity_id');
    $this->setCollection($collection);
    return parent::_prepareCollection();
}

and finally

    $this->addColumn('sku', array(
             'header' => Mage::helper('sales')->__('SKU'),
             'index' => 'increment_id',
             'frame_callback' => array($this, 'callback_skus'),
             'filter_condition_callback' => array($this, 'filter_skus'),
    ));

EDIT:

I also tried using this code:

public function filter_skus($collection, $column) {
    if (!$value = $column->getFilter()->getValue()) {
        return $this;
    }
    $this->getCollection()->getSelect()->join( array('table_alias'=>'sales_flat_order_item'), 'main_table.entity_id = table_alias.order_id',array('table_alias.sku'));
    $this->getCollection()->getSelect()->where("sku like ?", "%$value%");

    return $this;
}
  • go to var/report and open 1404938437855 . what is the error log ? – Manashvi Birla Apr 12 '16 at 4:51
0

I have seen you are modifying core files, it's bad idea never touch core files, Here is great tutorial for it :

  1. ADDING SKU COLUMN TO MAGENTO ORDERS GRID
  2. How to extend Magento Order Grid?

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.