2013-07-26 59 views
0

我已將交貨日期添加爲產品的自定義選項。我希望將交貨日期顯示在管理員的銷售訂單網格中。 我已經創建了Namespace_Module_Block_Adminhtml_Sales_Order_Grid的本地副本。在這裏,在_prepareCollection()函數,我能夠獲得產品選項:將產品自定義選項的交貨日期添加到magento中的銷售訂單網格

$collection = Mage::getResourceModel($this->_getCollectionClass()) 
     ->join(
     'sales/order_item', 
     '`sales/order_item`.order_id=`main_table`.entity_id', 
     array(

      **'proptions' => new Zend_Db_Expr('group_concat(`sales/order_item`.product_options SEPARATOR ",")'),** 

     ) 

    ); 

我然後添加列:

$this->addColumn('proptions', array(
     'header' => Mage::helper('Sales')->__('Product Options'), 
     'width'  => '100px', 
     'index'  => 'proptions', 
     'renderer' => new Namespace_Module_Block_Adminhtml_Renderer_Data(), 
    )); 
在Namespace_Module_Block_Adminhtml_Renderer_Data()

現在我有一個方法:

public function _getValue(Varien_Object $row) 
{ 
    $val = $row->getData($this->getColumn()->getIndex()); // row value 
    $array = unserialize($val); 

    //loop thru the $array and create a format string 
    // 
    $options = $array['options']; 
    $format_val = ''; 
    foreach ($options as $key=> $value) { 
     $format_val = $format_val . $key . "=>" . $value . " , "; 
    } 

    return $format_val; 

} 

顯示不正確。我沒有正確地循環訪問數組。有人能指導我做什麼,我在這裏做錯了嗎?

謝謝, 尼特

+0

嗨,這個問題似乎是因爲查詢返回的值不完整: – neetw

回答

0

通過更新的MySQL解決:group_concat_max_len SET SESSION = 1000000;

這也可以在全局級別上設置。 謝謝, 啃老族

1

如果你想這樣做的直接SQL quesries打開這個文件, - > APP->設計 - > adminhtml->默認 - >默認 - >模板 - >模板 - >信息。 phtml並添加此代碼

<div class="entry-edit"> 
      <div class="entry-edit-head"> 
       <h4 class="icon-head head-products"><?php echo Mage::helper('sales')->__('Delivery Time Information') ?></h4> 
      </div> 
     </div> 
     <div class="grid np"> 

$connection = Mage::getSingleton('core/resource')->getConnection('core_read'); 
//$write = Mage::getSingleton('core/resource')->getConnection('core_write');//for writing to database 
$sql = "SELECT * FROM tablename"; 

$results = $connection->fetchAll($sql); 
foreach($results as $result) { 
    echo $result['column_name']."<br/>"; 
} 
</div></div></div> 
相關問題