Post by chongshengdz » Sun Jun 19, 2022 8:08 pm

how to combine duplicate custom_field name with value opencart version 3038?
before combination:
Account Custom Fields
color yellow
color green
color red
image 3ba9557e23ecb68b0152683e2623dd72907bdfff
image MPX2102AP.jpg
size big
size small
after combination, the chart will show like:
Account Custom Fields
color: yellow,green,red
image: 3ba9557e23ecb68b0152683e2623dd72907bdfff, MPX2102AP.jpg
size: big, small
how to do it?

Attachments

combine.jpg

how to combine duplicate custom_field name with value - combine.jpg (41.45 KiB) Viewed 944 times


https://www.ectransistors.com/
https://www.transistormosfet.com/


Active Member

Posts

Joined
Sat Apr 12, 2014 10:18 pm


Post by paulfeakins » Mon Jun 20, 2022 8:07 pm

If you can't find an extension, you could pay a developer such as ourselves or post a job in the Commercial Support Forum.

UK OpenCart Hosting | OpenCart Audits | OpenCart Support - please email info@antropy.co.uk


User avatar
Legendary Member

Posts

Joined
Mon Aug 22, 2011 11:01 pm
Location - London Gatwick, United Kingdom

Post by straightlight » Tue Jun 21, 2022 9:21 am

This request seem to have been in demand for quite sometime now. It's been routed to the opencart-3 as well. Let's give this a try without an event, this time, since it may also be a core experience.

In admin/controller/customer/custom_field.php file,

find:

Code: Select all

$data['custom_fields'] = array();
		
		$filter_data = array(
			'sort'  => $sort,
			'order' => $order,
			'start' => ($page - 1) * $this->config->get('config_limit_admin'),
			'limit' => $this->config->get('config_limit_admin')
		);

		$custom_field_total = $this->model_customer_custom_field->getTotalCustomFields();

		$results = $this->model_customer_custom_field->getCustomFields($filter_data);

		foreach ($results as $result) {
			$type = '';

			switch ($result['type']) {
				case 'select':
					$type = $this->language->get('text_select');
					break;
				case 'radio':
					$type = $this->language->get('text_radio');
					break;
				case 'checkbox':
					$type = $this->language->get('text_checkbox');
					break;
				case 'input':
					$type = $this->language->get('text_input');
					break;
				case 'text':
					$type = $this->language->get('text_text');
					break;
				case 'textarea':
					$type = $this->language->get('text_textarea');
					break;
				case 'file':
					$type = $this->language->get('text_file');
					break;
				case 'date':
					$type = $this->language->get('text_date');
					break;
				case 'datetime':
					$type = $this->language->get('text_datetime');
					break;
				case 'time':
					$type = $this->language->get('text_time');
					break;
			}

			$data['custom_fields'][] = array(
				'custom_field_id' => $result['custom_field_id'],
				'name'            => $result['name'],
				'location'        => $this->language->get('text_' . $result['location']),
				'type'            => $type,
				'status'          => $result['status'],
				'sort_order'      => $result['sort_order'],
				'edit'            => $this->url->link('customer/custom_field/edit', 'user_token=' . $this->session->data['user_token'] . '&custom_field_id=' . $result['custom_field_id'] . $url, true)
			);
		}
replace with:

Code: Select all

$data['custom_fields'] = array();
		
		$custom_field_values = array();

		$filter_data = array(
			'sort'  => $sort,
			'order' => $order,
			'start' => ($page - 1) * $this->config->get('config_limit_admin'),
			'limit' => $this->config->get('config_limit_admin')
		);

		$custom_field_total = $this->model_customer_custom_field->getTotalCustomFields();

		$results = $this->model_customer_custom_field->getCustomFields($filter_data);

		foreach ($results as $result) {
			$type = '';

			switch ($result['type']) {
				case 'select':
					$type = $this->language->get('text_select');
					break;
				case 'radio':
					$type = $this->language->get('text_radio');
					break;
				case 'checkbox':
					$type = $this->language->get('text_checkbox');
					break;
				case 'input':
					$type = $this->language->get('text_input');
					break;
				case 'text':
					$type = $this->language->get('text_text');
					break;
				case 'textarea':
					$type = $this->language->get('text_textarea');
					break;
				case 'file':
					$type = $this->language->get('text_file');
					break;
				case 'date':
					$type = $this->language->get('text_date');
					break;
				case 'datetime':
					$type = $this->language->get('text_datetime');
					break;
				case 'time':
					$type = $this->language->get('text_time');
					break;
			}

			$data['custom_fields'][] = array(
				'custom_field_id' => $result['custom_field_id'],
				'name'            => $result['name'],
				'location'        => $this->language->get('text_' . $result['location']),
				'type'            => $type,
				'status'          => $result['status'],
				'sort_order'      => $result['sort_order'],
				'edit'            => $this->url->link('customer/custom_field/edit', 'user_token=' . $this->session->data['user_token'] . '&custom_field_id=' . $result['custom_field_id'] . $url, true)
			);
			
			$name = $result['name'];
			
			$value = $result['value'];
			
			$custom_field_values[$name][] = $name . '|' . $value;
		}
		
		$tmp_custom_fields = array();
		
		foreach ($custom_field_values as $key => $values) {
			if (!empty($values) && is_array($values)) {
				foreach ($values as $value) {
					$value_exploded = explode('|', trim($value));
				
					$tmp_custom_fields[$value_exploded[0]][] = $value_exploded[1];
				}
			}
		}		
			
		$data['custom_field_values'] = array();
			
		foreach ($tmp_custom_fields as $key => $values) {
			$commas = implode(', ', $values);
				
			$data['custom_field_values'][$key][] = $commas;
		}
Then, in admin/view/template/customer/custom_field.twig file, find:

Code: Select all

<td class="text-left">{{ custom_field.name }}</td>
replace with:

Code: Select all

<td class="text-left">{% for key,values in custom_field_values %}
				  {% if key == custom_field.name %}				  
				  {{ custom_field.name }}:&nbsp;
				  {% for value in values %}				  
				  {{ value }}
				  {% endfor %}
				  {% endif %}
				  {% endfor %}
				  </td>
See if that solves the issue.
Last edited by straightlight on Tue Jun 21, 2022 6:24 pm, edited 2 times in total.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by chongshengdz » Tue Jun 21, 2022 12:02 pm

straightlight wrote:
Tue Jun 21, 2022 9:21 am
This request seem to have been in demand for quite sometime now. It's been routed to the opencart-3 as well. Let's give this a try without an event, this time, since it may also be a core experience.

In admin/controller/customer/custom_field.php file,

find:

Code: Select all

$data['custom_fields'] = array();
		
		$filter_data = array(
			'sort'  => $sort,
			'order' => $order,
			'start' => ($page - 1) * $this->config->get('config_limit_admin'),
			'limit' => $this->config->get('config_limit_admin')
		);

		$custom_field_total = $this->model_customer_custom_field->getTotalCustomFields();

		$results = $this->model_customer_custom_field->getCustomFields($filter_data);

		foreach ($results as $result) {
			$type = '';

			switch ($result['type']) {
				case 'select':
					$type = $this->language->get('text_select');
					break;
				case 'radio':
					$type = $this->language->get('text_radio');
					break;
				case 'checkbox':
					$type = $this->language->get('text_checkbox');
					break;
				case 'input':
					$type = $this->language->get('text_input');
					break;
				case 'text':
					$type = $this->language->get('text_text');
					break;
				case 'textarea':
					$type = $this->language->get('text_textarea');
					break;
				case 'file':
					$type = $this->language->get('text_file');
					break;
				case 'date':
					$type = $this->language->get('text_date');
					break;
				case 'datetime':
					$type = $this->language->get('text_datetime');
					break;
				case 'time':
					$type = $this->language->get('text_time');
					break;
			}

			$data['custom_fields'][] = array(
				'custom_field_id' => $result['custom_field_id'],
				'name'            => $result['name'],
				'location'        => $this->language->get('text_' . $result['location']),
				'type'            => $type,
				'status'          => $result['status'],
				'sort_order'      => $result['sort_order'],
				'edit'            => $this->url->link('customer/custom_field/edit', 'user_token=' . $this->session->data['user_token'] . '&custom_field_id=' . $result['custom_field_id'] . $url, true)
			);
		}
replace with:

Code: Select all

$data['custom_fields'] = array();
		
		$custom_field_values = array();

		$filter_data = array(
			'sort'  => $sort,
			'order' => $order,
			'start' => ($page - 1) * $this->config->get('config_limit_admin'),
			'limit' => $this->config->get('config_limit_admin')
		);

		$custom_field_total = $this->model_customer_custom_field->getTotalCustomFields();

		$results = $this->model_customer_custom_field->getCustomFields($filter_data);

		foreach ($results as $result) {
			$type = '';

			switch ($result['type']) {
				case 'select':
					$type = $this->language->get('text_select');
					break;
				case 'radio':
					$type = $this->language->get('text_radio');
					break;
				case 'checkbox':
					$type = $this->language->get('text_checkbox');
					break;
				case 'input':
					$type = $this->language->get('text_input');
					break;
				case 'text':
					$type = $this->language->get('text_text');
					break;
				case 'textarea':
					$type = $this->language->get('text_textarea');
					break;
				case 'file':
					$type = $this->language->get('text_file');
					break;
				case 'date':
					$type = $this->language->get('text_date');
					break;
				case 'datetime':
					$type = $this->language->get('text_datetime');
					break;
				case 'time':
					$type = $this->language->get('text_time');
					break;
			}

			$data['custom_fields'][] = array(
				'custom_field_id' => $result['custom_field_id'],
				'name'            => $result['name'],
				'location'        => $this->language->get('text_' . $result['location']),
				'type'            => $type,
				'status'          => $result['status'],
				'sort_order'      => $result['sort_order'],
				'edit'            => $this->url->link('customer/custom_field/edit', 'user_token=' . $this->session->data['user_token'] . '&custom_field_id=' . $result['custom_field_id'] . $url, true)
			);
			
			$name = $result['name'];
			
			$value = $result['value'];
			
			$custom_field_values[$name][] = $name . '|' . $value;
		}
		
		$tmp_custom_fields = array();
		
		foreach ($custom_field_values as $key => $values) {
			$values_exploded = explode('|', trim($values));
				
			$tmp_custom_fields[$values_exploded[0]][] = $values_exploded[1];
		}		
			
		$data['custom_field_values'] = array();
			
		foreach ($tmp_custom_fields as $key => $values) {
			$commas = implode(', ', $values);
				
			$data['custom_field_values'][$key][] = $commas;
		}
Then, in admin/view/template/customer/custom_field.twig file, find:

Code: Select all

<td class="text-left">{{ custom_field.name }}</td>
replace with:

Code: Select all

<td class="text-left">{% for key,values in custom_field_values %}
				  {% if key == custom_field.name %}				  
				  {% for value in values %}				  
				  {{ custom_field.name }}: {{ value }}
				  {% endfor %}
				  {% endif %}
				  {% endfor %}
				  </td>
See if that solves the issue.
not working.
it says:
Warning: trim() expects parameter 1 to be string, array given in /admin/controller/customer/custom_field.php on line 232
Notice: Undefined offset: 1 in /admin/controller/customer/custom_field.php on line 234

https://www.ectransistors.com/
https://www.transistormosfet.com/


Active Member

Posts

Joined
Sat Apr 12, 2014 10:18 pm


Post by chongshengdz » Tue Jun 21, 2022 1:44 pm

please see the attached photo:
before combination:
Image
after combination:
Image
the modification should be as the after-combination.

https://www.ectransistors.com/
https://www.transistormosfet.com/


Active Member

Posts

Joined
Sat Apr 12, 2014 10:18 pm


Post by straightlight » Tue Jun 21, 2022 6:25 pm

You don't need to re-post the same screenshots for PHP errors. The code has been edited on the above now. Please try again.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by chongshengdz » Tue Jun 21, 2022 8:16 pm

straightlight wrote:
Tue Jun 21, 2022 6:25 pm
You don't need to re-post the same screenshots for PHP errors. The code has been edited on the above now. Please try again.
this time, no php errors, but the value is blank, don't show up.
please help again.

Attachments

value-is-blank.jpg

value is blank - value-is-blank.jpg (6.4 KiB) Viewed 873 times


https://www.ectransistors.com/
https://www.transistormosfet.com/


Active Member

Posts

Joined
Sat Apr 12, 2014 10:18 pm


Post by chongshengdz » Wed Jun 22, 2022 3:25 am

straightlight wrote:
Tue Jun 21, 2022 6:25 pm
You don't need to re-post the same screenshots for PHP errors. The code has been edited on the above now. Please try again.
please help modify admin/controller/sale/order.php and /admin/view/template/sale/order_info.twig under account_custom_field.
not admin/controller/customer/custom_field.php and admin/view/template/customer/custom_field_list.twig

https://www.ectransistors.com/
https://www.transistormosfet.com/


Active Member

Posts

Joined
Sat Apr 12, 2014 10:18 pm


Post by straightlight » Wed Jun 22, 2022 6:28 am

chongshengdz wrote:
Wed Jun 22, 2022 3:25 am
straightlight wrote:
Tue Jun 21, 2022 6:25 pm
You don't need to re-post the same screenshots for PHP errors. The code has been edited on the above now. Please try again.
please help modify admin/controller/sale/order.php and /admin/view/template/sale/order_info.twig under account_custom_field.
not admin/controller/customer/custom_field.php and admin/view/template/customer/custom_field_list.twig
What you are acquiring may require extensive coding. Therefore, I would suggest to create a new service request in the Commercial Support section of the forum to get this done as a custom job.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by chongshengdz » Wed Jun 22, 2022 6:45 am

straightlight wrote:
Wed Jun 22, 2022 6:28 am
chongshengdz wrote:
Wed Jun 22, 2022 3:25 am
straightlight wrote:
Tue Jun 21, 2022 6:25 pm
You don't need to re-post the same screenshots for PHP errors. The code has been edited on the above now. Please try again.
please help modify admin/controller/sale/order.php and /admin/view/template/sale/order_info.twig under account_custom_field.
not admin/controller/customer/custom_field.php and admin/view/template/customer/custom_field_list.twig
What you are acquiring may require extensive coding. Therefore, I would suggest to create a new service request in the Commercial Support section of the forum to get this done as a custom job.
at thebeginning, you are doing wrong, please help me again

https://www.ectransistors.com/
https://www.transistormosfet.com/


Active Member

Posts

Joined
Sat Apr 12, 2014 10:18 pm


Post by straightlight » Wed Jun 22, 2022 10:06 am

chongshengdz wrote:
Wed Jun 22, 2022 6:45 am
straightlight wrote:
Wed Jun 22, 2022 6:28 am
chongshengdz wrote:
Wed Jun 22, 2022 3:25 am

please help modify admin/controller/sale/order.php and /admin/view/template/sale/order_info.twig under account_custom_field.
not admin/controller/customer/custom_field.php and admin/view/template/customer/custom_field_list.twig
What you are acquiring may require extensive coding. Therefore, I would suggest to create a new service request in the Commercial Support section of the forum to get this done as a custom job.
at thebeginning, you are doing wrong, please help me again
The reason was also indicated on your posted commit from Github Opencart. More implications would need to be involved than simply adding those commas in the end. However, if you do require assistance specifically on this request, again, please create a new service request in the Commercial Support section of the forum.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by chongshengdz » Thu Jun 23, 2022 2:33 am

straightlight wrote:
Wed Jun 22, 2022 10:06 am
chongshengdz wrote:
Wed Jun 22, 2022 6:45 am
straightlight wrote:
Wed Jun 22, 2022 6:28 am


What you are acquiring may require extensive coding. Therefore, I would suggest to create a new service request in the Commercial Support section of the forum to get this done as a custom job.
at thebeginning, you are doing wrong, please help me again
The reason was also indicated on your posted commit from Github Opencart. More implications would need to be involved than simply adding those commas in the end. However, if you do require assistance specifically on this request, again, please create a new service request in the Commercial Support section of the forum.
hello, please help me check again, the {{ value }} don't show up anything,
is there anything wrong?

https://www.ectransistors.com/
https://www.transistormosfet.com/


Active Member

Posts

Joined
Sat Apr 12, 2014 10:18 pm

Who is online

Users browsing this forum: Google [Bot] and 15 guests