管理员按国家/地区自定义销售订单

时间:2016-04-01 11:18:00

标签: country sales

在我的自定义网格中,我有列表国家/地区代码,总订单和订购数量。 我没有得到total_order,因为我在mysql查询中得到它而不是在网格结果中,请检查下面的网格和集合代码: 在集合中:

protected function _addAddressFields()
{
    $shippingAliasName = 'shipping_o_a';
    $joinTable = $this->getTable('sales/order_address');

    $this->addFilterToMap('shipping_country_id', $shippingAliasName . '.country_id');

    $this
        ->getSelect()
        ->join(
            array($shippingAliasName => $joinTable),
            "(main_table.entity_id = {$shippingAliasName}.parent_id)",
            array(
                $shippingAliasName . '.country_id'
            )
        )
        ->columns(array('totals' => 'count(main_table.entity_id)'))
        ->group($shippingAliasName.'.country_id');
    Mage::getResourceHelper('core')->prepareColumnsList($this->getSelect());
    echo $this->getSelect();exit;
    return $this;
}

在网格中:

protected function _prepareColumns()
{
    $this->addColumn('country', array(
        'header'    =>Mage::helper('reports')->__('Country Code'),
        'index'     =>'country_id'
    ));

   $this->addColumn('total_orders', array(
        'header'    =>Mage::helper('reports')->__('Orders'),
        'index'     =>'totals'
    ));

    $this->addColumn('ordered_qty', array(
        'header'    =>Mage::helper('reports')->__('Quantity Ordered'),
        'width'     =>'120px',
        'align'     =>'right',
        'index'     =>'entity_id',
        'total'     =>'count',
        'type'      =>'number'
    ));

    //$this->addExportType('*/*/exportSoldCsv', Mage::helper('reports')->__('CSV'));
    //$this->addExportType('*/*/exportSoldExcel', Mage::helper('reports')->__('Excel XML'));

    return parent::_prepareColumns();
}

1 个答案:

答案 0 :(得分:0)

我已经解决了,并找到了如下答案:

public function addOrderedQty($from = '', $to = '')
{
    $adapter              = $this->getConnection();
    $orderTableAliasName = $adapter->quoteIdentifier('main_table');
    $adapter              = $this->getConnection();

    $shippingAliasName = 'shipping_o_a';
    $joinTable = $this->getTable('sales/order_address');

    $this->getSelect()->reset()
        ->from(array('main_table' => $this->getTable('sales/order')),
            array(
                'total_orders' => 'count(main_table.entity_id)'
            ))
        ->join(
            array($shippingAliasName => $joinTable),
            /*"(main_table.entity_id = {$shippingAliasName}.parent_id"
                . " AND {$shippingAliasName}.address_type = 'shipping')",*/
               "(main_table.entity_id = {$shippingAliasName}.parent_id)",
            array(
                $shippingAliasName . '.country_id'
            )
        )
        ->group($shippingAliasName.'.country_id');
    if ($from != '' && $to != '') {
        $fieldName            = $orderTableAliasName . '.created_at';
        $this->getSelect()->where($this->_prepareBetweenSql($fieldName, $from, $to));

    }
    //echo $this->getSelect();exit;
    return $this;

}