Page 1 of 1

bug in "Edit Order" when using required custom fields

Posted: Tue Aug 29, 2017 4:02 am
by ossandust
OpenCart v.3.0.2.0
I added a few required custom fields to the customer details page. When I try to edit an existing order I'm stuck on the first tab, with a "field required!" error message appearing next to each required custom field, although all required fields are filled in. (screenshot attached)

Re: bug in "Edit Order" when using required custom fields

Posted: Wed Nov 15, 2017 6:00 am
by straightlight
Updated steps:

- https://github.com/opencart/opencart/bl ... stomer.php
- https://github.com/opencart/opencart/bl ... ayment.php

Clear your OC cache afterwards from the OC admin. This should resolved the issue.

Re: bug in "Edit Order" when using required custom fields

Posted: Wed Mar 14, 2018 4:18 am
by stashdesign
I also have the exact same problem. Someone please help me solve it.. Try to fix it for the last 8 hours!

Re: bug in "Edit Order" when using required custom fields

Posted: Wed Mar 14, 2018 6:23 pm
by straightlight
You have the exact same problem but without providing the OC version. Of course. There was a recent topic solution on my behalf but can no longer seem to find it. I have now updated the steps above.

Re: bug in "Edit Order" when using required custom fields

Posted: Wed Mar 14, 2018 7:49 pm
by stashdesign
That solved my problem! Many thanks!

Also need this file for fully working:
https://github.com/opencart/opencart/bl ... ipping.php

Btw i am on version 3.0.2.0 OCMOD.

Re: bug in "Edit Order" when using required custom fields

Posted: Wed Mar 14, 2018 9:26 pm
by straightlight
Also need this file for fully working:
https://github.com/opencart/opencart/bl ... ipping.php
Thanks for the info.

Re: bug in "Edit Order" when using required custom fields

Posted: Thu Mar 15, 2018 12:03 am
by straightlight
Found the actual topic: viewtopic.php?f=201&t=202036#p713641

Re: bug in "Edit Order" when using required custom fields

Posted: Tue Oct 02, 2018 4:58 pm
by marco.rocci92
Hi,
there is error when using custom errors with Regex like
/^[a-zA-Z]{6}[0-9]{2}[abcdehlmprstABCDEHLMPRST]{1}[0-9]{2}([a-zA-Z]{1}[0-9]{3})[a-zA-Z]{1}$/

the problem is on ^ character

Re: bug in "Edit Order" when using required custom fields

Posted: Wed Oct 03, 2018 4:07 am
by straightlight
marco.rocci92 wrote:
Tue Oct 02, 2018 4:58 pm
Hi,
there is error when using custom errors with Regex like
/^[a-zA-Z]{6}[0-9]{2}[abcdehlmprstABCDEHLMPRST]{1}[0-9]{2}([a-zA-Z]{1}[0-9]{3})[a-zA-Z]{1}$/

the problem is on ^ character
More information needed. Which route and location are you describing this issue from?

Re: bug in "Edit Order" when using required custom fields

Posted: Wed Oct 03, 2018 4:22 pm
by marco.rocci92
I retried and now it work, but there is a problem on the length of the regex like:

Code: Select all

/^(?:(?:[B-DF-HJ-NP-TV-Z]|[AEIOU])[AEIOU][AEIOUX]|[B-DF-HJ-NP-TV-Z]{2}[A-Z]){2}[\dLMNP-V]{2}(?:[A-EHLMPR-T](?:[04LQ][1-9MNP-V]|[1256LMRS][\dLMNP-V])|[DHPS][37PT][0L]|[ACELMRT][37PT][01LM])(?:[A-MZ][1-9MNP-V][\dLMNP-V]{2}|[A-M][0L](?:[1-9MNP-V][\dLMNP-V]|[0L][1-9MNP-V]))[A-Z]$/i
opencart trunc the regex when save

Re: bug in "Edit Order" when using required custom fields

Posted: Wed Oct 03, 2018 5:57 pm
by straightlight
Not a bug. Posted in wrong section.

Re: bug in "Edit Order" when using required custom fields

Posted: Sat Oct 06, 2018 1:35 am
by marco.rocci92
i edited the file, now it is like https://github.com/opencart/opencart/bl ... stomer.php
but now i have problem:
the regex of custom field is /^[A-Z]{6}\d{2}[A-Z]\d{2}[A-Z]\d{3}[A-Z]$/i
when i press continue, i have error on filter_var

Re: bug in "Edit Order" when using required custom fields

Posted: Sat Oct 06, 2018 7:58 pm
by straightlight
Already fixed on Github. In catalog/controller/api/customer.php file,

find:

Code: Select all

} elseif (($custom_field['type'] == 'text') && !empty($custom_field['validation']) && !filter_var($this->request->post['custom_field'][$custom_field['custom_field_id']], FILTER_VALIDATE_REGEXP, array('options' => array('regexp' => $custom_field['validation'])))) {
replace with:

Code: Select all

} elseif (($custom_field['type'] == 'text') && !empty($custom_field['validation']) && filter_var($this->request->post['custom_field'][$custom_field['custom_field_id']], FILTER_VALIDATE_REGEXP, array('options' => array('regexp' => '/' . html_entity_decode($custom_field['validation'], ENT_QUOTES, 'UTF-8') . '/')))) {
This should resolved the issue.

Re: bug in "Edit Order" when using required custom fields

Posted: Sun Oct 07, 2018 3:47 am
by marco.rocci92
Thanks for the answer.
My catalog/controller/api/customer.php
is like your:

Code: Select all

<?php
class ControllerApiCustomer extends Controller {
	public function index() {
		$this->load->language('api/customer');
		// Delete past customer in case there is an error
		unset($this->session->data['customer']);
		$json = array();
		if (!isset($this->session->data['api_id'])) {
			$json['error']['warning'] = $this->language->get('error_permission');
		} else {
			// Add keys for missing post vars
			$keys = array(
				'customer_id',
				'customer_group_id',
				'firstname',
				'lastname',
				'email',
				'telephone',
			);
			foreach ($keys as $key) {
				if (!isset($this->request->post[$key])) {
					$this->request->post[$key] = '';
				}
			}
			// Customer
			if ($this->request->post['customer_id']) {
				$this->load->model('account/customer');
				$customer_info = $this->model_account_customer->getCustomer($this->request->post['customer_id']);
				if (!$customer_info || !$this->customer->login($customer_info['email'], '', true)) {
					$json['error']['warning'] = $this->language->get('error_customer');
				}
			}
			if ((utf8_strlen(trim($this->request->post['firstname'])) < 1) || (utf8_strlen(trim($this->request->post['firstname'])) > 32)) {
				$json['error']['firstname'] = $this->language->get('error_firstname');
			}
			if ((utf8_strlen(trim($this->request->post['lastname'])) < 1) || (utf8_strlen(trim($this->request->post['lastname'])) > 32)) {
				$json['error']['lastname'] = $this->language->get('error_lastname');
			}
			if ((utf8_strlen($this->request->post['email']) > 96) || (!filter_var($this->request->post['email'], FILTER_VALIDATE_EMAIL))) {
				$json['error']['email'] = $this->language->get('error_email');
			}
			if ((utf8_strlen($this->request->post['telephone']) < 3) || (utf8_strlen($this->request->post['telephone']) > 32)) {
				$json['error']['telephone'] = $this->language->get('error_telephone');
			}
			// Customer Group
			if (is_array($this->config->get('config_customer_group_display')) && in_array($this->request->post['customer_group_id'], $this->config->get('config_customer_group_display'))) {
				$customer_group_id = $this->request->post['customer_group_id'];
			} else {
				$customer_group_id = $this->config->get('config_customer_group_id');
			}
			// Custom field validation
			$this->load->model('account/custom_field');
			$custom_fields = $this->model_account_custom_field->getCustomFields($customer_group_id);
			foreach ($custom_fields as $custom_field) {
				if ($custom_field['location'] == 'account') {
					if ($custom_field['required'] && empty($this->request->post['custom_field'][$custom_field['custom_field_id']])) {
						$json['error']['custom_field' . $custom_field['custom_field_id']] = sprintf($this->language->get('error_custom_field'), $custom_field['name']);
					} elseif (($custom_field['type'] == 'text') && !empty($custom_field['validation']) && filter_var($this->request->post['custom_field'][$custom_field['custom_field_id']], FILTER_VALIDATE_REGEXP, array('options' => array('regexp' => '/' . html_entity_decode($custom_field['validation'], ENT_QUOTES, 'UTF-8') . '/')))) {
						$json['error']['custom_field' . $custom_field['custom_field_id']] = sprintf($this->language->get('error_custom_field'), $custom_field['name']);
					}
				}
			}
			if (!$json) {
				$this->session->data['customer'] = array(
					'customer_id'       => $this->request->post['customer_id'],
					'customer_group_id' => $customer_group_id,
					'firstname'         => $this->request->post['firstname'],
					'lastname'          => $this->request->post['lastname'],
					'email'             => $this->request->post['email'],
					'telephone'         => $this->request->post['telephone'],
					'custom_field'      => isset($this->request->post['custom_field']) ? $this->request->post['custom_field'] : array()
				);
				$json['success'] = $this->language->get('text_success');
			}
		}
		$this->response->addHeader('Content-Type: application/json');
		$this->response->setOutput(json_encode($json));
	}
}
but i have the same issue

Re: bug in "Edit Order" when using required custom fields

Posted: Sun Oct 07, 2018 5:02 am
by marco.rocci92
You gave me this code
replace with:

Code: Select all

} elseif (($custom_field['type'] == 'text') && !empty($custom_field['validation']) && filter_var($this->request->post['custom_field'][$custom_field['custom_field_id']], FILTER_VALIDATE_REGEXP, array('options' => array('regexp' => '/' . html_entity_decode($custom_field['validation'], ENT_QUOTES, 'UTF-8') . '/')))) {

but
i read code on the register.php where there is a similar filter_var (where maybe it should be change integrating the html_entity_decode)
then maybe the code should be:

Code: Select all

} elseif (($custom_field['type'] == 'text') && !empty($custom_field['validation']) && !filter_var($this->request->post['custom_field'][$custom_field['custom_field_id']], FILTER_VALIDATE_REGEXP, array('options' => array('regexp' =>  html_entity_decode($custom_field['validation'], ENT_QUOTES, 'UTF-8') )))) {
I tested and it work
what do you think about?
I removed the concatenation of html_entity_decode because the string have the '/' . and i put the negation in filter_var

Re: bug in "Edit Order" when using required custom fields

Posted: Sun Oct 07, 2018 10:19 am
by straightlight
In catalog/controller/account/register.php file,

find:

Code: Select all

} elseif (($custom_field['type'] == 'text') && !empty($custom_field['validation']) && !filter_var($this->request->post['custom_field'][$custom_field['location']][$custom_field['custom_field_id']], FILTER_VALIDATE_REGEXP, array('options' => array('regexp' => $custom_field['validation'])))) {
replace with:

Code: Select all

} elseif (($custom_field['type'] == 'text') && !empty($custom_field['validation']) && filter_var($this->request->post['custom_field'][$custom_field['location']][$custom_field['custom_field_id']], FILTER_VALIDATE_REGEXP, array('options' => array('regexp' => '/' . html_entity_decode($custom_field['validation'], ENT_QUOTES, 'UTF-8') . '/')))) {

Re: bug in "Edit Order" when using required custom fields

Posted: Mon Nov 12, 2018 10:14 am
by qualitas
I have a specific order blocked on step 4 "shipping details" without having done any modification yet.
No error message and no error log.

I want to add shipping fees on step 5 but cannot access it. (product is too big for postal service and didn't calculate it).

First I taught it's a Regex problem because of a French character but I change it and it's still not going to tab 5.

I just updated those 4 files:
https://github.com/opencart/opencart/bl ... stomer.php
https://github.com/opencart/opencart/bl ... ayment.php
https://github.com/opencart/opencart/bl ... ipping.php
https://github.com/opencart/opencart/bl ... gister.php

And it still not work.

Here the order details (see attachment picture):