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

Page 1 of 2
Changing Customer Filter Column To Display Customer “Company” (in Admin)
 
leetaylordoes
Sr. Member
 
Total Posts:  227
Joined:  2008-02-05
San Diego, CA
 

Hi All,

Has anyone tried to customize the “customer filter” inside the Admin yet? We want to change the filter columns by switching out one of the current columns (phone, email, zip, etc.) and add the “Business” that the customer is associated with.

I don’t believe it should be too much tweaking in order to replace one of those columns to show the “Business Field” - but I’m not familiar enough with the flow of things to be sure yet.

I’ll keep looking into this, though if anyone has any suggestions, I’m sure others in the community would find it helpful as well.

I notice most of the tweaking will take place within the following page:

app/code/core/Mage/Adminhtml/Block/Customer/Grid.php

Thanks,
- Lee

 
Magento Community Magento Community
Magento Community
Magento Community
 
leetaylordoes
Sr. Member
 
Total Posts:  227
Joined:  2008-02-05
San Diego, CA
 

A better question might be: “Where is the company name stored within the database so I can simply access it via the correct model and .php page?”

 
Magento Community Magento Community
Magento Community
Magento Community
 
leetaylordoes
Sr. Member
 
Total Posts:  227
Joined:  2008-02-05
San Diego, CA
 

I noticed the values for “company” are found within the “attribute_id” of the “customer_address_entity_varchar” table. The value associated with “attribute_id” “13” holds the company name.

Can someone mention how to access this inside the Grid.php page I mentioned?

An example would be super helpful.

I’m not familiar enough with the Zend Framework.

Thanks!
- Lee

 
Magento Community Magento Community
Magento Community
Magento Community
 
leetaylordoes
Sr. Member
 
Total Posts:  227
Joined:  2008-02-05
San Diego, CA
 

Hi all,

Any info on this?

All assistance is appreciated, and we’ll look forward to getting this figured out!

Thanks.

 
Magento Community Magento Community
Magento Community
Magento Community
 
leetaylordoes
Sr. Member
 
Total Posts:  227
Joined:  2008-02-05
San Diego, CA
 

So here’s the snippet of code that needs to be modified to display the “company” from each customer (See below: “Grid.php"), though I’m not sure how to get the correct values to show via the Zend Framework.

class Mage_Adminhtml_Block_Customer_Grid extends Mage_Adminhtml_Block_Widget_Grid
{

    
public function __construct()
    
{
        parent
::__construct();
        
$this->setId('customerGrid');
        
$this->setUseAjax(true);
        
$this->setDefaultSort('id');
    
}

    
protected function _prepareCollection()
    
{
        $collection 
Mage::getResourceModel('customer/customer_collection')
            ->
addAttributeToSelect('firstname')
            ->
addAttributeToSelect('lastname')
            ->
addExpressionAttributeToSelect('name',
                
'CONCAT({{firstname}}, " ", {{lastname}})',
                array(
'firstname''lastname'))
            ->
addAttributeToSelect('email')
            ->
addAttributeToSelect('created_at')
            ->
addAttributeToSelect('group_id')
            ->
joinAttribute('billing_postcode''customer_address/postcode''default_billing'null'left')
            ->
joinAttribute('billing_city''customer_address/city''default_billing'null'left')
            ->
joinAttribute('billing_telephone''customer_address/telephone''default_billing'null'left')
            ->
joinAttribute('billing_regione''customer_address/region''default_billing'null'left')
            ->
joinAttribute('billing_country_id''customer_address/country_id''default_billing'null'left');

        
$this->setCollection($collection);

        return 
parent::_prepareCollection();
    
}

    
protected function _prepareColumns()
    
{
        $this
->addColumn('id', array(
            
'header'    => Mage::helper('customer')->__('ID'),
            
'width'     => '50px',
            
'index'     => 'entity_id'
        
));
        
/*$this->addColumn('firstname', array(
            'header'    => Mage::helper('customer')->__('First Name'),
            'index'     => 'firstname'
        ));*/

        
$this->addColumn('lastname', array(
            
'header'    => Mage::helper('customer')->__('Company'),
            
'index'     => 'company'
        
));
        
$this->addColumn('name', array(
            
'header'    => Mage::helper('customer')->__('Name'),
            
'index'     => 'name'
        
));
        
$this->addColumn('email', array(
            
'header'    => Mage::helper('customer')->__('Email'),
            
'width'     => '150',
            
'index'     => 'email'
        
));

        
$groups Mage::getResourceModel('customer/group_collection')
            ->
addFieldToFilter('customer_group_id', array('gt'=> 0))
            ->
load()
            ->
toOptionHash();

        
$this->addColumn('group', array(
            
'header'    =>  Mage::helper('customer')->__('Group'),
            
'width'     =>  '100',
            
'index'     =>  'group_id',
            
'type'      =>  'options',
            
'options'   =>  $groups,
        ));

        
$this->addColumn('Telephone', array(
            
'header'    => Mage::helper('customer')->__('Telephone'),
            
'width'     => '100',
            
'index'     => 'billing_telephone'
        
));

Does anyone know if there are other files that need to be adjusted?
I do see we may need to set configuration up to access another table ("customer_address_entity_varchar") - and then access the correct field.

Any ideas?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Moshe
Magento Team
 
Avatar
Total Posts:  1770
Joined:  2007-08-07
Los Angeles
 

Need to add to the collection:

protected function _prepareCollection()
    
{
        $collection 
Mage::getResourceModel('customer/customer_collection')
// ...
// ADD THIS TO THE END:
            
->joinAttribute(
                
'billing_company'// field alias
                
'customer_address/company'// field source (entity/attribute)
                
'default_billing'// original entity binding attribute
                
null// no additional conditions for the join
                
'left' // left join to allow non-existing joined records
            
);
// ...
    
}

And to the columns:

$this->addColumn('company', array(
            
'header'    => Mage::helper('customer')->__('Company'),
            
'index'     => 'billing_company'
        
));
 
Magento Community Magento Community
Magento Community
Magento Community
 
leetaylordoes
Sr. Member
 
Total Posts:  227
Joined:  2008-02-05
San Diego, CA
 

Moshe,

You’re a stud.

Thanks for making the time to reply and resolve this issue.

Much appreciative,
- Lee

 
Magento Community Magento Community
Magento Community
Magento Community
 
nicolas46
Sr. Member
 
Total Posts:  210
Joined:  2008-04-09
Toulouse
 

I want to add in this grid the product like this :

order # | sku | price | qte | ...
100001 p1 50 2
100001 p2 54 1
100002 p1 10 1
100003 p7 5 4
100003 p8 50 1
100003 p4 70 5

It’s for use the existing method getCsv() to finaly export my orders

I don’t realy know what i have to write, if you can just give me an exemple to get in this grid the “sku” I will probably understand.

I have done this

$collection->getSelect() 
           ->
from(array("tableCMDentity"=>"mage_sales_order_entity"))
            ->
from(array("tableEAV"=>"mage_eav_attribute"))
            ->
from(array("tableVar"=>"mage_sales_order_entity_varchar"),array("sku"=>"value")         
            )
             ->
where("tableEAV.attribute_id=?",345// sku
             
->where("tableVar.attribute_id=tableEAV.attribute_id")
             ->
where("tableVar.entity_id=tableCMDentity.entity_id")
             ->
where("tableCMDentity.parent_id=e.entity_id");
And this :
$this->addColumn('sku', array(
            
'header'=> Mage::helper('sales')->__('sku'),
            
'width' => '80px',
            
'index' => 'sku',
        ));

It’s working good but i loose increment_id and i don’t think that the method i use is the good one.

Thanks a lot Moshe.

 
Magento Community Magento Community
Magento Community
Magento Community
 
nicolas46
Sr. Member
 
Total Posts:  210
Joined:  2008-04-09
Toulouse
 

help long face

 
Magento Community Magento Community
Magento Community
Magento Community
 
nicolas46
Sr. Member
 
Total Posts:  210
Joined:  2008-04-09
Toulouse
 

Maybe something like this :

$collection Mage::getResourceModel('sales/order_collection')        
            ->
addAttributeToSelect('*')
            ->
joinAttribute('billing_firstname''order_address/firstname''billing_address_id'null'left')
            ->
joinAttribute('billing_lastname''order_address/lastname''billing_address_id'null'left')
            ->
joinAttribute('shipping_firstname''order_address/firstname''shipping_address_id'null'left')
            ->
joinAttribute('shipping_lastname''order_address/lastname''shipping_address_id'null'left')
          ->
joinAttribute('sku''order_item/sku''*******'null'left')

But what i need to write instead of the “*****” ?

 
Magento Community Magento Community
Magento Community
Magento Community
 
kelvin
Jr. Member
 
Total Posts:  15
Joined:  2008-06-11
 

I’ve been working on the same problem as you nicolas46 today, I finally figured it out after a lot of trial and error, anyway here’s my code that will hopefully help you.

$collection Mage::getResourceModel('sales/order_collection')
            ->
addAttributeToSelect('*')
            ->
joinAttribute('parent_id_orig''order_item/entity_id''entity_id''parent_id''inner')
            ->
joinAttribute('sku''order_item/sku''parent_id_orig''''inner')
            ->
joinAttribute('product_name''order_item/name''parent_id_orig''''inner')
            ->
joinAttribute('original_price''order_item/original_price''parent_id_orig''''inner')
            ->
joinAttribute('price''order_item/price''parent_id_orig''''inner')
            ->
joinAttribute('discount_amount''order_item/discount_amount''parent_id_orig''''inner')
            ->
joinAttribute('qty''order_item/qty_ordered''parent_id_orig''''inner')
            ->
joinAttribute('shipping''order/shipping_amount''entity_id''''left')
            ->
addExpressionAttributeToSelect('row_total',
                
'SUM(({{price}}*{{qty}})-{{discount_amount}})',
                array(
'price''qty','discount_amount'))
            ->
setRowIdFieldName('parent_id_orig')
            ->
groupByAttribute('parent_id_orig');

I’ve used a sum expression to get the total but I think there’s an attribute called row_total_with_discount or something but I haven’t looked into how to get it yet. The only thing I need to finish my code is to get the shipped date but that’s proving harder than I thought. If anyone can give any insight into how to get that attribute I’ll really appreciate it.

 
Magento Community Magento Community
Magento Community
Magento Community
 
gamelodge
Sr. Member
 
Avatar
Total Posts:  89
Joined:  2007-08-31
Brisbane, Qld, Australia
 

Did you guys add this straight to the core code or did you overide this somwhere - if you added it to core how will updates/upgrades effect your code -
if you did it via overiding, PLEASE tell me the paths you used in XML config.xml becasue i am trying to override a grid in my module, but i am struggling with the correct path syntax

all i am trying to do is extend a method in a grid class in adminhtml

I have tried so many Combinations I have no idea how to tell the

core/adminhtml/block/sales/order/grid.php that i want to extend it.
I have added the below code in all combinations under <admin> under <global> under and even added extra tags like <global><adminhtml> aaarggggg!!!!! 

PLEASE HELP!!

<adminhtml>
    <
blocks>
      <
sales>
        <
order>
          <
rewrite>
            <
grid>Twg_Delivery_Block_Adminhtml_Sales_Order_Grid</grid>
          </
rewrite>
        </
order>
      </
sales>
    </
blocks>
  </
adminhtml>
 
Magento Community Magento Community
Magento Community
Magento Community
 
gamelodge
Sr. Member
 
Avatar
Total Posts:  89
Joined:  2007-08-31
Brisbane, Qld, Australia
 

I got the path:

GOT IT:

in

<global>
-----------------
    <
blocks>
      <
adminhtml>
        <
rewrite>
          <
sales_order_grid>Twg_Delivery_Block_Adminhtml_Sales_Order_Grid</sales_order_grid>
        </
rewrite>
      </
adminhtml>
    </
blocks>
---------------
</global>

I got advice from this wiki - http://www.magentocommerce.com/wiki/how_to_customize_backend_template_f.e._sales_order_information
But the last lines say to add the path to <default> - this did not work for me - it worked in global and only when i did it as ‘<sales_order_grid>’

some guidance from the magento team as to what is the correct way to do this would be gratefull

 
Magento Community Magento Community
Magento Community
Magento Community
 
gamelodge
Sr. Member
 
Avatar
Total Posts:  89
Joined:  2007-08-31
Brisbane, Qld, Australia
 

Please Help

I see nicolas46 had the same problem as me, he is unsure what the ‘// original entity binding attribute’
looking at moshe’s code and all the following i also cant really understand what you mean by ‘// original entity binding attribute’

I see steve figured it out - but i don’t really know what he did other than call everything parent_id_orig and then call
->setRowIdFieldName(’parent_id_orig’)
->groupByAttribute(’parent_id_orig’);

I am sorry if its obvious to you guys and if i sound really stupid, but i really am struggling to get my head around the whole EAV side of things and was wondering if you could explain it more ie moshs just saying ‘// original entity binding attribute’ may seem really obvious to you - what do you actually mean…

 
Magento Community Magento Community
Magento Community
Magento Community
 
mixwiz
Member
 
Total Posts:  39
Joined:  2008-07-21
 

Please also help again on this post.

I understand what Moshe has done but I am confused with how he has create the data collection?

 
Magento Community Magento Community
Magento Community
Magento Community
 
mixwiz
Member
 
Total Posts:  39
Joined:  2008-07-21
 
mixwiz - 12 September 2008 10:31 AM

Please also help again on this post.

I understand what Moshe has done but I am confused with how he has create the data collection?

I’m looking to remove the “ship to column” and replace it with the content of what they have ordered i.e. a list of products

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top
Page 1 of 2