Rhapsody Posted January 7, 2013 Share Posted January 7, 2013 (edited) Solved: Thanks to Terragg the solution has been found. See his response in post #4. I have setup PS 1.5.3.1 and have successfully created overrides for certain Front Office functions, with the default theme I've copied, renamed and modified. Specifically I have created an override for /override/classes/customer.php that supports additional custom fields I have added to the ps_customer table. I have also successfully created overrides in /override/controllers/front for OrderOpcController.php to accommodate the additional custom fields. I am able to modify the /controllers/adminAdminCustomersController.php core to add the fields in the BO so I can view and edit what I want. I have been unsuccessful in getting PS to recognize an override to work using /override/controllers/admin/AdminCustomersController.php so when I upgrade, the modified files will not be overwritten. Has anyone used an override for the BO controllers and made it work? If so, any tips to pass on? Below is my override that is not recognized by the core code when I try it. <?php /* * Used PS 1.5.3.1 core to create override * Rhapsody Modified to add fields for spouse, yachtclub, boat * model, sailnum, phrfspin, phrfnonspin */ class AdminCustomerThreadsController extends AdminCustomerThreadsControllerCore { public function renderForm() { if (!($obj = $this->loadObject(true))) return; $genders = Gender::getGenders(); $list_genders = array(); foreach ($genders as $key => $gender) { $list_genders[$key]['id'] = 'gender_'.$gender->id; $list_genders[$key]['value'] = $gender->id; $list_genders[$key]['label'] = $gender->name; } $years = Tools::dateYears(); $months = Tools::dateMonths(); $days = Tools::dateDays(); $groups = Group::getGroups($this->default_form_language, true); $this->fields_form = array( 'legend' => array( 'title' => $this->l('Customer'), 'image' => '../img/admin/tab-customers.gif' ), 'input' => array( array( 'type' => 'radio', 'label' => $this->l('Titles:'), 'name' => 'id_gender', 'required' => false, 'class' => 't', 'values' => $list_genders ), array( 'type' => 'text', 'label' => $this->l('First name:'), 'name' => 'firstname', 'size' => 33, 'required' => true, 'hint' => $this->l('Forbidden characters:').' 0-9!<>,;?=+()@#"�{}_$%:' ), array( 'type' => 'text', 'label' => $this->l('Last name:'), 'name' => 'lastname', 'size' => 33, 'required' => true, 'hint' => $this->l('Invalid characters:').' 0-9!<>,;?=+()@#"�{}_$%:' ), array( 'type' => 'text', 'label' => $this->l('E-mail address:'), 'name' => 'email', 'size' => 33, 'required' => true ), array( 'type' => 'password', 'label' => $this->l('Password:'), 'name' => 'passwd', 'size' => 33, 'required' => ($obj->id ? false : true), 'desc' => ($obj->id ? $this->l('Leave blank if no change') : $this->l('5 characters min., only letters, numbers, or').' -_') ), array( 'type' => 'birthday', 'label' => $this->l('Birthday:'), 'name' => 'birthday', 'options' => array( 'days' => $days, 'months' => $months, 'years' => $years ) ), array( 'type' => 'text', 'label' => $this->l('Spouse name:'), 'name' => 'spouse', 'size' => 33, 'required' => false ), array( 'type' => 'text', 'label' => $this->l('Yacht Club:'), 'name' => 'yachtclub', 'size' => 33, 'required' => false ), array( 'type' => 'text', 'label' => $this->l('Boat name:'), 'name' => 'boat', 'size' => 33, 'required' => false ), array( 'type' => 'text', 'label' => $this->l('Boat model:'), 'name' => 'model', 'size' => 33, 'required' => false ), array( 'type' => 'text', 'label' => $this->l('Sail Number:'), 'name' => 'sailnum', 'size' => 10, 'required' => false ), array( 'type' => 'text', 'label' => $this->l('PHRF Spinnaker:'), 'name' => 'phrfspin', 'size' => 5, 'required' => false ), array( 'type' => 'text', 'label' => $this->l('PHRF Non-Spinnaker:'), 'name' => 'phrfnonspin', 'size' => 5, 'required' => false ), array( 'type' => 'radio', 'label' => $this->l('Status:'), 'name' => 'active', 'required' => false, 'class' => 't', 'is_bool' => true, 'values' => array( array( 'id' => 'active_on', 'value' => 1, 'label' => $this->l('Enabled') ), array( 'id' => 'active_off', 'value' => 0, 'label' => $this->l('Disabled') ) ), 'desc' => $this->l('Allow or disallow this customer to log in') ), array( 'type' => 'radio', 'label' => $this->l('Newsletter:'), 'name' => 'newsletter', 'required' => false, 'class' => 't', 'is_bool' => true, 'values' => array( array( 'id' => 'newsletter_on', 'value' => 1, 'label' => $this->l('Enabled') ), array( 'id' => 'newsletter_off', 'value' => 0, 'label' => $this->l('Disabled') ) ), 'desc' => $this->l('Customer will receive your newsletter via e-mail') ), array( 'type' => 'radio', 'label' => $this->l('Opt-in:'), 'name' => 'optin', 'required' => false, 'class' => 't', 'is_bool' => true, 'values' => array( array( 'id' => 'optin_on', 'value' => 1, 'label' => $this->l('Enabled') ), array( 'id' => 'optin_off', 'value' => 0, 'label' => $this->l('Disabled') ) ), 'desc' => $this->l('Customer will receive your ads via e-mail') ), ) ); // if we add a customer via fancybox (ajax), it's a customer and he doesn't need to be added to the visitor and guest groups if (Tools::isSubmit('addcustomer') && Tools::isSubmit('submitFormAjax')) { $visitor_group = Configuration::get('PS_UNIDENTIFIED_GROUP'); $guest_group = Configuration::get('PS_GUEST_GROUP'); foreach ($groups as $key => $g) if (in_array($g['id_group'], array($visitor_group, $guest_group))) unset($groups[$key]); } $this->fields_form['input'] = array_merge($this->fields_form['input'], array( array( 'type' => 'group', 'label' => $this->l('Group access:'), 'name' => 'groupBox', 'values' => $groups, 'required' => true, 'desc' => $this->l('Select all customer groups you would like to apply to this customer') ), array( 'type' => 'select', 'label' => $this->l('Default customer group:'), 'name' => 'id_default_group', 'options' => array( 'query' => $groups, 'id' => 'id_group', 'name' => 'name' ), 'hint' => $this->l('The group will be as applied by default.'), 'desc' => $this->l('Apply the discount\'s price of this group.') ) ) ); // if customer is a guest customer, password hasn't to be there if ($obj->id && ($obj->is_guest && $obj->id_default_group == Configuration::get('PS_GUEST_GROUP'))) { foreach ($this->fields_form['input'] as $k => $field) if ($field['type'] == 'password') array_splice($this->fields_form['input'], $k, 1); } if (Configuration::get('PS_B2B_ENABLE')) { $risks = Risk::getRisks(); $list_risks = array(); foreach ($risks as $key => $risk) { $list_risks[$key]['id_risk'] = (int)$risk->id; $list_risks[$key]['name'] = $risk->name; } $this->fields_form['input'][] = array( 'type' => 'text', 'label' => $this->l('Company:'), 'name' => 'company', 'size' => 33 ); $this->fields_form['input'][] = array( 'type' => 'text', 'label' => $this->l('SIRET:'), 'name' => 'siret', 'size' => 14 ); $this->fields_form['input'][] = array( 'type' => 'text', 'label' => $this->l('APE:'), 'name' => 'ape', 'size' => 5 ); $this->fields_form['input'][] = array( 'type' => 'text', 'label' => $this->l('Website:'), 'name' => 'website', 'size' => 33 ); $this->fields_form['input'][] = array( 'type' => 'text', 'label' => $this->l('Outstanding allowed:'), 'name' => 'outstanding_allow_amount', 'size' => 10, 'hint' => $this->l('Valid characters:').' 0-9', 'suffix' => '¤' ); $this->fields_form['input'][] = array( 'type' => 'text', 'label' => $this->l('Max payment days:'), 'name' => 'max_payment_days', 'size' => 10, 'hint' => $this->l('Valid characters:').' 0-9' ); $this->fields_form['input'][] = array( 'type' => 'select', 'label' => $this->l('Risk:'), 'name' => 'id_risk', 'required' => false, 'class' => 't', 'options' => array( 'query' => $list_risks, 'id' => 'id_risk', 'name' => 'name' ), ); } $this->fields_form['submit'] = array( 'title' => $this->l(' Save '), 'class' => 'button' ); $birthday = explode('-', $this->getFieldValue($obj, 'birthday')); $this->fields_value = array( 'years' => $this->getFieldValue($obj, 'birthday') ? $birthday[0] : 0, 'months' => $this->getFieldValue($obj, 'birthday') ? $birthday[1] : 0, 'days' => $this->getFieldValue($obj, 'birthday') ? $birthday[2] : 0, ); // Added values of object Group $customer_groups = $obj->getGroups(); $customer_groups_ids = array(); if (is_array($customer_groups)) foreach ($customer_groups as $customer_group) $customer_groups_ids[] = $customer_group; // if empty $carrier_groups_ids : object creation : we set the default groups if (empty($customer_groups_ids)) { $preselected = array(Configuration::get('PS_UNIDENTIFIED_GROUP'), Configuration::get('PS_GUEST_GROUP'), Configuration::get('PS_CUSTOMER_GROUP')); $customer_groups_ids = array_merge($customer_groups_ids, $preselected); } foreach ($groups as $group) $this->fields_value['groupBox_'.$group['id_group']] = Tools::getValue('groupBox_'.$group['id_group'], in_array($group['id_group'], $customer_groups_ids)); return parent::renderForm(); } } Edited January 29, 2013 by Rhapsody (see edit history) Link to comment Share on other sites More sharing options...
PhiLho Posted January 8, 2013 Share Posted January 8, 2013 (edited) I tried something similar, trying to cleanly apply a hack I found in this forum to allow HTML editing of Categories or Manufacturers. Except since my needs were small, so I just called parent::renderForm() inside the overridden function, and changed specific parts of $this->fields_form. It failed totally, rendering as a blank page. Perhaps I made a syntax error that was hidden by PS. I later learned how to get errors to be displayed, so I might try that again... Alas, the official doc. on overriding only shows small examples, not stuff like in our case. Edited January 8, 2013 by PhiLho (see edit history) Link to comment Share on other sites More sharing options...
Krystian Podemski Posted January 23, 2013 Share Posted January 23, 2013 (edited) Unfortunately, some time ago I had a similar problem. Only helped to extend (create another array for custom fields)... core file in order to extend ...core file Edited January 23, 2013 by Krystian Podemski (see edit history) Link to comment Share on other sites More sharing options...
Popular Post Terragg Posted January 28, 2013 Popular Post Share Posted January 28, 2013 The issue is with the return parent::renderForm(); at the end of your override. What's happening is that you're assigning variables in the AdminCustomerThreadsController::renderForm() and then calling the parent which re-assigns those same variables back to the 'un-overridden' values when you call parent::renderForm(). What you'll need to do is call the parent's (AdminCustomerThreadsControllerCore) parent (AdminController) directly: return AdminController::renderForm(); and that should work. 15 Link to comment Share on other sites More sharing options...
lawis Posted January 28, 2013 Share Posted January 28, 2013 (edited) Hello everyone, I've got the same issue : I'm trying to override AdminProductsController.php. My last step was just copying a function from the original file, and even doing just it a blank screen is the result. I'm going to watch your answer Terragg but i'm not on my production machine right now. Thanks all. Edited January 28, 2013 by lawis (see edit history) Link to comment Share on other sites More sharing options...
PotionsFactory Posted January 28, 2013 Share Posted January 28, 2013 Hello everyone, I've got the same issue : I'm trying to override AdminProductsController.php. My last step was just copying a function from the original file, and even doing just it a blank screen is the result. I'm going to watch your answer Terragg but i'm not on my production machine right now. Thanks all. Hey lawis, could you post your current override code here? Link to comment Share on other sites More sharing options...
lawis Posted January 28, 2013 Share Posted January 28, 2013 As I juste said I juste copied a function and did no changes at all. I'll send it tomorrow after tried Terragg's hint. Link to comment Share on other sites More sharing options...
Krystian Podemski Posted January 28, 2013 Share Posted January 28, 2013 The issue is with the return parent::renderForm(); at the end of your override. What's happening is that you're assigning variables in the AdminCustomerThreadsController::renderForm() and then calling the parent which re-assigns those same variables back to the 'un-overridden' values when you call parent::renderForm(). What you'll need to do is call the parent's (AdminCustomerThreadsControllerCore) parent (AdminController) directly: return AdminController::renderForm(); and that should work. Yep, that's works but I overwrite AdminController so that we can simply override an array of fields - all of it. Anyway, that's works. 1 Link to comment Share on other sites More sharing options...
Rhapsody Posted January 29, 2013 Author Share Posted January 29, 2013 (edited) @ Terragg - your answer in post #4 is the solution that works. Thanks very much! I've marked this thread solved. Edited January 29, 2013 by Rhapsody (see edit history) 1 Link to comment Share on other sites More sharing options...
lawis Posted January 29, 2013 Share Posted January 29, 2013 (edited) Unfortunately, it's not working for me, here is new thread : http://www.prestashop.com/forums/index.php?/topic/220374-overriding-adminproductscontroller/ Edited January 29, 2013 by lawis (see edit history) Link to comment Share on other sites More sharing options...
Artx Posted March 11, 2014 Share Posted March 11, 2014 Thank you for solutions for me it also appeared I had to delete cache->class_index.php for my admin controller override to work. I found it there: http://nemops.com/prestashop-1-5-virtual-products-combinations/#.Ux8R7oWC_4Y 1 Link to comment Share on other sites More sharing options...
enSysRanjit Posted July 3, 2014 Share Posted July 3, 2014 (edited) The issue is with thereturn parent::renderForm();at the end of your override. What's happening is that you're assigning variables in the AdminCustomerThreadsController::renderForm() and then calling the parent which re-assigns those same variables back to the 'un-overridden' values when you call parent::renderForm().What you'll need to do is call the parent's (AdminCustomerThreadsControllerCore) parent (AdminController) directly:return AdminController::renderForm();and that should work. It worked for me Thanks Terragg !!!!! Edited July 3, 2014 by enSysRanjit (see edit history) 1 Link to comment Share on other sites More sharing options...
bcsteeve Posted July 9, 2015 Share Posted July 9, 2015 Shouldn't this be documented?? There's a [mostly] well written document titled "overriding default behaviors" that doesn't mention this at all. It would be nice if the override system PRESUMED that "parent" refers to (for lack of a better term) the "grandparent" and pass it accordingly. If the more rare case is that the modifier intends to actually pass to the parent, then they can explicitly address it. The most common override case will be copy/paste from existing file and just make necessary changes, which shouldn't involve scouring the code for parent references. 2 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now