Jump to content

Overriding AdminCustomersController.php doesn't work


Big_Berny

Recommended Posts

Hi guys

I use some overrides to change some core functionalities which works great normally.

 

But now I want to replace "public function __construct()" from AdminCustomersController.php and it just doesn't seem to work.

 

What I want: I need an additional column if I click on "Customers" in the backend. As I found I this works quite by adding these lines (for SIRET) in line 99 of the original AdminCustomersController.php:

  'siret' => array(
   'title' => $this->l('SIRET'),
   'width' => 'auto'
  ),

 

But since this change is not safe when we update I tried to copy the whole "public function __construct()" to the override file it just doesn't work. It just doesn't create the new siret field if I only define it in the override. The code is:

<?php
class AdminCustomersController extends AdminCustomersControllerCore
{
public function __construct()
{
 $this->required_database = true;
 $this->required_fields = array('newsletter','optin');
 $this->table = 'customer';
 $this->className = 'Customer';
 $this->lang = false;
 $this->deleted = true;
 $this->explicitSelect = true;
 $this->addRowAction('edit');
 $this->addRowAction('view');
 $this->addRowAction('delete');
 $this->bulk_actions = array('delete' => array('text' => $this->l('Delete selected'), 'confirm' => $this->l('Delete selected items?')));
 $this->context = Context::getContext();
 $this->default_form_language = $this->context->language->id;
 $genders = array();
 $genders_icon = array('default' => 'unknown.gif');
 foreach (Gender::getGenders() as $gender)
 {
  $gender_file = 'genders/'.$gender->id.'.jpg';
  if (file_exists(_PS_IMG_DIR_.$gender_file))
   $genders_icon[$gender->id] = '../'.$gender_file;
  else
   $genders_icon[$gender->id] = $gender->name;
  $genders[$gender->id] = $gender->name;
 }
 $this->_select = '
 a.date_add,
 IF (YEAR(`birthday`) = 0, "-", (YEAR(CURRENT_DATE)-YEAR(`birthday`)) - (RIGHT(CURRENT_DATE, 5) < RIGHT(birthday, 5))) AS `age`, (
  SELECT c.date_add FROM '._DB_PREFIX_.'guest g
  LEFT JOIN '._DB_PREFIX_.'connections c ON c.id_guest = g.id_guest
  WHERE g.id_customer = a.id_customer
  ORDER BY c.date_add DESC
  LIMIT 1
 ) as connect';
 $this->fields_list = array(
  'id_customer' => array(
   'title' => $this->l('ID'),
   'align' => 'center',
   'width' => 20
  ),
  'id_gender' => array(
   'title' => $this->l('Titles'),
   'width' => 70,
   'align' => 'center',
   'icon' => $genders_icon,
   'orderby' => false,
   'type' => 'select',
   'list' => $genders,
   'filter_key' => 'a!id_gender',
  ),
  'lastname' => array(
   'title' => $this->l('Last Name'),
   'width' => 'auto'
  ),
  'firstname' => array(
   'title' => $this->l('First name'),
   'width' => 'auto'
  ),
  'siret' => array(
   'title' => $this->l('SIRET'),
   'width' => 'auto'
  ),
  'email' => array(
   'title' => $this->l('E-mail address'),
   'width' => 140,
  ),
  'age' => array(
   'title' => $this->l('Age'),
   'width' => 20,
   'search' => false,
   'align' => 'center'
  ),
  'active' => array(
   'title' => $this->l('Enabled'),
   'width' => 70,
   'align' => 'center',
   'active' => 'status',
   'type' => 'bool',
   'orderby' => false,
   'filter_key' => 'a!active',
  ),
  'newsletter' => array(
   'title' => $this->l('News.'),
   'width' => 70,
   'align' => 'center',
   'type' => 'bool',
   'callback' => 'printNewsIcon',
   'orderby' => false
  ),
  'optin' => array(
   'title' => $this->l('Opt.'),
   'width' => 70,
   'align' => 'center',
   'type' => 'bool',
   'callback' => 'printOptinIcon',
   'orderby' => false
  ),
  'date_add' => array(
   'title' => $this->l('Registration'),
   'width' => 150,
   'type' => 'date',
   'align' => 'right'
  ),
  'connect' => array(
   'title' => $this->l('Last visit'),
   'width' => 100,
   'type' => 'datetime',
   'search' => false,
   'havingFilter' => true
  )
 );
 $this->shopLinkType = 'shop';
 $this->shopShareDatas = Shop::SHARE_CUSTOMER;
 parent::__construct();
 // Check if we can add a customer
 if (Shop::isFeatureActive() && (Shop::getContext() == Shop::CONTEXT_ALL || Shop::getContext() == Shop::CONTEXT_GROUP))
  $this->can_add_customer = false;
}
}

 

Any idea, what could be the problem? Maybe the last "parent::__construct();"? Do I have to change that?

 

Thanks in advance!

Link to comment
Share on other sites

<?php
class AdminCustomersController extends AdminCustomersControllerCore
{
public function __construct()
{
 parent::__construct(); // This line has been moved to the top of the contructor

 $this->required_database = true;
 $this->required_fields = array('newsletter','optin');
// [...]
 $this->shopLinkType = 'shop';
 $this->shopShareDatas = Shop::SHARE_CUSTOMER;
 // Check if we can add a customer
 if (Shop::isFeatureActive() && (Shop::getContext() == Shop::CONTEXT_ALL || Shop::getContext() == Shop::CONTEXT_GROUP))
  $this->can_add_customer = false;
}
}

(untested, yet)

Edited by PhiLho (see edit history)
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...