Thank you.straightlight wrote: ↑Fri Apr 03, 2020 6:51 amTake note that adding custom fields into the invoice may result dealing with split invoice template between pages. Only use the following if considering to use split pages if you cannot configure your printer driver to a fit landscape.
In admin/controller/sale/order.php file, in the invoice() method,
find:
add above:Code: Select all
foreach ($orders as $order_id) {
Then, find - still in the invoice() method:Code: Select all
$this->load->model('customer/custom_field');
add above:Code: Select all
$data['orders'][] = array(
Then, in admin/view/template/sale/order_invoice.twig file,Code: Select all
$account_custom_fields = array(); $filter_data = array( 'sort' => 'cf.sort_order', 'order' => 'ASC' ); $custom_fields = $this->model_customer_custom_field->getCustomFields($filter_data); foreach ($custom_fields as $custom_field) { if ($custom_field['location'] == 'account' && isset($order_info['custom_field'][$custom_field['custom_field_id']])) { if ($custom_field['type'] == 'select' || $custom_field['type'] == 'radio') { $custom_field_value_info = $this->model_customer_custom_field->getCustomFieldValue($order_info['custom_field'][$custom_field['custom_field_id']]); if ($custom_field_value_info) { $account_custom_fields[] = array( 'name' => $custom_field['name'], 'value' => $custom_field_value_info['name'] ); } } if ($custom_field['type'] == 'checkbox' && is_array($order_info['custom_field'][$custom_field['custom_field_id']])) { foreach ($order_info['custom_field'][$custom_field['custom_field_id']] as $custom_field_value_id) { $custom_field_value_info = $this->model_customer_custom_field->getCustomFieldValue($custom_field_value_id); if ($custom_field_value_info) { $account_custom_fields[] = array( 'name' => $custom_field['name'], 'value' => $custom_field_value_info['name'] ); } } } if ($custom_field['type'] == 'text' || $custom_field['type'] == 'textarea' || $custom_field['type'] == 'file' || $custom_field['type'] == 'date' || $custom_field['type'] == 'datetime' || $custom_field['type'] == 'time') { $account_custom_fields[] = array( 'name' => $custom_field['name'], 'value' => $order_info['custom_field'][$custom_field['custom_field_id']] ); } if ($custom_field['type'] == 'file') { $upload_info = $this->model_tool_upload->getUploadByCode($order_info['custom_field'][$custom_field['custom_field_id']]); if ($upload_info) { $account_custom_fields[] = array( 'name' => $custom_field['name'], 'value' => $upload_info['name'] ); } } } } // Custom fields $payment_custom_fields = array(); foreach ($custom_fields as $custom_field) { if ($custom_field['location'] == 'address' && isset($order_info['payment_custom_field'][$custom_field['custom_field_id']])) { if ($custom_field['type'] == 'select' || $custom_field['type'] == 'radio') { $custom_field_value_info = $this->model_customer_custom_field->getCustomFieldValue($order_info['payment_custom_field'][$custom_field['custom_field_id']]); if ($custom_field_value_info) { $payment_custom_fields[] = array( 'name' => $custom_field['name'], 'value' => $custom_field_value_info['name'], 'sort_order' => $custom_field['sort_order'] ); } } if ($custom_field['type'] == 'checkbox' && is_array($order_info['payment_custom_field'][$custom_field['custom_field_id']])) { foreach ($order_info['payment_custom_field'][$custom_field['custom_field_id']] as $custom_field_value_id) { $custom_field_value_info = $this->model_customer_custom_field->getCustomFieldValue($custom_field_value_id); if ($custom_field_value_info) { $payment_custom_fields[] = array( 'name' => $custom_field['name'], 'value' => $custom_field_value_info['name'], 'sort_order' => $custom_field['sort_order'] ); } } } if ($custom_field['type'] == 'text' || $custom_field['type'] == 'textarea' || $custom_field['type'] == 'file' || $custom_field['type'] == 'date' || $custom_field['type'] == 'datetime' || $custom_field['type'] == 'time') { $payment_custom_fields[] = array( 'name' => $custom_field['name'], 'value' => $order_info['payment_custom_field'][$custom_field['custom_field_id']], 'sort_order' => $custom_field['sort_order'] ); } if ($custom_field['type'] == 'file') { $upload_info = $this->model_tool_upload->getUploadByCode($order_info['payment_custom_field'][$custom_field['custom_field_id']]); if ($upload_info) { $payment_custom_fields[] = array( 'name' => $custom_field['name'], 'value' => $upload_info['name'], 'sort_order' => $custom_field['sort_order'] ); } } } } // Shipping $shipping_custom_fields = array(); foreach ($custom_fields as $custom_field) { if ($custom_field['location'] == 'address' && isset($order_info['shipping_custom_field'][$custom_field['custom_field_id']])) { if ($custom_field['type'] == 'select' || $custom_field['type'] == 'radio') { $custom_field_value_info = $this->model_customer_custom_field->getCustomFieldValue($order_info['shipping_custom_field'][$custom_field['custom_field_id']]); if ($custom_field_value_info) { $shipping_custom_fields[] = array( 'name' => $custom_field['name'], 'value' => $custom_field_value_info['name'], 'sort_order' => $custom_field['sort_order'] ); } } if ($custom_field['type'] == 'checkbox' && is_array($order_info['shipping_custom_field'][$custom_field['custom_field_id']])) { foreach ($order_info['shipping_custom_field'][$custom_field['custom_field_id']] as $custom_field_value_id) { $custom_field_value_info = $this->model_customer_custom_field->getCustomFieldValue($custom_field_value_id); if ($custom_field_value_info) { $shipping_custom_fields[] = array( 'name' => $custom_field['name'], 'value' => $custom_field_value_info['name'], 'sort_order' => $custom_field['sort_order'] ); } } } if ($custom_field['type'] == 'text' || $custom_field['type'] == 'textarea' || $custom_field['type'] == 'file' || $custom_field['type'] == 'date' || $custom_field['type'] == 'datetime' || $custom_field['type'] == 'time') { $shipping_custom_fields[] = array( 'name' => $custom_field['name'], 'value' => $order_info['shipping_custom_field'][$custom_field['custom_field_id']], 'sort_order' => $custom_field['sort_order'] ); } if ($custom_field['type'] == 'file') { $upload_info = $this->model_tool_upload->getUploadByCode($order_info['shipping_custom_field'][$custom_field['custom_field_id']]); if ($upload_info) { $shipping_custom_fields[] = array( 'name' => $custom_field['name'], 'value' => $upload_info['name'], 'sort_order' => $custom_field['sort_order'] ); } } } }
find:
add below:Code: Select all
<b>{{ text_email }}</b> {{ order.store_email }}<br />
Then, find:Code: Select all
{% if order.account_custom_fields %} <table class="table table-bordered"> <thead> <tr> <td colspan="2">{{ text_account_custom_field }}</td> </tr> </thead> <tbody> {% for custom_field in order.account_custom_fields %} <tr> <td>{{ custom_field.name }}</td> <td>{{ custom_field.value }}</td> </tr> {% endfor %} </tbody> </table> <br /> {% endif %}
add below:Code: Select all
<b>{{ text_payment_method }}</b> {{ order.payment_method }}<br />
Then, find:Code: Select all
{% if order.payment_custom_fields %} <table class="table table-bordered"> <thead> <tr> <td colspan="2">{{ text_payment_custom_field }}</td> </tr> </thead> <tbody> {% for custom_field in order.payment_custom_fields %} <tr> <td>{{ custom_field.name }}</td> <td>{{ custom_field.value }}</td> </tr> {% endfor %} </tbody> </table> <br /> {% endif %}
add below:Code: Select all
<b>{{ text_shipping_method }}</b> {{ order.shipping_method }}
Then, follow this FAQ: viewtopic.php?f=134&t=215776#p718325Code: Select all
{% if order.shipping_custom_fields %} <table class="table table-bordered"> <thead> <tr> <td colspan="2">{{ text_shipping_custom_field }}</td> </tr> </thead> <tbody> {% for custom_field in order.shipping_custom_fields %} <tr> <td>{{ custom_field.name }}</td> <td>{{ custom_field.value }}</td> </tr> {% endfor %} </tbody> </table> {% endif %}
You can re-arrange the invoice presentation as you see fit.
Note: You forget to mention adding
Code: Select all
'shipping_custom_fields' => $shipping_custom_fields,
'payment_custom_fields' => $payment_custom_fields,
to
Code: Select all
$data['orders'][] = array(