我需要帮助。
我在Magento中创建了一个自定义报告。现在我想在我的网格中列出一个月内订购的所有产品。在我的报告中有以下几栏:SKU,名称,订购数量和基本成本。
在"订购数量"列中,我想显示产品的订购频率。在"基础成本"一栏中,我想显示总基础成本(订购数量*基础成本)。
使用下面的代码,我得到了正确的产品名称和skus。其他列不正确有人能帮帮我吗?
$this->getSelect()->reset()
->from(
array('order_items' => $this->getTable('sales/order_item')),
array(
'ordered_qty' => 'SUM(order_items.qty_ordered)',
'order_items_name' => 'order_items.name',
'base_cost' => 'SUM(order_items.base_cost)',
'sku' => 'order_items.sku'
))
->where("created_at BETWEEN '".$from."' AND '".$to."'")
->where('parent_item_id IS NULL')
->group('order_items.product_id')
->having('SUM(order_items.qty_ordered) > ?', 0)
->order(
array(
'SUM(order_items.qty_ordered) DESC'
));
我的解决方案是:
$this->getSelect()->reset()
->from(
array('order_items' => $this->getTable('sales/order_item')),
array(
'ordered_qty' => 'order_items.qty_ordered',
'order_items_name' => 'order_items.name',
'vendor' => 'attrval.value',
'base_cost' => '(SUM(order_items.qty_ordered) * order_items.base_cost)',
'sku' => 'order_items.sku'
))
->joinLeft(array('p' => 'catalog_product_entity'), 'order_items.product_id = p.entity_id')
->joinLeft(array('eav' => 'eav_attribute'), 'p.entity_type_id = eav.entity_type_id')
->joinLeft(array('attr' =>'eav_attribute_option'), 'attr.attribute_id = eav.attribute_id')
->joinLeft(array('attrval' =>'eav_attribute_option_value'), 'attrval.option_id = attr.option_id')
->where("eav.attribute_code='vendor'")
->where("order_items.created_at BETWEEN '".$from."' AND '".$to."'")
->where('parent_item_id IS NULL')
->group('order_items.product_id')
->having('SUM(order_items.qty_ordered) > ?', 0)
->order(
array(
'SUM(order_items.qty_ordered) DESC'
));
它包含了一个额外的自定义属性叫做'vendor'。
要输出原始SQL查询,请参见从Magento集合输出原始SQL查询
格式字段,您可以使用price
或currency
见http://code007.wordpress.com/2012/07/16/grid-column-types-in-magento/
$this->addColumn('some_column_id', array(
'header' => Mage::helper('core')->__('Some column name'),
'index' => 'some_column_index',
'type' => '???',
));
类型
- <
- 复选框/gh>
- concat 国家
- 货币
- datetime 输入>
- 界面 ip >
- 量变
- massaction
- 选项>价格
- 电台gh>
- 选择
- wrapline
参见/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer
文件夹。
要创建自己的网格类型,请参见http://mydons.com/how-to-create-custom-column-renderer-in-magento-grid/.