0

有没有办法在 Magento 管理员的“订单”下添加一个新的搜索字段?我希望能够按优惠券代码使用情况进行搜索(例如:按优惠券代码搜索:“sale2013”​​,在结账时找到所有应用该优惠券代码的订单)。

在此处输入图像描述

我能够将这些数据从 Magento DB 中提取出来,但我真的很想将此功能添加到 Magento 管理员中,以便让同事和我的老板更轻松。可以完成吗?如果可以,我可以从哪里开始?多谢你们。

4

2 回答 2

1

The coupon code used during checkout is stored on the primary order table (sales_flat_order) when the customer checks out. If there is no value, then no coupon code was used. However, the data for the grid in the admin comes from the sales_flat_order_grid table; it comes from there instead of the primary order table for performance reasons which become particularly evident on very high traffic sites.

Now that we know where the data is that you need to filter on, and where the data for the grid comes from, we can move on to build it!

The first thing that you will need to do is add a coupon_code column to the sales_flat_order_grid table matching the definition of the column on the sales_flat_order table. The values in the coupon_code column of sales_flat_order should automatically populate into sales_flat_order_grid once the matching column is there and your cache storage has been flushed.

The data is updated on the order save, so to be specific, new orders and orders updated via the admin (even a comment on the order) will have the data populated. For existing orders, run a data upgrade script to copy the values over.

After the data/schemas are in place, you'll want to have the grid show a filterable column for it. For this you will want to rewrite the Mage_Adminhtml_Block_Sales_Order_Grid class from your custom module (please don't edit the core files directly, it will haunt you later) and override the _prepareColumns method with one that includes your column definition:

    $this->addColumn('coupon_code', array(
        'header' => Mage::helper('sales')->__('Coupon Code'),
        'index' => 'coupon_code',
    ));

If you're very fresh on Magento development, I'd venture to say that I've only begun to help you. But you'll have plenty of reference points from which to dig in and build the functionality you need. HTH! :)

于 2013-01-15T01:41:10.780 回答
0

使用此扩展程序可以轻松地将新列添加到网格: https ://github.com/magento-hackathon/GridControl

gridcontrol.xml添加此扩展程序,在您的 etc 目录中编写您自己的扩展程序

然后这样的事情应该可以工作:

<?xml version="1.0"?>
<gridcontrol>
<grids>
    <order.grid>
        <coupon_code>
            <after>columnname</after>

            <add>
                <header>Coupon code</header>
                <type>text</type>
                <index>coupon_code</index>
                <joinField>coupon_code|sales/order|coupon_code|entity_id=entity_id||left</joinField>
            </add>
        </coupon_code>
    </order.grid>
</grids>
</gridcontrol>
于 2013-01-15T07:39:32.763 回答