Roshan Bhavsar Posted September 20, 2022 Share Posted September 20, 2022 I want to add 2 new text fields below pasword field into the backoffice of the prestashop 1.7.8.7 Please guide me to add the text fields in admin -> customers -> select Customer -> add 2 new fields in customer edit form. also the data should be saed into the database. Please look for the attached image. Link to comment Share on other sites More sharing options...
ps8modules Posted September 20, 2022 Share Posted September 20, 2022 Hi. https://www.google.com/amp/s/webkul.com/blog/adding-new-field-in-prestashop-1-7-admin-symfony-controller/amp/ Link to comment Share on other sites More sharing options...
Roshan Bhavsar Posted September 20, 2022 Author Share Posted September 20, 2022 (edited) Hello 4you.software Can you please explore more. I'm using version 1.7.8.7 It will be better if you could explain step by step. Thanks. Edited September 20, 2022 by Roshan Bhavsar (see edit history) Link to comment Share on other sites More sharing options...
ps8modules Posted September 20, 2022 Share Posted September 20, 2022 I will ask. Have you already programmed a module? Link to comment Share on other sites More sharing options...
Roshan Bhavsar Posted September 21, 2022 Author Share Posted September 21, 2022 14 hours ago, 4you.software said: I will ask. Have you already programmed a module? No Link to comment Share on other sites More sharing options...
ps8modules Posted September 21, 2022 Share Posted September 21, 2022 Thank you for answer. This section of the forum is intended primarily for developers. If you need a customized module, you can visit the JOB section and a programmer will create the module for you. https://www.prestashop.com/forums/?forumId=235 Estimate The module development estimate is from 30 minutes to a maximum of one hour. As a beginner programmer, you have the opportunity to study the documentation for developers, including a sample module. https://devdocs.prestashop-project.org/1.7/modules/ Sorry, but no one here is going to write a detailed step by step procedure when everything is already written and documented. Link to comment Share on other sites More sharing options...
Roshan Bhavsar Posted September 21, 2022 Author Share Posted September 21, 2022 Thanks. Now I have added a new field into the form, also added a new field into the ps_customer, but now I want to store that value into the database. So, please guide me to store that value into the database. Which files I need to modify. Thanks. Link to comment Share on other sites More sharing options...
ps8modules Posted September 21, 2022 Share Posted September 21, 2022 (edited) Hi. Ok, you need to put your code from the module here. I don't know the name of the field you created, I don't know the name of the column in the database table, etc. Then I'll give you the working code. There are also hooks to load and save data from the form. hookActionAfterUpdateCustomerFormHandler hookActionAfterCreateCustomerFormHandler and custom function Edited September 21, 2022 by 4you.software (see edit history) Link to comment Share on other sites More sharing options...
ps8modules Posted September 21, 2022 Share Posted September 21, 2022 sample: public function hookActionCustomerFormBuilderModifier(array $params) { /* your exists code */ $customerId = $params['id']; $params['data']['my_field_name_1'] = $this->getCustomerCustomFieldsData($customerId)[0]; $params['data']['my_field_name_2'] = $this->getCustomerCustomFieldsData($customerId)[1]; $formBuilder->setData($params['data']); } public function hookActionAfterUpdateCustomerFormHandler(array $params) { $this->updateCustomerCustomFields($params); } public function hookActionAfterCreateCustomerFormHandler(array $params) { $this->getCustomerCustomFieldsData($params); } private function getCustomerCustomFieldsData(array $params) { $customerId = $params['id']; if (!$customerId){return;} $customerFormData = $params['form_data']; $getSavedData = Db::getInstance()->getRow('SELECT my_field1, my_field2 FROM '._DB_PREFIX_.'customer WHERE id_customer = '.$customerId); $myTextField1 = $getSavedData['my_field1']; $myTextField2 = $getSavedData['my_field2']; return array($myTextField1, $myTextField2); } private function updateCustomerCustomFields(array $params) { $customerId = $params['id']; if (!$customerId){return;} $customerFormData = $params['form_data']; $myTextField1 = $customerFormData['my_field_name_1']; $myTextField2 = $customerFormData['my_field_name_2']; Db::getInstance()->execute("UPDATE "._DB_PREFIX_."customer SET my_field1 = '".$myTextField1."', my_field2 = '".$myTextField2."' WHERE id_customer = ".$customerId); } Link to comment Share on other sites More sharing options...
Roshan Bhavsar Posted September 23, 2022 Author Share Posted September 23, 2022 On 9/21/2022 at 9:03 PM, 4you.software said: sample: public function hookActionCustomerFormBuilderModifier(array $params) { /* your exists code */ $customerId = $params['id']; $params['data']['my_field_name_1'] = $this->getCustomerCustomFieldsData($customerId)[0]; $params['data']['my_field_name_2'] = $this->getCustomerCustomFieldsData($customerId)[1]; $formBuilder->setData($params['data']); } public function hookActionAfterUpdateCustomerFormHandler(array $params) { $this->updateCustomerCustomFields($params); } public function hookActionAfterCreateCustomerFormHandler(array $params) { $this->getCustomerCustomFieldsData($params); } private function getCustomerCustomFieldsData(array $params) { $customerId = $params['id']; if (!$customerId){return;} $customerFormData = $params['form_data']; $getSavedData = Db::getInstance()->getRow('SELECT my_field1, my_field2 FROM '._DB_PREFIX_.'customer WHERE id_customer = '.$customerId); $myTextField1 = $getSavedData['my_field1']; $myTextField2 = $getSavedData['my_field2']; return array($myTextField1, $myTextField2); } private function updateCustomerCustomFields(array $params) { $customerId = $params['id']; if (!$customerId){return;} $customerFormData = $params['form_data']; $myTextField1 = $customerFormData['my_field_name_1']; $myTextField2 = $customerFormData['my_field_name_2']; Db::getInstance()->execute("UPDATE "._DB_PREFIX_."customer SET my_field1 = '".$myTextField1."', my_field2 = '".$myTextField2."' WHERE id_customer = ".$customerId); } Thanks a Lot. 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