0

I'm gonna add the column in my order -> shipment grid!

I want to bring the "title" on 'sales_flat_shipment_track' table. And it has also "parent_id" column, means entity_id on sales_flat_shipment!

sales_flat_shipment_track

enter image description here

sales_flat_shipment

enter image description here

So i need to implement this requirment to Mage_Adminhtml_Block_Sales_Shipment_Grid

What code do i have to insert to protected function _prepareCollection() & protected function _prepareColumns() ?

I tried :

    protected function _prepareCollection()
{
    $collection = Mage::getResourceModel($this->_getCollectionClass());                 
    $collection->getSelect()->join('sales_flat_shipment_track', 'main_table.entity_id = sales_flat_shipment_track.parent_id', array('title'));

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

    protected function _prepareColumns()
{
    $methods = Mage::getSingleton('shipping/config')->getActiveCarriers();
    $shippingmethods = array();
    foreach($methods as $_ccode => $_carrier) {
        if($_methods = $_carrier->getAllowedMethods())  {
            if(!$_title = Mage::getStoreConfig("carriers/$_ccode/title"))
                 $_title = $_ccode;
               foreach($_methods as $_mcode => $_method)   {
                $_code = $_ccode . '_' . $_mcode;
                $shippingmethods[$_code]= $_title;
            }
        }
    }

     $this->addColumn('title', array(
        'header'=> Mage::helper('sales')->__('Shipping Method'),
        'width' => '80px',
        'type'  => 'options',
        'index' => 'title',
        'options' => $shippingmethods,
        ));

}

Please let me know it

Thank you so much!

1 Answer 1

0

If you want to bring your carrier information on grid, follow this instruction. Btw it would change the core file directly. What if you do not want to alter core file, please skip this post and i'll update after making local module.

Mage_Adminhtml_Block_Sales_Shipment_Grid

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

    $collection->getSelect()->joinLeft('sales_flat_shipment_track', 'main_table.entity_id = sales_flat_shipment_track.parent_id',array('title'))->group('title');

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


    protected function _prepareColumns()
{

    parent::_prepareColumns();

    $this->removeColumn('created_at');

    /*
    $methods = Mage::getSingleton('shipping/config')->getActiveCarriers();
    $shippingmethods = array();
    foreach($methods as $_ccode => $_carrier) {
        if($_methods = $_carrier->getAllowedMethods())  {
            if(!$_title = Mage::getStoreConfig("carriers/$_ccode/title"))
                 $_title = $_ccode;
               foreach($_methods as $_mcode => $_method)   {
                $_code = $_ccode . '_' . $_mcode;
                $shippingmethods[$_code]= $_title;
            }
        }
    }
    */

    $this->addColumn('increment_id', array(
        'header'    => Mage::helper('sales')->__('Shipment #'),
        'index'     => 'increment_id',
        'type'      => 'text',
    ));

    $this->addColumn('created_at', array(
        'header'    => Mage::helper('sales')->__('Date Shipped'),
        'index'     => 'created_at',
        'type'      => 'datetime',
        'filter_index' => 'main_table.created_at'
    ));

    $this->addColumn('order_increment_id', array(
        'header'    => Mage::helper('sales')->__('Order #'),
        'index'     => 'order_increment_id',
        'type'      => 'text',
    ));

    $this->addColumn('order_created_at', array(
        'header'    => Mage::helper('sales')->__('Order Date'),
        'index'     => 'order_created_at',
        'type'      => 'datetime',
    ));

    $this->addColumn('shipping_name', array(
        'header' => Mage::helper('sales')->__('Ship to Name'),
        'index' => 'shipping_name',
    ));

    $this->addColumn('total_qty', array(
        'header' => Mage::helper('sales')->__('Total Qty'),
        'index' => 'total_qty',
        'type'  => 'number',
    ));


    $this->addColumn('title', array(
        'header'=> Mage::helper('sales')->__('Shipping Method'),
        'width' => '80px',
        'type'  => 'text',
        'index' => 'title',
    ));

    $this->addExportType('*/*/exportCsv', Mage::helper('sales')->__('CSV'));
    $this->addExportType('*/*/exportExcel', Mage::helper('sales')->__('Excel XML'));

    return $this;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.