多个发票中的客户自定义字段opencart 2

时间:2018-04-05 13:39:42

标签: opencart invoice

我有一个vqmod,它将客户custom_field添加到invoice.tpl只要我点击一张发票的打印按钮就可以正常工作。但是,如果我选择多个订单并点击打印发票按钮,则只显示一个订单(最旧)的自定义字段值。

下面的vqmod:

<file name="admin/controller/sale/order.php">
    <operation>
        <search position="before"><![CDATA[$total_data = array();]]></search>
        <add><![CDATA[
        $data['account_custom_field'] = $order_info['custom_field'];

        // Custom Fields 
        $this->load->model('customer/custom_field');
        $data['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'] == 'text') {
                    $data['account_custom_fields'][] = array(
                        'name'  => $custom_field['name'],
                        'value' => $order_info['custom_field'][$custom_field['custom_field_id']]
                    );
                }
            }
        }

        ]]></add>
    </operation>
</file>
<file name="admin/view/template/sale/order_invoice.tpl">
   <operation info="add custom field in invoice">
        <search position="after"><![CDATA[<?php echo $order['payment_address']; ?>]]></search>
        <add><![CDATA[
        <?php if ($account_custom_fields) { ?>
          <br /><br />
          <?php foreach ($account_custom_fields as $custom_field) { ?>
          <b><?php echo $custom_field['name']; ?>:</b> <?php echo $custom_field['value']; ?>
          <?php } ?>
        <?php } ?>
        ]]></add>
    </operation>
</file>

我忘了什么?

1 个答案:

答案 0 :(得分:0)

1)$data['account_custom_fields']不应该是$data数组的一部分。只需将其变为名为$account_custom_fields的常规变量。

2)构建阵列后,您需要将其添加到$data['orders']数组中,就像其他所有内容一样......

$data['orders'][] = array(
    'order_id'              => $order_id,
    'invoice_no'            => $invoice_no,
    'account_custom_fields' => $account_custom_fields,

然后像模板中的其他内容一样访问它:$order['account_custom_fields']

您的其他变量$data['account_custom_field']也是如此。这里要理解的重要一点是,您正在foreach循环中间将代码插入控制器,循环遍历订单并构建数组 - 然后在模板内再次迭代。因此,您希望按订单添加的任何内容和访问权限都需要添加到该特定订单的$ data [&#39; orders&#39;]数组