0

I am trying to add "sku" and "product name" to sales order grid with filtering.

I have created my joins but the columns are empty and I'm not sure what I have done incorrectly here...

Trying to get collection from sales/flat_order_item

protected function _prepareCollection()
{
    $collection = Mage::getResourceModel($this->_getCollectionClass());

    $collection->getSelect()->joinLeft(array('sfoi' => 'sales_flat_order_item'),
        'sfoi.parent_id=main_table.entity_id', array('sfoi.sku',
        'sfoi.name'));

    $this->setCollection($collection);
    return parent::_prepareCollection();
}

And add to the grid

protected function _prepareColumns()
{
    $this->addColumn('sku', array(
        'header'=> Mage::helper('sales')->__('Sku'),
        'width' => '80px',
        'type'  => 'text',
        'filter_index' => 'sfoi.sku',
    ));

    $this->addColumn('name', array(
        'header'=> Mage::helper('sales')->__('Product Name'),
        'width' => '80px',
        'type'  => 'text',
        'filter_index' => 'sfoi.name',
    ));
}

Can anyone see what I have done wrong here please..?

1
protected function _prepareColumns()
{
    $this->addColumn('sku', array(
        'header'=> Mage::helper('sales')->__('Sku'),
        'width' => '80px',
        'type'  => 'text',
        'index' => 'sfoi.sku',
        'filter_index' => 'sfoi.sku',
    ));

    $this->addColumn('name', array(
        'header'=> Mage::helper('sales')->__('Product Name'),
        'width' => '80px',
        'type'  => 'text',
        'index' => 'sfoi.name',
         'filter_index' => 'sfoi.name',
    ));
}

you haven't assign index to column

0

Step 1: Create the Renderer directory under /app/code/core/Mage/Adminhtml/Block/Sales/Order

Step 2: Create a Block File in /app/code/core/Mage/Adminhtml/Block/Sales/Order/Renderer/Red.php (You can use any name)

<?php


class
Mage_Adminhtml_Block_Sales_Order_Renderer_Red extends
Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract

    {
      public function render(Varien_Object $row)

       {

         //$value = $row->getData($this->getColumn()->getIndex());



        $order_id=$row->getData('increment_id');

        $order = Mage::getModel('sales/order')->loadByIncrementID($order_id);

        $items = $order->getAllItems();

        // print_r($items);exit();

            foreach ($items as $itemId => $item)

                {

                if($item->getSku())

                    {

                    $sku[] = $item->getSku();

                    }

                }

                if(count($sku))

                    {

                    $skutext = implode(',',$sku);

                    }

            $conbinetext=$skutext;

            return $conbinetext;

        }

    }



?>

Step 3: Add the Below Code in /app/code/core/Mage/Adminhtml/Block/Sales/Order/Grid.php

$this->addColumn('Shopby',


  array(


  'header'=>Mage::helper('catalog')->__('Sku'),

  'index' => 'shopby',

  'filter'=> false,


  'sortable'=>false,

  'renderer'=> 'Mage_Adminhtml_Block_Sales_Order_Renderer_Red',// THIS IS WHAT THIS POST IS ALL ABOUT

  ));
0

May be help some one

protected function _prepareCollection() {
    $collection = Mage::getResourceModel($this->_getCollectionClass());

    $collection->getSelect()->joinLeft('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 ", ")'),'names' => new Zend_Db_Expr('group_concat(sales_flat_order_item.name SEPARATOR ", ")')))->group('main_table.entity_id');

    $this->setCollection($collection);

    return parent::_prepareCollection();
}

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.