Adding Shipping Method to the Magento Order Grid

本文介绍如何在Magento的订单管理界面中添加一个显示运输方式的新列。通过修改Grid.php文件并加入特定代码,实现了将自定义属性整合到订单列表视图中,方便商家快速查看订单的运输详情。

Open /app/code/core/Mage/Adminhtml/Block/Sales/Order/Grid.php

Create the file structure of :

/app/code/local/Mage/Adminhtml/Block/Sales/Order/Grid.php

Copy the contents of the Core file, and paste into the Local version.

Find the protected function _prepareCollection.  You are going to modify this function by adding one line to make the custom attribute available for inserting into the grid.

Just add this line :
$collection->getSelect()->join('sales_flat_order', 'main_table.entity_id = sales_flat_order.entity_id',array('shipping_description'));

after this line:

$collection = Mage::getResourceModel($this->_getCollectionClass());
So altogether you should have a function that looks like this:
protected function _prepareCollection()
{
$collection = Mage::getResourceModel($this->_getCollectionClass());
$collection->getSelect()->join('sales_flat_order', 'main_table.entity_id = sales_flat_order.entity_id',array('shipping_description'));
$this->setCollection($collection);
return parent::_prepareCollection();
}

 

So now that you’ve modified that function we need to add the new column to the grid using the addColumn method.  So now find the _prepareColumns() function.

Now just add this code :
$this->addColumn('shipping_method', array(
'header' => Mage::helper('sales')->__('Shipping Method'),
'index' => 'shipping_description',
));

In order to prevent a massive “SQLSTATE[23000]: Integrity constraint violation: 1052 Column ‘status’ in where clause is ambiguous” ERROR when sorting your orders…Make sure you add this:
'filter_index'=>'main_table.status',
to the addColumn Status array

Now save and upload your new Local Grid.php file, login to Magento Admin, Browse to Sales > Orders  and you will see your BRAND NEW SHINY column!

 

Cheers!

To add custom functions to the NX menu, you can use the NXOpen.MenuBar class in NXOpen.NET API. Here is an example code that demonstrates how to add a custom function to the NX menu: ```vb Imports System Imports NXOpen Module Module1 Sub Main() ' Get the NX session Dim theSession As Session = Session.GetSession() ' Get the UI work part Dim theUI As UI = theSession.UI Dim lw As ListingWindow = theSession.ListingWindow ' Get the menu bar Dim menuBar As MenuBar = theUI.MenuBar ' Get the File menu Dim fileMenu As Menu = menuBar.GetMenu("File") ' Add a separator to the File menu fileMenu.AddSeparator() ' Add a custom function to the File menu Dim menuItem As MenuItem = fileMenu.AddMenuItem("Custom Function", AddressOf CustomFunction) ' Show a message box when the custom function is clicked Sub CustomFunction(ByVal item As MenuItem) lw.Open() lw.WriteLine("Custom function is clicked!") lw.Close() End Sub ' Start the NX message loop to display the menu theUI.NXMessageBox.Show("Menu Example", NXMessageBox.DialogType.Information, "Click OK to display the menu") theUI.NXMessageBox.GetMessage() ' Remove the custom function from the menu fileMenu.RemoveMenuItem(menuItem) End Sub End Module ``` In the above code, we first obtain the NX session and UI work part. Then, we get the MenuBar object using `theUI.MenuBar`. Next, we retrieve the desired menu (e.g., "File") using `GetMenu()` method. We can add a separator using `AddSeparator()` method and add a custom function using `AddMenuItem()` method, specifying the function to be called when the menu item is clicked. In the example above, the `CustomFunction` is a sub that will be executed when the custom function menu item is clicked. You can customize the behavior of this function to perform your desired actions. After adding the custom function, we start the NX message loop using `theUI.NXMessageBox.Show()` and `theUI.NXMessageBox.GetMessage()` to display the menu. Finally, we remove the custom function from the menu using `RemoveMenuItem()` method. Please note that above code is just an example, and you may need to adjust it based on your specific requirements and menu structure in NX.
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值