dongse5528 2014-05-28 14:44
浏览 52

Magento自定义报告:从数据库中获取数据

I need some help.

I created a custom report in Magento. Now I want to list all products wich have been ordered in a month in my grid. In my report are the following columns: SKU, Name, Ordered Quantity and Base Cost.

In the column "Ordered Quantity" I want to show how often a product has been ordered. In the column "Base Cost" I want to show the total base costs (ordered quantity * base cost).

With the following code I get so correct product names and skus. The other columns are not correct.

Can someone help me?

$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'
            ));
  • 写回答

2条回答 默认 最新

  • douhao6557 2014-06-05 13:49
    关注

    To outputting the raw SQL query see Output raw SQL query from Magento collection

    Format field, you can use price or currency

    see 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' => '???',
      ));
    

    Types

    • action
    • checkbox
    • concat
    • country
    • currency
    • date
    • datetime
    • input
    • interface
    • ip
    • longtext
    • massaction
    • number
    • options
    • price
    • radio
    • select
    • store
    • text
    • theme
    • wrapline

    See /app/code/core/Mage/Adminhtml/Block/Widget/Grid/Column/Renderer folder.

    To make your own grid types see http://mydons.com/how-to-create-custom-column-renderer-in-magento-grid/.

    评论

报告相同问题?

悬赏问题

  • ¥100 c语言,请帮蒟蒻看一个题
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)