Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>After a lot of trial and error - <em>a lot</em> of error - I think I have it now.</p> <p>To begin with the <code>sales_flat_order_grid</code> is updated in <code>Mage_Sales_Model_Mysql4_Order_Abstract::updateGridRecords()</code>, by following the trail I worked out it inspects both the "main" table (<code>sales_flat_order</code>) and the main table + "_grid" (<code>sales_flat_order_grid</code>), takes the intersect of their columns and constructs a query from that. So any column you need in the grid table must also be in the main table. It's not an EAV-style entity so attributes don't need to be created.<br> Here is my setup script:</p> <pre><code>&lt;?php /* @var $this Nexxt_Booth_Model_Entity_Setup */ $installer = $this; $installer-&gt;getConnection()-&gt;addColumn($installer-&gt;getTable('sales_flat_order'), 'box_num', 'varchar(255)'); $installer-&gt;getConnection()-&gt;addColumn($installer-&gt;getTable('sales_flat_order_grid'), 'box_num', 'varchar(255)'); </code></pre> <p>Next, I needed the extra column to show in all order tables in admin. To do this I overrode each relevant block.</p> <pre><code>&lt;?xml version="1.0"?&gt; &lt;config&gt; .... &lt;global&gt; &lt;blocks&gt; &lt;adminhtml&gt; &lt;rewrite&gt; &lt;customer_edit_tab_view_orders&gt; &lt;!-- Recent 5 orders on customer page --&gt; My_Module_Block_Adminhtml_Customer_Edit_Tab_View_Orders &lt;/customer_edit_tab_view_orders&gt; &lt;customer_edit_tab_orders&gt; &lt;!-- All orders on customer tab --&gt; My_Module_Block_Adminhtml_Customer_Edit_Tab_Orders &lt;/customer_edit_tab_orders&gt; &lt;sales_order_grid&gt; &lt;!-- All orders in Sales menu --&gt; My_Module_Block_Adminhtml_Sales_Order_Grid &lt;/sales_order_grid&gt; &lt;/rewrite&gt; &lt;/adminhtml&gt; &lt;/blocks&gt; &lt;/global&gt; &lt;/config&gt; </code></pre> <p>In <code>My/Module/Block/Adminhtml/Sales/Order/Grid.php</code> I made the following:</p> <pre><code>&lt;?php class My_Module_Block_Adminhtml_Sales_Order_Grid extends Mage_Adminhtml_Block_Sales_Order_Grid protected function _prepareColumns() { $this-&gt;addColumn('box_num', array( 'header' =&gt; $this-&gt;__('Box #'), 'index' =&gt; 'box_num', 'width' =&gt; '100px' )); $this-&gt;addColumnsOrder('box_num', 'shipping_name'); return parent::_prepareColumns(); } } </code></pre> <p>Similarly, in <code>My/Module/Block/Adminhtml/Customer/Edit/Tab/Orders.php</code> and <code>My/Module/Block/Adminhtml/Customer/Edit/Tab/View/Orders.php</code> I added this function:</p> <pre><code> protected function _prepareColumns() { $this-&gt;addColumn('box_num', array( 'header' =&gt; $this-&gt;__('Box #'), 'index' =&gt; 'box_num', 'width' =&gt; '100px' )); $this-&gt;addColumnsOrder('box_num', (Mage::app()-&gt;isSingleStoreMode() ? 'grand_total' : 'store_id')); return parent::_prepareColumns(); } </code></pre> <p>Finally, to finish off, in the event <code>sales_convert_quote_to_order</code> I populated the new field. This bit isn't as important, so long as you add the data at a point before the order is saved.</p> <pre><code>$order-&gt;setBoxNum('DATA GOES HERE'); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload