Reputation: 83
I have added Delivery Date as a Custom Option on the Product. I want the Delivery Date to be displayed in the Sales Order Grid in admin.
I have created my local copy of Namespace_Module_Block_Adminhtml_Sales_Order_Grid
.
Here in the _prepareCollection()
function I am able to get the Product Options:
$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 ",")'),**
)
);
I then add the column as:
$this->addColumn('proptions', array(
'header' => Mage::helper('Sales')->__('Product Options'),
'width' => '100px',
'index' => 'proptions',
'renderer' => new Namespace_Module_Block_Adminhtml_Renderer_Data(),
));
Now in Namespace_Module_Block_Adminhtml_Renderer_Data()
I have a method:
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;
}
The display is not right. I don't think I'm looping through the array correctly. What am I doing wrong here?
Upvotes: 0
Views: 1101
Reputation: 71
If you want to do it in direct sql quesries open this file., ->app->design->adminhtml->default->default->template-> your template ->info.phtml and add this code
<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>
Upvotes: 1
Reputation: 83
Resolved by updating MySQL: SET SESSION group_concat_max_len = 1000000;
This can be set on the Global level as well. Thanks, Neet
Upvotes: 0