0

我已将交货日期添加为产品的自定义选项。我希望交货日期显示在管理员的销售订单网格中。我已经创建了Namespace_Module_Block_Adminhtml_Sales_Order_Grid.

_prepareCollection()函数中,我可以获得产品选项:

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

显示不正确。我认为我没有正确循环数组。我在这里做错了什么?

4

2 回答 2

1

如果您想在直接 sql 查询中执行此操作,请打开此文件。->app->design->adminhtml->default->default->template-> your template ->info.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>
于 2014-02-19T06:18:52.600 回答
0

通过更新 MySQL 解决:SET SESSION group_concat_max_len = 1000000;

这也可以在全局级别上设置。谢谢,尼特

于 2013-07-31T03:15:53.440 回答