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
Tutorial : Adding a custom admin filter (aka groups) in a grip view (aka orders) in 10 steps
 
asrenzo
Member
 
Avatar
Total Posts:  42
Joined:  2008-02-25
France
 

Hi, here is my own experience based on these two tutorials ([tutorial1] and [tutorial2]) and php|architect’s Guide to Programming with Magento.

First of all, you’ll need a working magento setup.

Now, we’ve got two solutions for customizing Magento’s code :
The bad one : Editing and changing Magento’s core files
The clean one : Creating a package of your own and telling Magento you’ll replace core files with your files.

NB : In this document, I’ll suppose you are using a *nix system and your magento’s installation leaves in

/var/www/html/magento

1 - Prepare your package’s location

mkdir -/var/www/html/magento/app/code/local/AsRenzoCorp
You need to create your own package where all your customizations will be placed. In this example my package will be named AsRenzoCorp.

2 - Find the file you need to customize

The core file we need to change to add customer groups to orders list is

/var/www/html/magento/app/code/core/Mage/Adminhtml/Block/Sales/Order/Grid.php

3 - Create your package’s path

mkdir -/var/www/html/magento/app/code/local/AsRenzoCorp/Adminhtml/Block/Sales/Order

4 - Copy original file to your custom location

cd /var/www/html/magento/app/code/local/AsRenzoCorp/Adminhtml/Block/Sales/Order
cp 
/var/www/html/magento/app/code/core/Mage/Adminhtml/Block/Sales/Order/Grid.php ./

5 - Edit your own Grid.php

vi /var/www/html/magento/app/code/local/AsRenzoCorp/Adminhtml/Block/Sales/Order/Grid.php

6 - Replace class definition
Change

class Mage_Adminhtml_Block_Sales_Order_Grid extends Mage_Adminhtml_Block_Widget_Grid
With
class AsRenzoCorp_Adminhtml_Block_Sales_Order_Grid extends Mage_Adminhtml_Block_Sales_Order_Grid
Namings are case sensitive and must reflect your system path

7 - Add your column declaration to the _prepareColumns() function

$this->addColumn('customer_group_id', array(
            
'header'=> Mage::helper('customer')->__('Group'),
            
'width' => '80px',
            
'index' => 'customer_group_id',
            
'renderer' => new AsRenzoCorp_Adminhtml_Block_Sales_Order_Renderer_CustomerGroup(),
            
'type' => 'options',
            
'options' => AsRenzoCorp_Adminhtml_Block_Sales_Order_Renderer_CustomerGroup::getCustomerGroupsArray(),
        ));

8 - Create the renderer defined in the above code

mkdir -/var/www/html/magento/app/code/local/AsRenzoCorp/Adminhtml/Block/Sales/Order/Renderer
Edit a new CustomerGroup.php file and paste the code below
vi /var/www/html/magento/app/code/local/AsRenzoCorp/Adminhtml/Block/Sales/Order/Renderer/CustomerGroup.php
<?php
class AsRenzoCorp_Adminhtml_Block_Sales_Order_Renderer_CustomerGroup extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract {

    
// Holds an associative array with customer_group_id and the associated label
    
private static $_customerGroups = array(); // "singleton"

    
public static function getCustomerGroupsArray() {
        
// Make sure the static property is only populated once
        
if (count(self::$_customerGroups) == 0{
            $customer_group 
= new Mage_Customer_Model_Group();
            
$customer_groups $customer_group->getCollection()->toOptionHash();
            
self::$_customerGroups $customer_groups;
        
}

        
return self::$_customerGroups;
    
}

    
// Transforms the customer_group_id into corresponding label
    
public function render(Varien_Object $row)
    
{
        $val 
$this->_getValue($row);
        
$customer_groups self::getCustomerGroupsArray();
        return isset(
$customer_groups[$val]) ? $customer_groups[$val] false;
    
}

}

9 - Tell Magento there is a new module available
Edit the local.xml file and add the declaration below into the <global> node

vi /var/www/html/magento/app/etc/local.xml

<modules>
                <
AsRenzoCorp_Adminhtml>
                        <
active>true</active>
                        <
codePool>local</codePool>
                </
AsRenzoCorp_Adminhtml>
         </
modules>

10 - Tell Magento to use your file instead of its own
Edit the local.xml file and add the declaration below into the <global> node

vi /var/www/html/magento/app/etc/local.xml

<blocks>
                <
adminhtml>
                        <
rewrite>
                                <
sales_order_grid>AsRenzoCorp_Adminhtml_Block_Sales_Order_Grid</sales_order_grid>
                        </
rewrite>
                </
adminhtml>
         </
blocks>

And you should see a new column in your orders grid view.

PS : You may need to clean the cache system before being able to see changes.

Laurent

 
Magento Community Magento Community
Magento Community
Magento Community
 
asrenzo
Member
 
Avatar
Total Posts:  42
Joined:  2008-02-25
France
 

Thank you VisualFrames wink

Hope this helps some of the people around here.

If someone wants to change anything, please let me know and I’ll edit original post.

Regards,

Laurent

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

Thanks for your job !

 
Magento Community Magento Community
Magento Community
Magento Community
 
Gaurav_Orbit
Jr. Member
 
Total Posts:  14
Joined:  2008-04-13
 

Thank you Laurent ,

This is the great article. this article great helps me to customize features of Magento,As i am new with Magento. 

I have one query,
It is compulsory to add initialization of modules and block code in local. you create local custom module. Is there any other option through which we do not want to change local. and we just define initialization code in local package specific xml file which resides in “ \magento\app\etc\modules\pkg_Module.xml “ rather than “ \magento\app\etc\local.xml” file.

Hope you getting my point.

Because when some times we need to override the magento installation files then local.xml is also override,And we lose our customized features.So we must want to considered override actions track.This is the only constraint that i have seen in this post.

Regards,
Gaurav Patel

 
Magento Community Magento Community
Magento Community
Magento Community
 
asrenzo
Member
 
Avatar
Total Posts:  42
Joined:  2008-02-25
France
 

@Gaurav_Orbit

I don’t think there is a way to create custom packages/modules without telling Magento where to find them.

The way you want it to be would force Magento to parse every directory under app/local to find xml files on every request.

I bet this would be a really time consuming action.

This is my point of view, not a documentation nor a member team advise.

Regards,

Laurent

 
Magento Community Magento Community
Magento Community
Magento Community
 
Gaurav_Orbit
Jr. Member
 
Total Posts:  14
Joined:  2008-04-13
 

Yes,this is really time consuming process.

But in this wiki article http://www.magentocommerce.com/wiki/how-to/customize_part_of_configuration You can just go through the following topic section.

“Which files are used in configuration?”

In this section you get how megento parse custom packages/modules initialization sequences to load configurations .xml files for customizing Modules.

But some how i try the same process of actions but there is still addchild(); fatal Error is occur.when i do not define module and Block initialization in local.xml.I define these code in “ \magento\app\etc\modules\pkg_Module.xml “.

I think according to wiki article it should work but any how i do not get success.

Hey Laurent can i get your chat id?So we can communicate regarding magento customization features.

Actually i want to create one custom module which will cover features of separate Vendor panel in magento ,With enhancing and customizing features of Magento admin panel.

Thanks a lot for your feedback.

Regards,
Gaurav Patel

 
Magento Community Magento Community
Magento Community
Magento Community
 
cckean31
Jr. Member
 
Total Posts:  11
Joined:  2008-09-07
 

Hi Laurent

Tx for your effort for the step by step instruction..

i’d tried to follow exactly the step, but i got error :-

Fatal error: Call to a member function setSaveParametersInSession() on a non-object in /home/myeseedc/domains/myeseed.com/public_html/pureseed/app/code/core/Mage/Adminhtml/Block/Widget/Grid/Container.php on line 59

u know why?

 
Magento Community Magento Community
Magento Community
Magento Community
 
lorenzo01
Sr. Member
 
Avatar
Total Posts:  221
Joined:  2007-09-06
France
 

Hello,
in addition of this tutorial very useful, is it possible to show only one customer group ? how to impose one customer group in the column ?
thanks for helps

 
Magento Community Magento Community
Magento Community
Magento Community
 
lorenzo01
Sr. Member
 
Avatar
Total Posts:  221
Joined:  2007-09-06
France
 

...finally, how can we view the orders only for one customer group and ban access to orders belonging to the others groups....please i need some helps !!
thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
lorenzo01
Sr. Member
 
Avatar
Total Posts:  221
Joined:  2007-09-06
France
 

...no solutions ? just a litlle help…

 
Magento Community Magento Community
Magento Community
Magento Community
 
Pierre SII
Jr. Member
 
Total Posts:  25
Joined:  2008-12-19
Nice, France
 

Hi guys,

I customized (with my own eav attribute filters) my order grid with no troubles.

I was just wondering if there a way to customize the columns position.

As long as I’m overloading the method “_prepareColumns()” of Adminhtml/Blocks/Sales/Order/Grid.php my cusomized colummns can be easily added at first or last position of the table.

But if I want to put them before the Action column How could I do ?

Thanks in advance for your ideas.

Cheers,

Pierre

 
Magento Community Magento Community
Magento Community
Magento Community
 
James Thompson
Jr. Member
 
Total Posts:  29
Joined:  2009-01-23
 

I used this technique to add a groups column to my order page but now the export to csv option doesn’t work. It just gives a 404.

Anyone got any ideas?

Edit: Just realise that the orders page doesn’t normally have an export to csv option, the non-working control was my failed attempt to export orders!

 
Magento Community Magento Community
Magento Community
Magento Community
 
r3sshin r3sshin
Jr. Member
 
Total Posts:  8
Joined:  2009-08-18
 
asrenzo - 27 May 2008 12:23 PM

Thank you VisualFrames wink

Hope this helps some of the people around here.

If someone wants to change anything, please let me know and I’ll edit original post.

Regards,

Laurent

Hi, what if i want to change the customergroup instead to sku? how do i go about doing it?

 
Magento Community Magento Community
Magento Community
Magento Community
 
r3sshin r3sshin
Jr. Member
 
Total Posts:  8
Joined:  2009-08-18
 

erm..anyone?

 
Magento Community Magento Community
Magento Community
Magento Community
 
r3sshin r3sshin
Jr. Member
 
Total Posts:  8
Joined:  2009-08-18
 

erm..any help guys?

 
Magento Community Magento Community
Magento Community
Magento Community
 
vinod_magento
Jr. Member
 
Total Posts:  5
Joined:  2009-12-17
 

I don’t think there is a way to create custom packages/modules without telling Magento where to find them.

The way you want it to be would force Magento to parse every directory under app/local to find xml files on every request.

I bet this would be a really time consuming action.

This is my point of view, not a documentation nor a member team advise.

Regards,

Laurent

Hi Lauren
you have done really really good job.
i have done something for xml file.
I have copy the content from local.xml file for our module .
Created new xml file for our module in app\etc\modules\
And put the copied content into the xml file.
Clear the cache and Refresh the page its working.

Is it ok?
or is it wrong way to create whole in custom module and control in custom module without editing core files.

waiting for reply
sorry for bad English

Thanks
vinod.

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