However, if I select the select all checkbox on the order list page then print the invoices, the custom field value does not appear. This is because the $order_info['custom_field'] array returns empty when bulk selecting orders.
Why does the $order_info['custom_field'] array return empty?
Any help would be appreciated. The code for the vqcache invoice() function in controller/sale/order is below.
Code: Select all
public function invoice() {
$this->load->language('sale/order');
$data['title'] = $this->language->get('text_invoice');
if ($this->request->server['HTTPS']) {
$data['base'] = HTTPS_SERVER;
} else {
$data['base'] = HTTP_SERVER;
}
$data['direction'] = $this->language->get('direction');
$data['lang'] = $this->language->get('code');
$data['text_invoice'] = $this->language->get('text_invoice');
$data['text_order_detail'] = $this->language->get('text_order_detail');
$data['text_order_id'] = $this->language->get('text_order_id');
$data['text_invoice_no'] = $this->language->get('text_invoice_no');
$data['text_invoice_date'] = $this->language->get('text_invoice_date');
$data['text_date_added'] = $this->language->get('text_date_added');
$data['text_telephone'] = $this->language->get('text_telephone');
$data['text_fax'] = $this->language->get('text_fax');
$data['text_email'] = $this->language->get('text_email');
$data['text_website'] = $this->language->get('text_website');
$data['text_to'] = $this->language->get('text_to');
$data['text_ship_to'] = $this->language->get('text_ship_to');
$data['text_payment_method'] = $this->language->get('text_payment_method');
$data['text_shipping_method'] = $this->language->get('text_shipping_method');
$data['column_product'] = $this->language->get('column_product');
$data['column_model'] = $this->language->get('column_model');
$data['column_quantity'] = $this->language->get('column_quantity');
$data['column_price'] = $this->language->get('column_price');
$data['column_total'] = $this->language->get('column_total');
$data['column_comment'] = $this->language->get('column_comment');
$this->load->model('sale/order');
$this->load->model('setting/setting');
$data['orders'] = array();
$orders = array();
if (isset($this->request->post['selected'])) {
$orders = $this->request->post['selected'];
} elseif (isset($this->request->get['order_id'])) {
$orders[] = $this->request->get['order_id'];
}
foreach ($orders as $order_id) {
$order_info = $this->model_sale_order->getOrder($order_id);
if ($order_info) {
// Custom Fields
$this->load->model('sale/custom_field');
$data['custom_fields'] = array();
$filter_data = array(
'sort' => 'cf.sort_order',
'order' => 'ASC'
);
$custom_fields = $this->model_sale_custom_field->getCustomFields($filter_data);
foreach ($custom_fields as $custom_field) {
$custom_field_value_info = $this->model_sale_custom_field->getCustomFieldValue($order_info['custom_field'][$custom_field['custom_field_id']]);
$data['custom_field_value_info'] = $custom_field_value_info;
$data['custom_fields'][] = array(
'custom_field_id' => $custom_field['custom_field_id'],
'custom_field_value' => $this->model_sale_custom_field->getCustomFieldValues($custom_field['custom_field_id']),
'name' => $custom_field['name'],
'value' => $custom_field_value_info['name'],
'type' => $custom_field['type'],
'location' => $custom_field['location'],
'sort_order' => $custom_field['sort_order']
);
}
$store_info = $this->model_setting_setting->getSetting('config', $order_info['store_id']);
$store_name = $order_info['store_name'];
$store_url = $order_info['store_url'];
if (strpos($store_url, "admin") !== false) {
$store_url = str_replace("admin/", "", $store_url);
$store_url = str_replace("admin", "", $store_url);
}
if ($store_info) {
$logo = $store_url . 'image/' . $store_info['config_logo'];
} else {
$logo = $store_url . 'image/' . $this->config->get('config_logo');
}
if ($store_info) {
$store_address = $store_info['config_address'];
$store_email = $store_info['config_email'];
$store_telephone = $store_info['config_telephone'];
$store_fax = $store_info['config_fax'];
} else {
$store_address = $this->config->get('config_address');
$store_email = $this->config->get('config_email');
$store_telephone = $this->config->get('config_telephone');
$store_fax = $this->config->get('config_fax');
}
if ($order_info['invoice_no']) {
$invoice_no = $order_info['invoice_prefix'] . $order_info['invoice_no'];
} else {
$invoice_no = '';
}
if ($order_info['payment_address_format']) {
$format = $order_info['payment_address_format'];
} else {
$format = '{firstname} {lastname}' . "\n" . '{company}' . "\n" . '{address_1}' . "\n" . '{address_2}' . "\n" . '{city} {postcode}' . "\n" . '{zone}' . "\n" . '{country}';
}
$find = array(
'{firstname}',
'{lastname}',
'{company}',
'{address_1}',
'{address_2}',
'{city}',
'{postcode}',
'{zone}',
'{zone_code}',
'{country}'
);
$replace = array(
'firstname' => $order_info['payment_firstname'],
'lastname' => $order_info['payment_lastname'],
'company' => $order_info['payment_company'],
'address_1' => $order_info['payment_address_1'],
'address_2' => $order_info['payment_address_2'],
'city' => $order_info['payment_city'],
'postcode' => $order_info['payment_postcode'],
'zone' => $order_info['payment_zone'],
'zone_code' => $order_info['payment_zone_code'],
'country' => $order_info['payment_country']
);
$payment_address = str_replace(array("\r\n", "\r", "\n"), '<br />', preg_replace(array("/\s\s+/", "/\r\r+/", "/\n\n+/"), '<br />', trim(str_replace($find, $replace, $format))));
if ($order_info['shipping_address_format']) {
$format = $order_info['shipping_address_format'];
} else {
$format = '{firstname} {lastname}' . "\n" . '{company}' . "\n" . '{address_1}' . "\n" . '{address_2}' . "\n" . '{city} {postcode}' . "\n" . '{zone}' . "\n" . '{country}';
}
$find = array(
'{firstname}',
'{lastname}',
'{company}',
'{address_1}',
'{address_2}',
'{city}',
'{postcode}',
'{zone}',
'{zone_code}',
'{country}'
);
$replace = array(
'firstname' => $order_info['shipping_firstname'],
'lastname' => $order_info['shipping_lastname'],
'company' => $order_info['shipping_company'],
'address_1' => $order_info['shipping_address_1'],
'address_2' => $order_info['shipping_address_2'],
'city' => $order_info['shipping_city'],
'postcode' => $order_info['shipping_postcode'],
'zone' => $order_info['shipping_zone'],
'zone_code' => $order_info['shipping_zone_code'],
'country' => $order_info['shipping_country']
);
$shipping_address = str_replace(array("\r\n", "\r", "\n"), '<br />', preg_replace(array("/\s\s+/", "/\r\r+/", "/\n\n+/"), '<br />', trim(str_replace($find, $replace, $format))));
$this->load->model('tool/upload');
$product_data = array();
$products = $this->model_sale_order->getOrderProducts($order_id);
foreach ($products as $product) {
$option_data = array();
$options = $this->model_sale_order->getOrderOptions($order_id, $product['order_product_id']);
foreach ($options as $option) {
if ($option['type'] != 'file') {
$value = $option['value'];
} else {
$upload_info = $this->model_tool_upload->getUploadByCode($option['value']);
if ($upload_info) {
$value = $upload_info['name'];
} else {
$value = '';
}
}
$option_data[] = array(
'name' => $option['name'],
'value' => $value
);
}
$product_data[] = array(
'name' => $product['name'],
'model' => $product['model'],
'option' => $option_data,
'quantity' => $product['quantity'],
'price' => $this->currency->format($product['price'] + ($this->config->get('config_tax') ? $product['tax'] : 0), $order_info['currency_code'], $order_info['currency_value']),
'total' => $this->currency->format($product['total'] + ($this->config->get('config_tax') ? ($product['tax'] * $product['quantity']) : 0), $order_info['currency_code'], $order_info['currency_value'])
);
}
$voucher_data = array();
$vouchers = $this->model_sale_order->getOrderVouchers($order_id);
foreach ($vouchers as $voucher) {
$voucher_data[] = array(
'description' => $voucher['description'],
'amount' => $this->currency->format($voucher['amount'], $order_info['currency_code'], $order_info['currency_value'])
);
}
$total_data = array();
$totals = $this->model_sale_order->getOrderTotals($order_id);
foreach ($totals as $total) {
$total_data[] = array(
'title' => $total['title'],
'text' => $this->currency->format($total['value'], $order_info['currency_code'], $order_info['currency_value']),
);
}
$data['orders'][] = array(
'order_id' => $order_id,
'invoice_no' => $invoice_no,
'date_added' => date($this->language->get('date_format_short'), strtotime($order_info['date_added'])),
'store_name' => $order_info['store_name'],
'store_url' => rtrim($order_info['store_url'], '/'),
'store_address' => nl2br($store_address),
'store_email' => $store_email,
'store_telephone' => $store_telephone,
'store_fax' => $store_fax,
'email' => $order_info['email'],
'telephone' => $order_info['telephone'],
'firstname' => $order_info['payment_firstname'],
'lastname' => $order_info['payment_lastname'],
'shipping_address' => $shipping_address,
'shipping_method' => $order_info['shipping_method'],
'payment_address' => $payment_address,
'payment_method' => $order_info['payment_method'],
'payment_company_id' => (isset($order_info['payment_company_id']) ? $order_info['payment_company_id'] : ''),
'payment_tax_id' => (isset($order_info['payment_tax_id']) ? $order_info['payment_tax_id'] : ''),
'product' => $product_data,
'voucher' => $voucher_data,
'total' => $total_data,
'comment' => nl2br($order_info['comment'])
);
}
}
if (!empty($orders)) {
if (isset($this->request->get['pdf'])) {
$html = $this->load->view('sale/print_email_invoice.tpl', $data);
require_once(DIR_SYSTEM . 'library/dompdf/dompdf_config.inc.php');
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
$pdfoutput = $dompdf->output();
$filepath = DIR_CACHE;
$filename = "invoice_" . $order_id . ".pdf";
$fp = fopen($filepath . $filename, "w");
fwrite($fp, $pdfoutput);
fclose($fp);
header('Content-Transfer-Encoding: binary');
header('Content-Type: application/pdf');
header('Content-Disposition: attachment; filename="' . $filename . '"');
header('Content-Length: '.filesize($filepath . $filename));
readfile($filepath . $filename);
unlink($filepath . $filename);
} else {
$this->response->setOutput($this->load->view('sale/order_invoice.tpl', $data));
}
} else {
$this->session->data['error_warning'] = 'No orders were selected!';
$this->response->redirect($this->url->link('sale/order', 'token=' . $this->session->data['token'], 'SSL'));
}
}