我们发布了关于如何将任何数据添加到订单网格的完整博客文章。希望对你有帮助! https://grafzahl-io.blogspot.de/2016/11/how-to-display-m2e-order-data-or.html
因此,解决办法是销售网格块复制到本地模块并添加列类似这样的例子:
$this->addColumn('order_type', array(
'header' => Mage::helper('sales')->__('Order Type'),
'width' => '100px',
'align' => 'left',
'index' => 'order_type',
'renderer' => 'yourmodule/adminhtml_sales_grid_renderer_m2eAttribute',
'filter_condition_callback' => array($this, '_filterM2eConditionCallback')
));
的filter_condition_callback是在网格块的方法。您可以在命名空间中看到渲染器是另一个类。在渲染器中,您可以定义列中显示的内容。 filter_condition_callback定义网格应该如何操作,以防有人按自定义列进行过滤。
它看起来是这样的:
/**
* filter callback to find the order_type
* of orders through m2e (amazon, ebay, ...)
*
* @param object $collection
* @param object $column
* @return Yourname_Yourmodule_Block_Adminhtml_Sales_Order_Grid
*/
public function _filterM2eConditionCallback($collection, $column) {
if (!$value = $column->getFilter()->getValue()) {
return $this;
}
if (!empty($value) && strtolower($value) != 'magento') {
$this->getCollection()->getSelect()
// join to the m2mepro order table and select component_mode
->join(
'm2epro_order',
'main_table.entity_id=m2epro_order.magento_order_id',
array('component_mode')
)
->where(
'm2epro_order.component_mode = "' . strtolower($value) . '"');
} elseif(strtolower($value) == 'magento') {
$this->getCollection()->getSelect()
->join(
'm2epro_order',
'main_table.entity_id=m2epro_order.magento_order_id',
array('component_mode')
)
->where(
'm2epro_order.component_mode = NULL');
}
return $this;
}
正如你可以看到,有两个加入到收集我们需要过滤的数据。
这是渲染器看起来像这将在网格中显示的数据:
class Yourname_Yourmodule_Block_Adminhtml_Sales_Grid_Renderer_M2eAttribute
extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
{
public function render(Varien_Object $row)
{
// do whatever you need, to display your data
// get the id of the row order data
$orderId = $row->getEntityId();
// get the related m2e order data
$orders = Mage::getModel('M2ePro/Order')
->getCollection()
->addFieldToSelect('component_mode')
->addFieldToFilter('magento_order_id', $orderId);
if($orders) {
$data = $orders->getFirstItem()->getData();
if(isset($data['component_mode'])) {
return ucfirst($data['component_mode']);
}
}
// return the string "magento" if there is no m2e relation
return 'Magento';
}
}
的链接会告诉你其他的例子,如何在顺序网格显示数据。
嗨,非常感谢您的回复。 我会看看这个扩展。我更新了我在Grid.php中尝试做的问题;) – Iuqnod
我看到了 - 你能发布整个Grid.php文件吗?你确定在_prepareCollection方法的$ this-> setCollection行上面添加这行吗? $ collection-> getSelect() - > joinLeft('sales_flat_order','main_table.entity_id = sales_flat_order.entity_id',array('total_qty_ordered')); – espradley
是的,工作,现在我得到与订单相关的总量。我也试过你的扩展。我设法为每个我想要的订单添加产品拆分,但是我无法将其导出到XML。我会给你看。 – Iuqnod