2

I have done below code in my event observer to add custom column to my sales order grid and still do not display the column to my website's admin panel?

Here is my code:

app/code/community/Mjsi/Orderprint/etc/config.xml

<adminhtml>
 ---
  <events>
        <core_layout_block_create_after>
            <observers>
                <mjsi_orderprint_add_columns>
                    <class>Mjsi_Orderprint_Model_Observer</class>
                    <method>addColumnsToGrid</method>
                </mjsi_orderprint_add_columns>
            </observers>
        </core_layout_block_create_after>
        <core_block_abstract_prepare_layout_before>
            <observers>
                <orderprint_core_block_abstract_prepare_layout_before>
                    <class>Mjsi_Orderprint_Model_Observer</class>
                    <method>addMassAction</method>
                </orderprint_core_block_abstract_prepare_layout_before>
            </observers>
        </core_block_abstract_prepare_layout_before>
        <adminhtml_widget_container_html_before>
            <observers>
                <mjsi_orderprint>
                     <class>Mjsi_Orderprint_Model_Observer</class>
                     <method>adminhtmlWidgetContainerHtmlBefore</method>
                </mjsi_orderprint>
            </observers>
        </adminhtml_widget_container_html_before>
  <events>
 ---
</adminhtml>

app/code/community/Mjsi/Orderprint/Model/Observer.php

<?php

class Mjsi_Orderprint_Model_Observer
{
/** 
 * Add new column to orders grid
 *
 * @param Varien_Event_Observer $observer
 * @return $this
 */
public function addColumnsToGrid(Varien_Event_Observer $observer)
{
    $block = $observer->getEvent()->getBlock();

    // Check whether the loaded block is the orders grid block
    if (!($block instanceof Mage_Adminhtml_Block_Sales_Order_Grid)
        || $block->getNameInLayout() != 'sales_order.grid'
    ) {
        return $this;
    }

    // Add a new column rigth after the "Status" column
    $block->addColumnAfter('mjsi_orderprint', [
        'header' => $block->__('Printed'),
        'width' => '80px',
        'filter' => false,
        'renderer' =>'Mjsi_Orderprint_Block_Adminhtml_Sales_Order_Renderer_Printed',
        //'index' => 'coupon_rule_name',
    ], 'status');

    return $this;
}

public function addMassAction(Varien_Event_Observer $observer)
{
    $block = $observer->getEvent()->getBlock();

    if(get_class($block) =='Mage_Adminhtml_Block_Widget_Grid_Massaction'
        && $block->getRequest()->getControllerName() == 'sales_order')
    {
        $block->addItem('massPrintSalesOrders_order', array(
            'label' => 'Print Sales Orders',
       'url' => Mage::app()->getStore()->getUrl('*/*/massPrintSalesOrders'),
        ));
    }
}

public function adminhtmlWidgetContainerHtmlBefore($event) {

    $block = $event->getBlock();
    if ($block instanceof Mage_Adminhtml_Block_Sales_Order_View) {
        $block->addButton('order_print', array(
            'label'     => Mage::helper('sales')->__('Print Orders'),
            'onclick'   => 'setLocation(\'' . $block->getUrl('*/*/print') . '\')',
        ));           
    }
}
}

0

Your Answer

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