I am building my first Magento plugin that will hook into the event of when an order is placed, and export the order to a third party web service.

Now, rather than creating a separate table to store each order and its export status, I want to use the existing Magento Order table. Is this possible?

Also- I would love to be able to add a button or two to the Magento Administration Order section. Is this possible without modifying core Magento files? I want this to be a plug and play Plugin that doesn't require modification to core files.

If not, I will have to create a new section that the administrator can track the export status of orders.


To add fields to order grid

  1. Create a custom magento module.

  2. Using your module install script to add a field to table sales_flat_order_grid

    in /app/code/local/MagePal/ThirdPartyExporter/sql/thirdpartyexporter_setup/mysql4-install-0.1.0.php

        ALTER TABLE `{$this->getTable('sales/order_grid')}` 
            ADD COLUMN `magepal_internal_order_num` INT NULL;
  3. In your admin layout.xml add

    <?xml version="1.0"?>
        <reference name="sales_order.grid">
            <action method="addColumnAfter">
                <arguments module="sales" translate="header">
                    <header>MagePal #</header>
        <update handle="add_order_grid_column_handle" />
        <update handle="add_order_grid_column_handle" />
  4. To save/update magepal_internal_order_num in sales_flat_order_grid

    In /app/code/local/MagePal/ThirdPartyExporter/Model/Mysql4/Order.php

    public function updateOrderGrid($orderId, $array)
            return false;
        $db = $this->_getWriteAdapter();
            $array, 'entity_id = '. $orderId);
        return true;

    Then in /app/code/local/MagePal/ThirdPartyExporter/Model/Order.php

    public function updateOrderGrid($orderId, $uid)
        return $this->getResource()->updateOrderGrid($orderId, $uid);

    When you want to upgrade the info in sales_flat_order_grid you can now do

    Mage::getModel('thirdpartyexporter/order')->updateOrderGrid($order_id, array('magepal_internal_order_num' => 'your id here'));

You could also rewrite sales_order_grid see http://inchoo.net/ecommerce/magento/how-to-extend-magento-order-grid/


To add a buttons to your order view section

You can either:

  1. Rewrite Mage_Adminhtml_Block_Sales_Order_View. See How to add new button to order view in Magento admin panel

  2. Use observer/event. See Order view page print pdf button magento

    Use adminhtml_block_html_before instead of core_block_abstract_to_html_before


    Then in your observer.php

    if ($block->getId() == 'sales_order_view' && $block->getRequest()->getControllerName() == 'sales_order')

    or Assuming that you DO NOT have any other module rewriting Mage_Adminhtml_Block_Sales_Order_View block (if you have a module that rewrite that module class name e.g if(get_class($block) =='MagePal_Guest2Customer_Block_Adminhtml_Sales_Order_View'))

    if(get_class($block) =='Mage_Adminhtml_Block_Sales_Order_View')

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.