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!
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!
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
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.
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.
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
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
You could use the following into your catalog/controller/mail/order.php file at your desired location:
Then, in your order mail twig file, you could use:
Replace the: … your argument here with your actual condition and custom field name you want to add.
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;
}
}
Code: Select all
{% if custom_fields %}
{% for custom_field in custom_fields %}
… your argument here ...
{% endfor %}
{% endif %}
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
Good afternoon, I'm new. Could you indicate with an example how the code could look like - ... your argument herestraightlight wrote: ↑Mon Jul 23, 2018 10:30 pmYou could use the following into your catalog/controller/mail/order.php file at your desired location:
Then, in your order mail twig file, you could use: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; } }
Replace the: … your argument here with your actual condition and custom field name you want to add.Code: Select all
{% if custom_fields %} {% for custom_field in custom_fields %} … your argument here ... {% endfor %} {% endif %}
Who is online
Users browsing this forum: DesignCart, OSWorX, sidclel and 103 guests