Jump to content

How to show company from address in customer list ?


Recommended Posts

Hello , guys i try to get company from address in AdminCustomerController but return me a sql error . How to get this data and print to backend cutomer list.

 $titles_array = array();
        $genders = Gender::getGenders($this->context->language->id);
        foreach ($genders as $gender) {
            /** @var Gender $gender */
            $titles_array[$gender->id_gender] = $gender->name;
        $this->_select .= ', ad.`company` as company_names';
        $this->_join = 'LEFT JOIN '._DB_PREFIX_.'address ad ON (a.id_customer = ad.id_customer)';
        $this->_join = 'LEFT JOIN '._DB_PREFIX_.'gender_lang gl ON (a.id_gender = gl.id_gender AND gl.id_lang = '.(int)$this->context->language->id.')';
        $this->_use_found_rows = false;
        $this->fields_list = array(
            'id_customer' => array(
                'title' => $this->l('ID'),
                'align' => 'text-center',
                'class' => 'fixed-width-xs'
            'title' => array(
                'title' => $this->l('Social title'),
                'filter_key' => 'a!id_gender',
                'type' => 'select',
                'list' => $titles_array,
                'filter_type' => 'int',
                'order_key' => 'gl!name'
            'firstname' => array(
                'title' => $this->l('First name')
            'lastname' => array(
                'title' => $this->l('Last name')
            'email' => array(
                'title' => $this->l('Email address')
           'company_names' => array(
             'title' => $this->l('Company')


Link to comment
Share on other sites

imho the problem is in the line

$this->_select .= ', ad.`company` as company_names';

should be

$this->_select = ', ad.`company` as company_names';

but I would recommend you

to change also the join ( it is not neccessary, but sometimes customer fills more addreses)

$this->_join = 'LEFT JOIN (SELECT id_customer, GROUP_CONCAT(DISTINCT company) AS company FROM '._DB_PREFIX_.'address GROUP BY id_customer) ad ON (a.id_customer = ad.id_customer)';


Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...