Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3235082
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:27:56+00:00 2026-05-17T17:27:56+00:00

I have extended Magento’s customer information form to store an additional attribute for customer.

  • 0

I have extended Magento’s customer information form to store an additional attribute for customer. Lets call it ‘customer_referrer_id’.

I have a role ‘referrer ‘ who has access to customer grid and order grid only. But, I want to restrict a referrer to see only those customers in the grid who have the customer_referrer_id set as the referrer’s id who has logged in. Similarly for orders, the logged in referrer shall be able to see only those orders made by customers who have customer_referrer_id = loggedin_referrer_id.

I already know how to override a module and that I have to mainly override Adminhtml/Block/Customer/Grid::_prepareCollection and Adminhtml/Block/Sales/Order/Grid::_prepareCollection

I am using Magento 1.4.1.1

This is my module declaration file in app/etc/modules/Myproject_Adminhtml

<?xml version="1.0"?>

<config>
    <modules>
        <Myproject_Adminhtml>
            <active>true</active>
            <codePool>local</codePool>
            <depends>
                <Mage_Sales />
            </depends>
        </Myproject_Adminhtml>
    </modules>
</config>

And my modules config.xml in local/Myproject/Adminhtml/etc/ is as follows:

<config>
    <modules>
        <Myproject_Adminhtml>
            <version>1.0.0</version>
        </Myproject_Adminhtml>    
    </modules>

    <global>
          <blocks>
            <adminhtml>
                <rewrite>
                <sales_order_grid>Myproject_Adminhtml_Block_Sales_Order_Grid</sales_order_grid>
                <customer_grid>Myproject_Adminhtml_Block_Customer_Grid</customer_grid>
                </rewrite>
            </adminhtml>
        </blocks>
    </global>
</config>

And

class Myproject_Adminhtml_Block_Customer_Grid extends Mage_Adminhtml_Block_Customer_Grid
{
    protected function _prepareCollection()
    {
        $collection = Mage::getResourceModel('customer/customer_collection')
        ->addNameToSelect()
        ->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_region', 'customer_address/region', 'default_billing', null, 'left')
        ->joinAttribute('billing_country_id', 'customer_address/country_id', 'default_billing', null, 'left');    

        $this->setCollection($collection);

        $referrer_id = Mage::getSingleton('admin/session')->getUser()->getId();
        Mage::log('Logged in admin has id: ' . $referrer_id);

        return parent::_prepareCollection();
    }  
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T17:27:57+00:00Added an answer on May 17, 2026 at 5:27 pm

    My first attempt would be (for both files mentioned),

    $collection->addAttributeToFilter('customer_referrer_id', $referrer_id);
    

    Where $referrer_id is the value you must retrieve from the logged in user. Since you appear to be using admin users – which are separate entities from customers – this is one way of retrieving;

    $referrer_id = Mage::getSingleton('admin/session')->getUser()->getId();
    

    Note the currently logged in admin user is not apparent from the database alone so it cannot be a table join.

    On another point I would use the frontend for referrers instead of the admin. I would have the new customers and their orders shown in the referrer’s customer account, similar to their own “My Orders” page. Of course I don’t know what other requirements you have to attend to.

    Second part

    Override Mage_Adminhtml_Block_Sales_Order_Grid::_prepareCollection() to look like this:

    protected function _prepareCollection()
    {
        $collection = Mage::getResourceModel('customer/customer_collection');
        $collection->getSelect()->reset('columns'); // remove all customer columns
        $collection->addAttributeToFilter('entity_id', $referrer_id);
        $collection->joinTable('sales/order_grid', 'customer_id=entity_id', array('*'));
    
        $this->setCollection($collection);
        return parent::_prepareCollection();
    }
    

    This is necessary because the original table sales/order_grid is flat, not an entity collection, and so cannot be joined with attributes. The above works in reverse, by starting with a customer collection and then joining the flat table after.

    A possibly neater method would be to override sales/order_grid_collection with your own collection class which performs all this. Although it better follows coding conventions it is more work and no more functional in the end.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a windows form application, and I have extended the window's frame into
I have a class that has a complex static factory method, lets call it
I have an extended class for dateTime who makes some extra validation steps. When
I have a SharePoint site extended for forms authentication. The Active Directory site is
I have a FBA website and then I extended it (to use Windows Authentication)
I have a C++ Windows application that can be extended by writing C++ plugins,
I have 2 classes, main and extended. I need to use main vars in
Is there a way to write an enumeration that can be extended. I have
I have 'extended' the System.DateTime struct by adding some essential fields to it. Ideally
I have extended regexes enabled in my Bash by shopt -s extglob They may

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.