Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

How do i add “company name” field in orders section of back end. 
 
pcdjebay
Jr. Member
 
Total Posts:  3
Joined:  2011-02-24
 

Im trying to add a filterable column for company name in the orders section, so we can see right away which company has placed orders without clicking on each one. I know the file to modify is app/code/core/mage/adminhtml/block/sales/order/grid.php

Ive also figured out how to add the column by putting:

$this->addColumn('company', array(
            
'header'    => Mage::helper('customer')->__('Company'),
            
'index'     => 'billing_company'
        
));

after one of the other columns, however it does not contain data. I assume i need the code that goes after

$collection Mage::getResourceModel($this->_getCollectionClass());

If anyone can assist it would be great. Thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
SarathTomy
Sr. Member
 
Avatar
Total Posts:  146
Joined:  2009-03-13
Melbourne, Australia
 

Copy app/code/core/Mage/Adminhtml/Block/Sales/Order/Grid.php
–> app/code/local/Mage/Adminhtml/Block/Sales/Order/Grid.php

Add the code to show company name filter option after

$this->addColumn(\'grand_total\', array(
            
\'header\' => Mage::helper(\'sales\')->__(\'G.T. (Purchased)\'),
            
\'index\' => \'grand_total\',
            
\'type\'  => \'currency\',
            
\'currency\' => \'order_currency_code\',
        ));

$this->addColumn(\'company\', array(
            
\'header\'    => Mage::helper(\'sales\')->__(\'Company\'),
            
\'index\'     => \'company\',
        ));

Copy app/code/core/Mage/Core/Model/Mysql4/Collection/Abstract.php
–> app/code/local/Mage/Core/Model/Mysql4/Collection/Abstract.php

Add a function at the last

public function joinLeft($table$cond$cols=\'*\')
        
{
            
if (!isset($this->_joinedTables[$table])) {
                $this
->getSelect()->joinLeft(array($table=>$this->getTable($table)), $cond$cols);
                
$this->_joinedTables[$table] true;
            
}
            
return $this;
        
}

Then in app/code/local/Mage/Adminhtml/Block/Sales/Order/Grid.php about line 57 , you can find a protected function _prepareCollection().
To add a company name, you can add one left join to the collection

->joinLeft(\'order\'\'main_table.entity_id = order.entity_id\'\'company\');
 
Magento Community Magento Community
Magento Community
Magento Community
 
pcdjebay
Jr. Member
 
Total Posts:  3
Joined:  2011-02-24
 

This looks good but I do not have a folder or file that you mentioned

app/code/core/Mage/Core/Model/Mysql4/Collection/Abstract.php

Is there another place i can put it to allow this function to be accessed.

 
Magento Community Magento Community
Magento Community
Magento Community
 
youzer_naim
Jr. Member
 
Total Posts:  12
Joined:  2008-06-03
UK
 

Hey Sarath,

Thanks for this.  I was wondering if you could answer a question for me?

I had already added the joinLeft function etc as I needed to add a subtotal column to my tables a while back, however, trying to add the company name seems a little more difficult…

I have tried:

$collection->joinLeft('order''main_table.entity_id = order.entity_id''company');

however there is not a field “company” in the sales_flat_order table, therefore we need to go to the sales_flat_order_address table to find the company name for each order.  Sounds easy?

BUT… as soon as you look into the order_address table there is a major issue… there are 2 addresses per order (ie a default billing address and a default shipping address.)

This then means that the increment_id’s for both tables do not match and so there doesn’t seem to be any common ground for a join…

There is the customer_id field, but again, there are 2 addresses per customer_id and so the whole thing breaks down.

What I have tried to do is a leftJoin with a WHERE clause saying where the customer_id’s match and the address_type = billing join the tables, but I just cannot get it to work.

$address_type 'billing';
$collection->joinLeft('order_address''main_table.customer_id = order_address.customer_id''company')
->
where(order_address.address_type = ? , $address_type);

Do you have any ideas?

Thanks

Marc

 
Magento Community Magento Community
Magento Community
Magento Community
 
jimkent
Jr. Member
 
Total Posts:  1
Joined:  2012-03-19
 

If anyone can help me with this, I’ve tried what it says in this post and get an error.  I have no idea what to do next.
Parse error: syntax error, unexpected T_OBJECT_OPERATOR in
/app/code/local/Mage/Adminhtml/Block/Sales/Order/Grid.php on line 60

My line 60 looks like this:
->joinLeft(’order’, ‘main_table.entity_id = order.entity_id’, ‘company’);

It’s an easy fix, I just don’t know enough about this language to figure it out.

Thanks.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Amasty
Mentor
 
Avatar
Total Posts:  3988
Joined:  2009-11-10
 

Hi! You can use Customer Attributes Module to show name of the company at order grid, order view page, manage customers grid and billing info page.
The information about the company can be added by the customer at regictration page or on billing info page when register during checkout or by the admin when creating a customer account from admin panel.

See more details, user guide and live demo here http://amasty.com/customer-attributes.html

Image Attachments
customer atttributes-order grid.png
 
Magento Community Magento Community
Magento Community
Magento Community
 
AITOC
Guru
 
Avatar
Total Posts:  618
Joined:  2009-02-19
US
 

Hello,

AITOC Checkout Fields Manager extension allows for adding different types of fields to checkout steps of your online store. These custom fields can be added either separately for each checkout option or for both simultaneously. Data collected from customers can be displayed on order details page in both admin area and in customer’s account. With this extension you will also be able to add custom fields to customer registration page.

Please check out the product page with the full list of features and screen shots http://www.aitoc.com/en/magentomods_checkoutfieldsmanager.html?utm_source=Magento+Forum&utm;_medium=How+do+I?+Questions&utm;_campaign=Kr

Thanks,

 
Magento Community Magento Community
Magento Community
Magento Community
 
Kaushik Patel
Jr. Member
 
Total Posts:  28
Joined:  2011-12-24
 

try this its working…
http://hkpatel201.blogspot.in/2013/02/add-company-column-in-customer-grid.html

 
Magento Community Magento Community
Magento Community
Magento Community
 
rebeccama
Sr. Member
 
Avatar
Total Posts:  110
Joined:  2012-11-05
 

Did you check Additional Checkout Attributes Magento extension. You can add Text Field, Text Area, Date, Yes/No, Multiple Select, Dropdown, Checkbox, and Radio Button fields on any checkout stage. read more description here;

http://www.magentocommerce.com/magento-connect/additional-checkout-attributes-7685.html

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top