Page 1 of 3

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):

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

Posted: Wed Sep 25, 2019 3:09 pm
by ihateusernames
Hi,

I am experiencing the same issue. I've copied & pasted the two php files as suggested by Straightlight but I now get an error pop up instead. This reads....

Code: Select all

SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data
OK
<b>Warning</b>: filter_var(): Unknown modifier '[' in <b>/home/ihateusernames/shop.indonesianwholesaler.com/catalog/controller/api/customer.php</b> on line <b>58</b><b>Warning</b>: filter_var(): Unknown modifier '[' in <b>/home/ihateusernames/shop.indonesianwholesaler.com/catalog/controller/api/customer.php</b> on line <b>58</b><b>Warning</b>: filter_var(): Unknown modifier '[' in <b>/home/ihateusernames/shop.indonesianwholesaler.com/catalog/controller/api/customer.php</b> on line <b>58</b>{"error":{"custom_field4":"Country required!"}}
Any solution welcomed. Thanks.

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

Posted: Sun Oct 06, 2019 4:50 pm
by ihateusernames
Hi,

I've now disabled the custom fields but I still get this Syntax error...:

Code: Select all

SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data
OK
<br />
<b>Fatal error</b>:  Uncaught ArgumentCountError: Too few arguments to function ModelExtensionTotalSubTotal::getTotal(), 0 passed in /home/ihateusernames/ocartdataclone/storage/modification/system/engine/loader.php on line 248 and exactly 1 expected in /home/ihateusernames/shop.indonesianwholesaler.com/catalog/model/extension/total/sub_total.php:3
Stack trace:
#0 /home/ihateusernames/ocartdataclone/storage/modification/system/engine/loader.php(248): ModelExtensionTotalSubTotal-&gt;getTotal()
#1 /home/ihateusernames/shop.indonesianwholesaler.com/catalog/controller/api/payment.php(146): Loader-&gt;{closure}(Array, Array, 0)
#2 /home/ihateusernames/ocartdataclone/storage/modification/system/engine/action.php(78): ControllerApiPayment-&gt;methods()
#3 /home/ihateusernames/shop.indonesianwholesaler.com/catalog/controller/startup/router.php(25): Action-&gt;execute(Object(Registry))
#4 /home/ihateusernames/ocartdataclone/storage/modification/system/engine/action.php(78): ControllerStartupRouter-&gt;index()
#5 /home/ihateusernames/shop.indonesianwholes in <b>/home/ihateusernames/shop.indonesianwholesaler.com/catalog/model/extension/total/sub_total.php</b> on line <b>3</b><br />
If anyone has a fix for this issue it would be greatly appreciated, thanks.

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

Posted: Sun Nov 17, 2019 5:58 pm
by Zest 365
Hi All,

For those who are having the same issue but on OC Version 3.0.3.2 please read this.
I have fixed this issue by using "Straightlight's" fix to "catalog/controller/api/customer.php" file.

A Massive Thank You to "Straightlight".

The path to this file is as follows;
https://github.com/opencart/opencart/bl ... stomer.php

Please see the attached file for screenshot of my Order Edit and confirmation email to customer (showing custom field) following updating the above file.