Magento:无法重写Widget Grid以优化过滤

时间:2015-06-21 09:50:56

标签: php xml magento shopping-cart

我正在研究Magento框架。

我想重写Mage_Adminhtml_Block_Widget_Grid以优化搜索过滤。

我在etc/config.xml上添加了重写块,并将名称块添加为grid_search_date

<config>
  <global>
    <helpers>
      <core>
        <rewrite>
          <data>Jdate_Format_Helper_Data</data>
        </rewrite>
      </core>
    </helpers>
    <blocks>
      <grid_search_date>
        <rewrite>
          <widget_grid>Jdate_Format_Block_Widget_Grid</widget_grid>
        </rewrite>
      </grid_search_date>
      <topmenu_admin_time>
        <rewrite>
          <widget_grid_column_renderer_date>Jdate_Format_Block_Widget_Grid_Column_Renderer_Date</widget_grid_column_renderer_date>
        </rewrite>
      </topmenu_admin_time>

    </blocks>
  </global>
</config>

您可以看到Jdate_Format_Block_Widget_Grid想要重写widget_grid,我们会转到此文件

class Jdate_Format_Block_Widget_Grid extends Mage_Adminhtml_Block_Widget_Grid
{   
    protected function _addColumnFilterToCollection($column)
    {   

        if ($this->getCollection()) {
            $field = ( $column->getFilterIndex() ) ? $column->getFilterIndex() : $column->getIndex();
            if ($column->getFilterConditionCallback()) {
                call_user_func($column->getFilterConditionCallback(), $this->getCollection(), $column);
            } else {
                $cond = $column->getFilter()->getCondition();
                die(var_dump($cond["orig_from"]));
                die(var_dump($cond["orig_to"]));
                if ($field && isset($cond)) {
                    $this->getCollection()->addFieldToFilter($field , $cond);
                }
            }
        }
        return $this;
    }   
}

但没有任何事情发生。但是,如果我直接将Widget_Grid文件更改为此文件,则可以正常运行。

有什么想法吗?

1 个答案:

答案 0 :(得分:1)

尝试

<global>
   <blocks>
      <adminhtml>  <!-- should be the name of the module -->
        <rewrite>
          <widget_grid>Jdate_Format_Block_Widget_Grid</widget_grid>
        </rewrite>
      </adminhtml>
   </blocks>
  .....