2016-04-01 12 views
-1

In meiner benutzerdefinierten Grid habe ich Liste Ländercode, Gesamtauftrag und bestellte Menge. ich nicht immer total_order, wie ich es in mysql Abfrage aber nicht in dem Raster Ergebnis bin immer, überprüfen Sie bitte unten Code für Grid und Sammlung: In der Sammlung:Kundenauftrag nach Land in Admin

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; 
} 

Im Grid:

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(); 
} 

Antwort

0

ich habe es gelöst und gefunden, wie unten eine Antwort:

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; 

} 
Verwandte Themen