Page 1 of 3

Customer Custom Fields not available in admin & not saving

Posted: Sat Apr 07, 2018 12:44 am
by webs_bd
version 3.0.2.0.
I have successfully created a Custom Field in Customers. This shows in registration page but when filled out as a customer it does not save. Also the field is not available in admin area at all - does not show when looking at Customer in question.
Anyone come across this?

Re: Customer Custom Fields not available in admin & not saving

Posted: Sat Apr 07, 2018 1:02 am
by straightlight

Re: Customer Custom Fields not available in admin & not saving

Posted: Tue Apr 10, 2018 11:15 pm
by webs_bd
Sorry - to clarify, if I overwrote these 3 files it should clear the problem?
Would I need to create custom fields again or should this adjust and work for existing custom fields I already created?

Re: Customer Custom Fields not available in admin & not saving

Posted: Tue Apr 10, 2018 11:40 pm
by straightlight
Replacing these 3 files and clearing your OC cache from the OC admin should do it. There's no need to re-create the custom fields after replacing those files.

Re: Customer Custom Fields not available in admin & not saving

Posted: Wed Apr 11, 2018 12:34 am
by webs_bd
Thanks. No luck unfortunately. The field shows in customer front end but will not save entered value. Field does not show at all in admin.

Re: Customer Custom Fields not available in admin & not saving

Posted: Wed Apr 11, 2018 12:35 am
by straightlight
From which admin page are you filling the custom field exactly? Have you also cleared your OC cache by applying these steps: viewtopic.php?f=176&p=718325#p718325 ?

Re: Customer Custom Fields not available in admin & not saving

Posted: Wed Apr 11, 2018 12:48 am
by webs_bd
I have cleared caches yes.
I was trying to login as an existing customer then edit this field under 'edit account' to add a value for this new field

Re: Customer Custom Fields not available in admin & not saving

Posted: Wed Apr 11, 2018 12:55 am
by straightlight
Ensure that the registered customer account is within the same customer group where the custom field has been created from the OC admin. Both readings must match.

Re: Customer Custom Fields not available in admin & not saving

Posted: Wed Apr 11, 2018 1:30 am
by webs_bd
Yes they already match - I just have one customer group (Default).
The field shows fine in the customer account area - it is just the fact that the entered value does not save

Re: Customer Custom Fields not available in admin & not saving

Posted: Wed Apr 11, 2018 3:34 am
by straightlight
Let's test this. In catalog/model/account/customer.php file,

find:

Code: Select all

$this->db->query("UPDATE " . DB_PREFIX . "customer SET firstname = '" . $this->db->escape($data['firstname']) . "', lastname = '" . $this->db->escape($data['lastname']) . "', email = '" . $this->db->escape($data['email']) . "', telephone = '" . $this->db->escape($data['telephone']) . "', custom_field = '" . $this->db->escape(isset($data['custom_field']['account']) ? json_encode($data['custom_field']['account']) : '') . "' WHERE customer_id = '" . (int)$customer_id . "'");
add below:

Code: Select all

if (!empty($this->session->data['user_token'])) {
    exit;
}
Then, as still being logged in as a customer from the OC admin customer link, go back to the edit account page. Once saving the form, you should see a blank background screen. This is intended. Do you see any messages on that screen once the form submitted?

Re: Customer Custom Fields not available in admin & not saving

Posted: Wed Apr 11, 2018 7:18 pm
by webs_bd
Thank you for looking into this.
I do indeed get the blank screen. There is no message that shows however and nothing gets saved.

Can I just check something please - code below (have included a little above and below so you can see!). I just wanted to ensure I didn't have an extra bracket in there:

return $customer_id;
}

public function editCustomer($customer_id, $data) {
$this->db->query("UPDATE " . DB_PREFIX . "customer SET firstname = '" . $this->db->escape($data['firstname']) . "', lastname = '" . $this->db->escape($data['lastname']) . "', email = '" . $this->db->escape($data['email']) . "', telephone = '" . $this->db->escape($data['telephone']) . "', custom_field = '" . $this->db->escape(isset($data['custom_field']['account']) ? json_encode($data['custom_field']['account']) : '') . "' WHERE customer_id = '" . (int)$customer_id . "'");
if (!empty($this->session->data['user_token'])) {
exit;
}
}

public function editPassword($email, $password) {
$this->db->query("UPDATE " . DB_PREFIX . "customer SET salt = '" . $this->db->escape($salt = token(9)) . "', password = '" . $this->db->escape(sha1($salt . sha1($salt . sha1($password)))) . "', code = '' WHERE LOWER(email) = '" . $this->db->escape(utf8_strtolower($email)) . "'");
}

Re: Customer Custom Fields not available in admin & not saving

Posted: Wed Apr 11, 2018 7:34 pm
by straightlight
The added code location is valid. However, ensure the display errors on your domain are enabled. The blank screen you are getting may also mean you have a hidden error message. Check in your admin - > systems - > maintenance - > error logs page for the latest error message regarding the account/edit page.

Re: Customer Custom Fields not available in admin & not saving

Posted: Wed Apr 11, 2018 8:58 pm
by webs_bd
Thanks - no errors showing I'm afraid.
The regex doesn't have anything to do with it does it? Nothing is specified here but wondered if it should maybe?

Re: Customer Custom Fields not available in admin & not saving

Posted: Wed Apr 11, 2018 9:23 pm
by straightlight
If you want to try the validate() method results, remove the above troubleshoot lines . Then, in your catalog/controller/account/edit.php file,

find:

Code: Select all

$this->session->data['success'] = $this->language->get('text_success');
add above:

Code: Select all

if (!empty($this->session->data['user_token'])) {
    exit;
}
Then, re-apply the same steps by re-logging as an admin and login as a customer from the admin. Then, go back to the edit form and re-save the form. The REGEX validation would still provide an error message if this was the related issue since, by default, the REGEX are already checked in the account edit page as well when the form is being saved.

Re: Customer Custom Fields not available in admin & not saving

Posted: Wed Apr 11, 2018 10:22 pm
by webs_bd
Thanks again.
Unfortunately still no luck.
I tried creating a new customer as well with this field filled in but it just does not register.
I checked in phpmyadmin too and nothing showing (custom field is there but no values).

Re: Customer Custom Fields not available in admin & not saving

Posted: Thu Apr 12, 2018 12:13 am
by straightlight
Ensure your database credentials are all check marked from your host console.

Re: Customer Custom Fields not available in admin & not saving

Posted: Thu Apr 12, 2018 12:49 am
by webs_bd
Sorry! Not sure what you mean......

Re: Customer Custom Fields not available in admin & not saving

Posted: Thu Apr 12, 2018 12:55 am
by straightlight
Then, the issue may lie there. Follow this Youtube video on how to database privileges: https://www.youtube.com/watch?v=9QhID5g2S2A

Re: Customer Custom Fields not available in admin & not saving

Posted: Thu Apr 12, 2018 3:32 am
by webs_bd
Right sorry - no all database privileges are fine and as they should be.

Re: Customer Custom Fields not available in admin & not saving

Posted: Thu Apr 12, 2018 3:37 am
by straightlight
In your PHPMyAdmin, what is your COLLATE settings and also your database table types?