Post by djcottrell » Mon Aug 13, 2018 1:29 am

I have created a custom shipping module that allows local delivery to selected customers. There is a custom field called Local Delivery that is disabled so it shows up on the admin customer edit side but not the customer account login side. I am using the following code to access the custom fields but it will only display custom fields that are enabled. I need to find how to show those that are disabled as well.

Code: Select all

// Custom Fields
$data['custom_fields'] = array();
$this->load->model('account/custom_field');
$custom_fields = $this->model_account_custom_field->getCustomFields($this->config->get('config_customer_group_id'));
foreach ($custom_fields as $custom_field) {
	if ($custom_field['location'] == 'account') {
		$data['custom_fields'][] = $custom_field;
	}
}
print_r($data['custom_fields']);

Newbie

Posts

Joined
Fri Oct 14, 2016 6:08 am

Post by straightlight » Mon Aug 13, 2018 1:32 am

No OC version posted. Forum rules unfollowed.

- catalog/model/account/custom_field.php file:
$custom_field_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "custom_field_customer_group` cfcg LEFT JOIN `" . DB_PREFIX . "custom_field` cf ON (cfcg.custom_field_id = cf.custom_field_id) LEFT JOIN `" . DB_PREFIX . "custom_field_description` cfd ON (cf.custom_field_id = cfd.custom_field_id) WHERE cf.status = '1' AND cfd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND cfcg.customer_group_id = '" . (int)$customer_group_id . "' ORDER BY cf.sort_order ASC");

The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.

F. Rules:

- viewtopic.php?f=176&t=200480
- viewtopic.php?f=176&t=200804


Regards,
Straightlight


Legendary Member

Posts

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

Post by djcottrell » Mon Aug 13, 2018 7:05 am

Version 3.0.2

I don't think this is what I am looking for. I am attempting to pull the value of the fields for the user if they are logged in. I realized the query I included was for pulling fields for a specific group not for the individual. I have not been able to find the query for pulling the results.

Newbie

Posts

Joined
Fri Oct 14, 2016 6:08 am

Post by straightlight » Mon Aug 13, 2018 7:38 am

To accomplish those two separated requests, that has not been specified from the first post altogether (forum rules), would be this one:

Code: Select all

$this->db->query("SELECT * FROM `" . DB_PREFIX . "custom_field` cf LEFT JOIN `" . DB_PREFIX . "custom_field_description` cfd ON (cf.custom_field_id = cfd.custom_field_id) LEFT JOIN `" . DB_PREFIX . "custom_field_customer_group` `cfcg` ON (`cfcg`.`custom_field_id` = `cfd`.`custom_field_id`) INNER JOIN `" . DB_PREFIX . "customer_group` `cg` ON (`cg`.`customer_group_id` = `cfcg`.`customer_group_id`) INNER JOIN `" . DB_PREFIX . "customer` `c` ON (`c`.`customer_group_id` = `cg`.`customer_group_id`) WHERE cfd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND `c`.`customer_id` = '" . (int)$this->customer->getId() . "' AND LENGTH(TRIM(`cf`.`value`)) > 0 AND `cfcg`.`required` = '1' ORDER BY cf.sort_order ASC");
Last edited by straightlight on Mon Aug 13, 2018 8:44 am, edited 2 times in total.

The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.

F. Rules:

- viewtopic.php?f=176&t=200480
- viewtopic.php?f=176&t=200804


Regards,
Straightlight


Legendary Member

Posts

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

Post by djcottrell » Mon Aug 13, 2018 7:55 am

This code throws the following error. I dont know enough about the database configuration yet to diagnose this.

Code: Select all

Fatal error: Uncaught exception 'Exception' with message 'Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''oc_custom_field' cf LEFT JOIN 'oc_custom_field_description' cfd ON (cf.custom_' at line 1<br />Error No: 1064<br /> SELECT * FROM 'oc_custom_field' cf LEFT JOIN 'oc_custom_field_description' cfd ON (cf.custom_field_id = cfd.custom_field_id) LEFT JOIN 'oc_custom_field_customer_group' 'cfcg' ON ('cfcg'.'custom_field_id' = 'cfd'.'custom_field_id') INNER JOIN 'oc_customer_group' cg' ON ('cg'.'customer_group_id' = 'cfcg'.'customer_group_id') INNER JOIN 'oc_customer' 'c' ON ('c'.'customer_group_id' = 'cg'.'customer_group_id') WHERE cfd.language_id = '1' AND 'c'.'customer_id' = '2' ORDER BY cf.sort_order ASC' in /home/omadamar/public_html/design/victory/system/library/db/mysqli.php:40 Stack trace: #0 /home/omadamar/public_html/design/victory/system/library/db.php(45): DB\MySQLi->query('\nSELECT * FROM ...') #1 /home/omadama in /home/test/system/library/db/mysqli.php on line 40

Newbie

Posts

Joined
Fri Oct 14, 2016 6:08 am

Post by straightlight » Mon Aug 13, 2018 8:04 am

Fixed.

The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.

F. Rules:

- viewtopic.php?f=176&t=200480
- viewtopic.php?f=176&t=200804


Regards,
Straightlight


Legendary Member

Posts

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

Post by djcottrell » Mon Aug 13, 2018 8:27 am

The code you gave me pulls the fields but not their values. I need to check if the field is checked. Your query returned the following.

Code: Select all

Array(
	[custom_field_id] => 2
	[type] => checkbox
	[value] => 
	[validation] => 
	[location] => account
	[status] => 1
	[sort_order] => 1
	[language_id] => 1
	[name] => Local delivery
	[customer_group_id] => 2
	[required] => 0
	[approval] => 0
	[customer_id] => 2
	[store_id] => 0
	[firstname] => Test 
	[lastname] => Account
	[email] => test@test.com
	[telephone] => 1234567890
	[fax] => 
	[password] => 00000000000000000000000
	[salt] => 000000000
	[cart] => 
	[wishlist] => 
	[newsletter] => 0
	[address_id] => 2
	[custom_field] => {"3":["7"],"2":["6"]}
	[ip] => 000.000.000.000
	[safe] => 1
	[token] => 
	[code] => 
	[date_added] => 2018-08-12 11:21:18
)

Newbie

Posts

Joined
Fri Oct 14, 2016 6:08 am

Post by straightlight » Mon Aug 13, 2018 8:36 am

Correct. The JSON string is pulling from the query. Your previous post state to build a query to pull customers that are logged in and your first post is about any custom fields statuses. However, the JSON string needs to be decoded with your posted codes.

The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.

F. Rules:

- viewtopic.php?f=176&t=200480
- viewtopic.php?f=176&t=200804


Regards,
Straightlight


Legendary Member

Posts

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

Post by djcottrell » Mon Aug 13, 2018 8:37 am

In the second post it also states
I am attempting to pull the value of the fields

Newbie

Posts

Joined
Fri Oct 14, 2016 6:08 am

Post by straightlight » Mon Aug 13, 2018 8:43 am

djcottrell wrote:
Mon Aug 13, 2018 8:37 am
In the second post it also states
I am attempting to pull the value of the fields
True. However, this portion was not mentioned prior:
I need to check if the field is checked.
Please follow the forum rules, Currently, you are posting partial information piece-by-piece.

The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.

F. Rules:

- viewtopic.php?f=176&t=200480
- viewtopic.php?f=176&t=200804


Regards,
Straightlight


Legendary Member

Posts

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

Post by straightlight » Mon Aug 13, 2018 8:44 am

Code edited.

The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.

F. Rules:

- viewtopic.php?f=176&t=200480
- viewtopic.php?f=176&t=200804


Regards,
Straightlight


Legendary Member

Posts

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

Post by djcottrell » Mon Aug 13, 2018 8:52 am

Ok so you are saying that the code you gave me allows me to see if the checkbox is checked without a value. The results I get from what you gave me does not return anything different if the box is check vs not checked so I assumed that I need the value in order to determine that case. If I am missing something please fill me in.

Newbie

Posts

Joined
Fri Oct 14, 2016 6:08 am

Post by straightlight » Mon Aug 13, 2018 9:02 am

It depends. Are you referring from the customer's side of view or the admin side of view? If the admin, then obviously, only the required fields would be shown from the last edited codes. However, if from the customer's side of view, then it might require more codes to accomplish your request as 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, since it may require a larger mount of time to complete this.

The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.

F. Rules:

- viewtopic.php?f=176&t=200480
- viewtopic.php?f=176&t=200804


Regards,
Straightlight


Legendary Member

Posts

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

Post by djcottrell » Mon Aug 13, 2018 9:10 am

I am working on the checkout system so I am guessing you would call this the customer side. I need to know weather the checkbox is checked so I can display the option or remove it. I also made a few different types of custom fields some active and some not and they all return the same blank value.

The last code you provided returned a blank array

Newbie

Posts

Joined
Fri Oct 14, 2016 6:08 am

Post by straightlight » Mon Aug 13, 2018 9:30 am

One example you could refer would be in the catalog/view/theme/<your_theme>/template/account/edit.twig file - regarding checkboxes with custom fields TWIG file with a bit of customization with the related controller file:

Code: Select all

{% if custom_field.type == 'checkbox' %}
              <div class="form-group{% if custom_field.required %} required {% endif %} custom-field" data-sort="{{ custom_field.sort_order }}">
                <label class="col-sm-2 col-form-label">{{ custom_field.name }}</label>
                <div class="col-sm-10">
                  <div>
                    {% for custom_field_value in custom_field.custom_field_value %}
                      <div class="form-check">
                        {% if account_custom_field[custom_field.custom_field_id] and custom_field_value.custom_field_value_id in account_custom_field[custom_field.custom_field_id] %}
                          <label><input type="checkbox" name="custom_field[{{ custom_field.location }}][{{ custom_field.custom_field_id }}][]" value="{{ custom_field_value.custom_field_value_id }}" class="form-check-input" checked="checked"/>
                            {{ custom_field_value.name }}</label>
                        {% else %}
                          <label><input type="checkbox" name="custom_field[{{ custom_field.location }}][{{ custom_field.custom_field_id }}][]" value="{{ custom_field_value.custom_field_value_id }}" class="form-check-input"/>
                            {{ custom_field_value.name }}</label>
                        {% endif %}
                      </div>
                    {% endfor %}
                  </div>
                  {% if error_custom_field[custom_field.custom_field_id] %}
                    <div class="text-danger">{{ error_custom_field[custom_field.custom_field_id] }}</div>
                  {% endif %}
                </div>
              </div>
            {% endif %}

The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.

F. Rules:

- viewtopic.php?f=176&t=200480
- viewtopic.php?f=176&t=200804


Regards,
Straightlight


Legendary Member

Posts

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

Users browsing this forum: No registered users and 8 guests