Post by Matt-UDC » Mon Jul 23, 2018 8:25 pm

Hi, I'm running OC 3.0.2 (with Journal2 theme, but I that shouldn't change this query)

I used "Customers > Custom Fields" to add a field for our internal account number for our business customers.

I can see the data in the MySQL database in the 'oc_customers' table in the field/column labelled as 'custom_field'. The same data exists in the 'oc_order' table in the field 'custom_field' as well.

The data is stored as {"1":"ABC1234"}. (presumably if more custom fields are added they are encapsulated in this same field with their own delimiter)

When an order is placed and an email send to us and the customer I'd like to include this field in the subject and in the body of the email.

Right now, I'm clueless as to how to extract this value into a variable that I can place in the email.

I've search and search and couldn't find anything to do this. Could someone kindly point me in the right direction?

Thanks!

User avatar
Newbie

Posts

Joined
Wed May 31, 2017 5:32 pm

Post by straightlight » Mon Jul 23, 2018 8:44 pm

More information is needed. Is it for an account or address custom field type you'd like to add to the email's subject and body?

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 Matt-UDC » Mon Jul 23, 2018 9:05 pm

Thanks for the quick reply.

It's just a short text string similar to "ABC1234" , added as a 'custom field' using the built in OpenCart option in the Admin panel, under Customers.

The string just needs to be inserted in the body of the email. It's not an email address or anything like that.

Once I have the data loaded extracted from database and inserted into a variable I believe I can probably handle customising the email that goes out.

User avatar
Newbie

Posts

Joined
Wed May 31, 2017 5:32 pm

Post by straightlight » Mon Jul 23, 2018 9:14 pm

When creating a custom field in the admin - > customers page, the form still inquiries to choose between an account type or an address type of custom field. For which type is it related for?

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 Matt-UDC » Mon Jul 23, 2018 9:37 pm

I understand now, my mistake.

Custom Field Name: "Account Number"
Location: Account
Type: Text
Value: (empty)
Validation (empty)
Customer Group: Business Customers
Required: Business Customers
Status: Enabled

User avatar
Newbie

Posts

Joined
Wed May 31, 2017 5:32 pm

Post by straightlight » Mon Jul 23, 2018 9:57 pm

Account type. What if the customer doesn't have an account in order for the custom field to show on the order email?

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 Matt-UDC » Mon Jul 23, 2018 10:26 pm

If the string is empty then nothing will be added to the subject or the body of the email.

User avatar
Newbie

Posts

Joined
Wed May 31, 2017 5:32 pm

Post by straightlight » Mon Jul 23, 2018 10:30 pm

You could use the following into your catalog/controller/mail/order.php file at your desired location:

Code: Select all

// Custom Fields
		$data['custom_fields'] = array();
		
		$this->load->model('account/custom_field');
		
		$custom_fields = $this->model_account_custom_field->getCustomFields();
		
		foreach ($custom_fields as $custom_field) {
			if ($custom_field['location'] == 'account') {
				$data['custom_fields'][] = $custom_field;
			}
		}
Then, in your order mail twig file, you could use:

Code: Select all

{% if custom_fields %}
    {% for custom_field in custom_fields %}
        … your argument here ...
    {% endfor %}
{% endif %}
Replace the: … your argument here with your actual condition and custom field name you want to add.

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 Matt-UDC » Mon Jul 23, 2018 10:59 pm

I wasn't expecting such a comprehensive reply!

Thank you very much. I'll give it a whirl this evening when things have calmed down around here.

Cheers,
Matt

User avatar
Newbie

Posts

Joined
Wed May 31, 2017 5:32 pm

Post by aliensgroup » Mon Jan 31, 2022 9:55 pm

straightlight wrote:
Mon Jul 23, 2018 10:30 pm
You could use the following into your catalog/controller/mail/order.php file at your desired location:

Code: Select all

// Custom Fields
		$data['custom_fields'] = array();
		
		$this->load->model('account/custom_field');
		
		$custom_fields = $this->model_account_custom_field->getCustomFields();
		
		foreach ($custom_fields as $custom_field) {
			if ($custom_field['location'] == 'account') {
				$data['custom_fields'][] = $custom_field;
			}
		}
Then, in your order mail twig file, you could use:

Code: Select all

{% if custom_fields %}
    {% for custom_field in custom_fields %}
        … your argument here ...
    {% endfor %}
{% endif %}
Replace the: … your argument here with your actual condition and custom field name you want to add.
Good afternoon, I'm new. Could you indicate with an example how the code could look like - ... your argument here

Newbie

Posts

Joined
Mon Jan 31, 2022 9:44 pm
Who is online

Users browsing this forum: sidclel and 88 guests