Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/magento/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在订单网格中添加自定义列(Magento 1.7.0.0)_Magento_Magento 1.7 - Fatal编程技术网

在订单网格中添加自定义列(Magento 1.7.0.0)

在订单网格中添加自定义列(Magento 1.7.0.0),magento,magento-1.7,Magento,Magento 1.7,在Magento 1.7.0.0中,我在订单网格中添加自定义列时遇到问题,我希望您能帮我一把。 基本上,我遵循了这个指南,它解释了我必须制作一个本地版本的/app/code/core/Mage/Adminhtml/Block/Sales/Order/Grid.php,并做了一些更改以获得我想要的额外列。按照上述指南,它说我必须编辑函数\u prepareCollection()来添加此行(指定要在数组中提取的字段) 以前 return parent::_prepareCollection();

在Magento 1.7.0.0中,我在订单网格中添加自定义列时遇到问题,我希望您能帮我一把。 基本上,我遵循了这个指南,它解释了我必须制作一个本地版本的
/app/code/core/Mage/Adminhtml/Block/Sales/Order/Grid.php
,并做了一些更改以获得我想要的额外列。按照上述指南,它说我必须编辑函数
\u prepareCollection()
来添加此行(指定要在数组中提取的字段)

以前

return parent::_prepareCollection();
并在
\u prepareColumns()
中添加两列,如下所示:

$this->addColumn('telephone', array(
        'header' => Mage::helper('sales')->__('Telephone'),
        'index' => 'telephone',
    ));

$this->addColumn('email', array(
        'header' => Mage::helper('sales')->__('Email'),
        'index' => 'email',
    ));
 if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/view')) {
        $this->addColumn('action',
            array(
                'header'    => Mage::helper('sales')->__('Action'),
                'width'     => '50px',
                'type'      => 'action',
                //~ 'getter'     => 'getId',
                'getter'     => 'getParentId',
                'actions'   => array(
                    array(
                        'caption' => Mage::helper('sales')->__('View'),
                        'url'     => array('base'=>'*/sales_order/view'),
                        'field'   => 'order_id',
                    )
                ),
                'filter'    => false,
                'sortable'  => false,
                'index'     => 'stores',
                'is_system' => true,
        ));
    }
public function getRowUrl($row)
{
    if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/view')) {
        //~ return $this->getUrl('*/sales_order/view', array('order_id' => $row->getId()));
        return $this->getUrl('*/sales_order/view', array('order_id' => $row->getParentId()));
    }
    return false;
}
就这样,显然。。。或者可能不是,因为我这样做时会抛出以下错误:

Item (Mage_Sales_Model_Order) with the same id "XXXX" already exist
根据下面的注释,解决方案是在
\u prepareCollection
$this->setCollection($collection)
之前添加以下行:

添加行后,订单网格现在显示的电子邮件和电话栏与我想要的一模一样,但结果显示分页停止工作,它只显示最近的20个,上面写着“第1页,共1页”“找到2条记录”。我似乎不明白为什么会发生这种情况,我看到的每一条评论都没有超出上面的最后一条说明。这个问题的原因可能是什么


我假设它可以复制,因为我没有对该模型进行任何其他修改。

尝试在addColumn函数中使用filter\u index:

$this->addColumn('telephone', array(
    'header' => Mage::helper('sales')->__('Telephone'),
    'index' => 'telephone',
     'filter_index' => 'tablename.telephone'
));
您可以通过打印sql查询找到表名:

var_dump((string)$collection->getSelect())

好了,解决了。这就是我所做的: 受这个答案的启发,我复制了一份文件
lib/Varien/Data/Collection/Db.php
,将其放在
app/core/local/Varien/Data/Collection/Db.php
下,并复制了该答案上建议的修改,以修复给我带来上述问题的组选择计数错误。到目前为止,它似乎奏效了

然而,行中有一个问题,当我点击订单时,它说订单“不再存在”,所以我检查了实际的url,结果发现url中的订单id与订单地址表中的“实体id”相同,与订单的实际关联id(父项id)不对应。在对MySQL查询进行了长时间的调整之后,我意识到问题出在我所做的
/app/code/local/Mage/Adminhtml/Block/Sales/Order/Grid.php
中的
\u prepareColumns()
getRowUrl()
函数调用的函数中,因为它们检索到了错误的Id。因此我做了以下更改:

\u prepareColumns()
中,在与Action列对应的代码中,我将“getter”更改为“getParentId”,如下所示:

$this->addColumn('telephone', array(
        'header' => Mage::helper('sales')->__('Telephone'),
        'index' => 'telephone',
    ));

$this->addColumn('email', array(
        'header' => Mage::helper('sales')->__('Email'),
        'index' => 'email',
    ));
 if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/view')) {
        $this->addColumn('action',
            array(
                'header'    => Mage::helper('sales')->__('Action'),
                'width'     => '50px',
                'type'      => 'action',
                //~ 'getter'     => 'getId',
                'getter'     => 'getParentId',
                'actions'   => array(
                    array(
                        'caption' => Mage::helper('sales')->__('View'),
                        'url'     => array('base'=>'*/sales_order/view'),
                        'field'   => 'order_id',
                    )
                ),
                'filter'    => false,
                'sortable'  => false,
                'index'     => 'stores',
                'is_system' => true,
        ));
    }
public function getRowUrl($row)
{
    if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/view')) {
        //~ return $this->getUrl('*/sales_order/view', array('order_id' => $row->getId()));
        return $this->getUrl('*/sales_order/view', array('order_id' => $row->getParentId()));
    }
    return false;
}
getRowUrl()
函数中,我在
getUrl()
函数中更改了$row语句,如下所示:

$this->addColumn('telephone', array(
        'header' => Mage::helper('sales')->__('Telephone'),
        'index' => 'telephone',
    ));

$this->addColumn('email', array(
        'header' => Mage::helper('sales')->__('Email'),
        'index' => 'email',
    ));
 if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/view')) {
        $this->addColumn('action',
            array(
                'header'    => Mage::helper('sales')->__('Action'),
                'width'     => '50px',
                'type'      => 'action',
                //~ 'getter'     => 'getId',
                'getter'     => 'getParentId',
                'actions'   => array(
                    array(
                        'caption' => Mage::helper('sales')->__('View'),
                        'url'     => array('base'=>'*/sales_order/view'),
                        'field'   => 'order_id',
                    )
                ),
                'filter'    => false,
                'sortable'  => false,
                'index'     => 'stores',
                'is_system' => true,
        ));
    }
public function getRowUrl($row)
{
    if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/view')) {
        //~ return $this->getUrl('*/sales_order/view', array('order_id' => $row->getId()));
        return $this->getUrl('*/sales_order/view', array('order_id' => $row->getParentId()));
    }
    return false;
}

现在它就像一个符咒。我希望这对其他人有帮助

问题在查询中。代替此查询:

$collection->getSelect()->join('magento_sales_flat_order_address', 'main_table.entity_id = magento_sales_flat_order_address.parent_id',array('telephone', 'email'));
您应该使用以下选项:

$collection->getSelect()->join('sales_flat_order_address', 'main_table.entity_id = sales_flat_order_address.parent_id AND sales_flat_order_address.address_type = "shipping" ',array('telephone', 'email'));

在表sales\u flat\u order\u address中,父项\u id重复。第一个用于计费,第二个用于发货。所以你只需要选择其中一个:账单还是发货。这些值位于列地址\u type…

我尝试了这个,但没有做任何不同。然而,我在这里发现了真正的问题:这是一行
$collection->getSelect()->group('main_table.entity_id'),如果我对上面的join()查询进行注释,并使group()查询保持打开状态,则会出现分页问题。它必须与此相关,即使这是填充列的唯一方式。