Magento,使用XML标记方法扩展Order Grid,选择选项问题

时间:2012-02-20 19:52:12

标签: magento

我正在寻找一些如何在Magento订单网格中填充选择选项标题的示例。以下是创建新列,呈现数据并在列标题中输出选择菜单。问题是未在选择菜单中创建选项。

<layout>
    <!-- main layout definition that adds the column -->
    <add_order_grid_column_handle>
        <reference name="sales_order.grid">
            <action method="addColumnAfter">
                <columnId>customer_country_id</columnId>
                <arguments module="ordermanager" translate="header">
                    <header>Shipping Country</header>
                    <index>customer_country_id</index>
                    <type>options</type>
                    <sortable>true</sortable>
                    <options>Flipmedia_AddShippingCountryColumn_Adminhtml_Block_Widget_Grid_Column_Renderer_Country</options>
                    <renderer>Flipmedia_AddShippingCountryColumn_Adminhtml_Block_Widget_Grid_Column_Renderer_Country</renderer>
                </arguments>
                <after>status</after>
            </action>
        </reference>
    </add_order_grid_column_handle>

    <!-- order grid action -->
    <adminhtml_sales_order_grid>
        <!-- apply the layout handle defined above -->
        <update handle="add_order_grid_column_handle" />
    </adminhtml_sales_order_grid>

    <!-- order grid view action -->
    <adminhtml_sales_order_index>
        <!-- apply the layout handle defined above -->
        <update handle="add_order_grid_column_handle" />
    </adminhtml_sales_order_index>
</layout>



class Flipmedia_AddShippingCountryColumn_Adminhtml_Block_Widget_Grid_Column_Renderer_Country extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract {

    private static $_countryList = array();

    public function options(Varien_Object $row) {
         if (count(self::$_countryList) == 0) {          
            $countries =        Mage::getResourceModel('directory/country_collection')
                                    ->loadData()
                                    ->toOptionArray(false);
            foreach ($countries as $country) {
                self::$_countryList[$country['value']] = $country['label'];
            }
         }

         return self::$_countryList;
     }

    public function render(Varien_Object $row){
           $value = $this->_getValue($row);        
           $_countryList = $this->options();           
           return isset($_countryList[$value]) ? $_countryList[$value] : false;
        }
}

1 个答案:

答案 0 :(得分:3)

我认为问题在于您的<options>元素,如果您通过重写它来覆盖销售订单网格,则必须为选项指定静态函数。我看了一下,看起来你需要改变你调用它的方式。

您可以尝试使用<options>元素(例如

),而不是使用<filter>元素
<filter>Flipmedia_AddShippingCountryColumn_Adminhtml_Block_Widget_Grid_Column_Filter_Country</filter>

请注意新课程,它应该像这样延伸Mage_Adminhtml_Block_Widget_Grid_Column_Filter_Select ...查看the magento svn作为参考。

class Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Super_Config_Grid_Filter_Inventory extends Mage_Adminhtml_Block_Widget_Grid_Column_Filter_Select
{

    protected function _getOptions()
    {
        // return an array of options
        return array(
                array(
                'value' =>  '',
                'label' =>  ''
        ));
    }
}