2015-11-02 110 views
0

我正在嘗試編輯訂單網格,以便我可以將數據導出到每一行上銷售的每件物品的數量。 現在我只能訪問訂單的總金額,這是不夠的。我想在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', 
     )); 

但是我沒有得到任何總量,當然我沒有得到在每個訂單的產物分割。我真的不知道在哪裏尋找實施這種產品分割。

提前致謝。

編輯:

這裏是什麼我得到感謝延伸

Order grid

但是,我不能,因爲最後一列是其他「嵌入式」的一種出口該產品分信息。所以我在XML中得到一個空列。

回答

0

我通常不建議擴展 - 我相信大多數人都可以多一點的麻煩比他們的價值,但在這種情況下,我不建議這一個:

http://www.magentocommerce.com/magento-connect/enhanced-admin-grids-editor.html

這是免費代碼相當乾淨,您可以通過單擊訂單頁面上的網格自定義按鈕,單擊更多選項,然後查找項目並下拉並添加這些列來添加。將向您顯示所有項目的表格。

如果您想發佈您編寫自定義方式的代碼,我可以幫助您自定義該方法來完成這項工作。

+0

嗨,非常感謝您的回覆。 我會看看這個擴展。我更新了我在Grid.php中嘗試做的問題;) – Iuqnod

+0

我看到了 - 你能發佈整個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

+0

是的,工作,現在我得到與訂單相關的總量。我也試過你的擴展。我設法爲每個我想要的訂單添加產品拆分,但是我無法將其導出到XML。我會給你看。 – Iuqnod

0

我們發佈了關於如何將任何數據添加到訂單網格的完整博客文章。希望對你有幫助! 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'; 
} 
} 

的鏈接會告訴你其他的例子,如何在順序網格顯示數據。