You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在OpenCart 3.0.2.0发票页面添加SKU显示

在OpenCart 3.0.2.0发票页面显示商品SKU的实现方法

我刚好处理过OpenCart 3.x版本的类似需求,给你一步步拆解实现方法,很简单的:

1. 先搞定后台管理员端的发票页面

OpenCart 3切换到Twig模板后,需要先把SKU数据从控制器传到模板里,再在模板中渲染展示。

修改后台订单控制器

找到路径 admin/controller/sale/order.php,打开后定位到 public function invoice() 方法。在遍历订单商品的代码块中,构建$data['products']数组时,新增SKU字段:

$data['products'][] = array(
    'product_id' => $product['product_id'],
    'name'       => $product['name'],
    'model'      => $product['model'],
    'sku'        => $product['sku'], // 新增这行,将SKU加入模板数据
    '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']),
    'href'       => $this->url->link('product/product', 'product_id=' . $product['product_id'])
);

修改后台发票模板

找到路径 admin/view/template/sale/order_invoice.twig,打开后做两处修改:

  • 在表头部分新增SKU列:
<thead>
  <tr>
    <th class="text-left">{{ column_name }}</th>
    <th class="text-left">{{ column_model }}</th>
    <th class="text-left">SKU</th> <!-- 新增SKU表头 -->
    <th class="text-right">{{ column_quantity }}</th>
    <th class="text-right">{{ column_price }}</th>
    <th class="text-right">{{ column_total }}</th>
  </tr>
</thead>
  • 在商品数据行中新增SKU显示:
<tr>
  <td class="text-left">{{ product.name }}<br>
    {% for option in product.option %}
    <small>{{ option.name }}: {{ option.value }}</small><br>
    {% endfor %}
  </td>
  <td class="text-left">{{ product.model }}</td>
  <td class="text-left">{{ product.sku }}</td> <!-- 新增SKU显示 -->
  <td class="text-right">{{ product.quantity }}</td>
  <td class="text-right">{{ product.price }}</td>
  <td class="text-right">{{ product.total }}</td>
</tr>

2. 处理前台用户端的发票页面

如果需要用户在个人账户查看发票时也显示SKU,重复类似操作:

修改前台订单控制器

找到路径 catalog/controller/account/order.php,定位到 public function invoice() 方法,同样在商品数组中添加'sku' => $product['sku'],字段,修改逻辑和后台控制器一致。

修改前台发票模板

找到路径 catalog/view/theme/你的主题名称/template/account/order_invoice.twig(默认主题为default),在表头和商品行中添加SKU的表头与显示代码,逻辑和后台模板修改相同。

3. 可选:让邮件发票也显示SKU

如果希望发送给用户的订单邮件中发票包含SKU,修改以下两个文件:

  • 控制器:catalog/controller/mail/order.php,在构建邮件模板的商品数组时添加'sku' => $product['sku'],
  • 邮件模板:catalog/view/theme/你的主题名称/template/mail/order_invoice.twig,添加SKU的表头与显示列

完成所有修改后,记得刷新OpenCart缓存(后台系统→设置→存储中点击刷新按钮),再查看发票页面就能看到SKU了。

内容的提问来源于stack exchange,提问作者Navid

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 07:45:33