How to display customer email in orders.csv - magento

can someone help me? how can I add a new field in orders.csv file in Mangento? for example i want to have in csv file email and phone.
please click the link below to understand which export is talking about
http://i.stack.imgur.com/fBAHG.png
Thank you

You have to customize the Grid block : /app/code/core/Mage/Adminhtml/Block/Sales/Order/Grid.php
So You can do like this. If you already enabled the local module functionality, Please copy and paste it to this path /app/code/local/Mage/Adminhtml/Block/Sales/Order/Grid.php
And Open that new file ( pasted ), check this method _prepareColumns().
In this method, you have to add those attributes which you are gonna to export in order.csv.
Check the following:
....
$this->addColumn('customer_email', array(
'header' => Mage::helper('sales')->__('Email'),
'index' => 'customer_email',
));
....
After this, refresh the magento cache.
Please check the following code:
In Grid.php
protected function _prepareCollection()
{
$collection = Mage::getResourceModel($this->_getCollectionClass());
$collection->getSelect()
->join(
'customer_entity',
'main_table.customer_id = customer_entity.entity_id', array('customer_email' => 'email')
);
$this->setCollection($collection);
return parent::_prepareCollection();
}
Then in protected function _prepareColumns() function add following code:
$this->addColumn('customer_email', array(
'header' => Mage::helper('sales')->__('Email'),
'index' => 'customer_email',
));
After this, you must refresh the cache or login again.

Related

magento show content according to condition in admin grid

I have developed custom admin module. I have used the usual methods _prepareCollection and _prepareColumns to show the data in Grid.
protected function _prepareCollection()
{
$collection = Mage::getModel("wallets/sellerrequest")->getCollection();
$collection->getSelect()
->join( array('ce1' => 'customer_entity_varchar'), 'ce1.entity_id=main_table.seller_id and ce1.attribute_id = "5"', array('seller_name' => 'value'));
$this->setCollection($collection);
parent::_prepareCollection();
return $this;
}
protected function _prepareColumns()
{
$helper = Mage::helper('sellers');
$currency = (string) Mage::getStoreConfig(Mage_Directory_Model_Currency::XML_PATH_CURRENCY_BASE);
$this->addColumn('id', array(
'header' => $helper->__('Request No'),
'index' => 'id'
));
$this->addColumn('Requested Amount', array(
'header' => $helper->__('Requested Amount'),
'index' => 'request_amount'
));
$this->addColumn('Seller Name', array(
'header' => $helper->__('Seller Name'),
'index' => 'seller_name',
));
$this->addColumn('Status', array(
'header' => $helper->__('Status'),
'index' => 'status_flag'
));
All the data shows correctly according to the table values. But I want to show the Request Amount column values preceding with $ sign, e.g. $300 etc. Also, I want to show the status flag according to condition. Means if the status flag is 1 then I want to show the value as "Approved", if flag is 2 then "Pending" etc. How should I customize the collection data and show in grid according to my requirement? Help appreciated.
Thanks.
I have answered to a question similar to your requirement
How to properly add a shipping_description column in magento order grid?
Check my answer and try to compare with your problem. In this example there is the solution for our currency problem too.
So check this out.Hope it will be helpful.
Here you should implement Grid Renderer.
Here is complete tutorial for that : http://inchoo.net/magento/how-to-add-custom-renderer-for-a-custom-column-in-magento-grid/
You can customize the value of any colum

Not saving data when add multiple select attribute in product grid

I have created one custom module with add associated products concept. Created successfully. And Its working well.
But when i add "Multi select attribute" column in product grid with that option values, That entity value not saved.
If i removed that option values from that brand attribute drop down, Its saving fine.
I have shown my code below what i did for add multi select attribute column in product grid
under _prepareColumns() method
$attribute = Mage::getModel('eav/config')->getAttribute('catalog_product', 'brand'); // attribute code here
foreach ( $attribute->getSource()->getAllOptions(true, true) as $option)
{
if($option['value'] != '')
$valArr[$option['value']] = $option['label'];
}
$this->addColumn('brand', array(
'header'=> Mage::helper('catalog')->__('Brand'),
'align' => 'left',
'index' => 'brand',
'type' => 'options',
'options' => $valArr,
'renderer' => 'Mage_Adminhtml_Block_Catalog_Product_Renderer_Brands', // Will have to create the renderer.
'filter_condition_callback' => array($this, '_filterBrandCondition')
));
When i hide 'options' => $valArr, , All are working fine.
I can't able to understand, why its happening. Please suggest me your ideas. Thanks in advance.
Have you already created the _filterBrandCondition function ?
What Mage_Adminhtml_Block_Catalog_Product_Renderer_Brands look like ?

Add onclick method on checkbox on grid in sales order?

I have added a custom column at sales_order_grid table and add this code at _prepareColumns() functions at grid.php and this checkbox is now showing but i cann't add onclick function at this column ,
$this->addColumn('exported', array(
'header' => Mage::helper('sales')->__('Exported'),
'index' => 'exported',
'type' => 'checkbox',
'field_name'=>'exported_',
'values' => array(1,2),//$this->_getExported(),//
'onclick' => $this->getJsObjectName('addRelatedToExport'),
));
I am stuck from 4 days,Help me ,
Thanks in advance.
Include this function in your grid file. Grid.php
protected function _prepareMassaction(){
$this->setMassactionIdField('entity_id'); // code to make the checkbox related with
$this->getMassactionBlock()->setFormFieldName('form_field_name');
$this->getMassactionBlock()->addItem('addRelatedToExport', array(
'label'=> Mage::helper('ModuleName')->__('Add to Export'),
'url' => $this->getUrl('*/*/massRelatedExport')
));
return $this;
}
And then in the same module controller e.g ModuleName/controllers/adminhtml/someController
public function massRelatedExportAction(){
// your code here
}

Magento - Add zip code / postcode to the order grid in Magento 1.6.2

I am trying to get the order grid to display the postcode/ zip code of the of the customer.
I am trying to join the sales_flat_order_address alias with the collection but to no success.
protected function _prepareCollection() {
$collection = Mage::getResourceModel($this->_getCollectionClass());
$collection->getSelect()->join('sales_flat_order_address', 'main_table.entity_id = sales_flat_order_address.parent_id',array('postcode'));
//var_dump($collection);
$this->setCollection($collection);
return parent::_prepareCollection();
}
Can any one please help me figure out a solution for this.
Before return parent::_prepareCollection(); You should create a join:
$collection->getSelect()->joinLeft(array('billing'=>'sales_flat_order_address'),
'main_table.entity_id = billing.parent_id AND billing.address_type="billing"',array('billing.postcode AS bp'));
If you want the shipping postcode instead, use:
$collection->getSelect()->joinLeft(array('shipping'=>'sales_flat_order_address'),
'main_table.entity_id = shipping.parent_id AND shipping.address_type="shipping"',array('shipping.postcode AS sp'));
And in the method _prepareColumns paste:
$this->addColumn('bp', array(
'header' => Mage::helper('sales')->__('Billing Postcode'),
'index' => 'bp',
'width' => '60px',
'filter_index' => 'billing.postcode'
));
That worked for me in a recent project.

How to add website field in magento admin grid?

Im creating a custom module for banner slider. In admin grid I want to display website field. For that in namespace/module/Block/Adminhtml/banner/Grid.php file I added
if (!Mage::app()->isSingleStoreMode()) {
$this->addColumn('website_id', array(
'header' => Mage::helper('bannerslider')->__('Website'),
'align' => 'center',
'width' => '80px',
'type' => 'options',
'options' => Mage::getSingleton('adminhtml/system_store')->getWebsiteOptionHash(true),
'index' => 'website_id',
));
}
in _prepareColumns() function. Now I can able to see website column. But Im not able to see the website names in each rows. How can I show the website names in each rows. Please see the image.
What im missing?
Here is my collection.
protected function _prepareCollection()
{
$collection = Mage::getModel('bannerslider/bannerslider')->getCollection();
$this->setCollection($collection);
return parent::_prepareCollection();
}
I have a field called "website_id" in my table. Each row may have multiple values which are comma separated. In this situation can you tell me how to use collection?
In the _prepareCollection() function, you insert :
parent::_prepareCollection();
$this->getCollection()->addWebsiteNamesToResult();
If the website_id is in other tables..., you'll need to join the table and add the website_id in select, in the _prepareCollection() function.
protected function _prepareCollection() {
//Your custom code in here
}

Resources