Magento订单网格:通过订单检索数量和产品
我正在尝试编辑订单网格,以便我可以将数据导出到每一行上销售的每件物品的数量。 现在我只能访问订单的总金额,这是不够的。我想在Order View> Information> Ordered items中为每个订单的信息构建一个Grid。Magento订单网格:通过订单检索数量和产品
这是可能的几行代码?
这里是我做了现在:从Grid.php
我试图在_prepareColumns(手动添加列)功能。
基本上,我尝试添加量柱:
$this->addColumn('total_qty_ordered', array(
'header' => Mage::helper('sales')->__('Qty'),
'index' => 'total_qty_ordered',
'filter_index' => 'sales_flat_order.total_qty_ordered',
));
但是我没有得到任何总量,当然我没有得到在每个订单的产物分割。我真的不知道在哪里寻找实施这种产品分割。
提前致谢。
编辑:
这里是什么我得到感谢延伸
但是,我不能,因为最后一列是其他“嵌入式”的一种出口该产品分信息。所以我在XML中得到一个空列。
我通常不建议扩展 - 我相信大多数人都可以多一点的麻烦比他们的价值,但在这种情况下,我不建议这一个:
http://www.magentocommerce.com/magento-connect/enhanced-admin-grids-editor.html
这是免费代码相当干净,您可以通过单击订单页面上的网格自定义按钮,单击更多选项,然后查找项目并下拉并添加这些列来添加。将向您显示所有项目的表格。
如果您想发布您编写自定义方式的代码,我可以帮助您自定义该方法来完成这项工作。
我们发布了关于如何将任何数据添加到订单网格的完整博客文章。希望对你有帮助! 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