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

OC3.0.2.0后台订单信息添加SKU显示的实现方法求助

How to Display Product SKUs on Order Info Page in OpenCart 3.0.2.0 Admin

Hey there! I’ve tinkered with OpenCart 3.0.2.0 a fair bit, so let me walk you through exactly how to add product SKUs to the order info page in your admin panel. It’s a straightforward two-part tweak—just make sure you back up your files first to be safe!

1. Update the Order Controller to Pull SKU Data

First, we need to fetch the SKU from the product database table and pass it to the template. Head to admin/controller/sale/order.php and find the getOrderProducts() method (it’s usually around lines 800-900, but line numbers can vary a bit).

Look for the database query that grabs order products. We’ll modify it to include the SKU and join the product table:

$products = $this->db->query("SELECT op.product_id, op.name, op.model, op.quantity, op.price, op.total, op.tax, op.reward, p.sku FROM " . DB_PREFIX . "order_product op LEFT JOIN " . DB_PREFIX . "product p ON op.product_id = p.product_id WHERE op.order_id = '" . (int)$order_id . "'");

Next, inside the loop that builds the $data['products'] array, add a line to include the SKU:

foreach ($products->rows as $product) {
    // Keep all your existing code here
    $data['products'][] = array(
        'product_id'  => $product['product_id'],
        'name'        => $product['name'],
        'model'       => $product['model'],
        'sku'         => $product['sku'], // Add this line to pass SKU to template
        'quantity'    => $product['quantity'],
        'price'       => $this->currency->format($product['price'], $order_info['currency_code'], $order_info['currency_value']),
        'total'       => $this->currency->format($product['total'], $order_info['currency_code'], $order_info['currency_value']),
        'tax'         => $this->currency->format($product['tax'], $order_info['currency_code'], $order_info['currency_value']),
        'reward'      => $product['reward']
    );
}

2. Modify the Template to Show the SKU

Now let’s add the SKU to the order info page layout. Go to admin/view/template/sale/order_info.twig and find the table that displays order products (look for <table class="table table-bordered table-hover">).

First, add a new header column for SKU in the <thead> section—insert this right after the Model column:

<th class="text-left">{{ column_sku }}</th>

Then, in the <tbody> loop where product details are rendered, add the SKU value right after the model:

<td class="text-left">{{ product.sku }}</td>

3. Add the Language Label (Optional but Clean)

To make the column header show a proper label instead of raw code, add a language string. Go to admin/language/en-gb/sale/order.php (use your language’s folder if you’re not using English) and add this line somewhere among the other column definitions:

$_['column_sku'] = 'SKU';

Final Step: Clear Cache

OpenCart caches template files, so don’t forget to clear your admin cache! Go to System > Maintenance > Cache and click "Clear" to make sure your changes show up immediately.

That’s it! Reload any order info page in your admin panel, and you’ll now see the product SKUs displayed alongside the other product details.


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.27 07:08:15