0

In OpenCart 3.0.2.0, I'm trying to get the Invoices pages to display the "SKU" variable for each product. The variable is in the database, along with other product data, but for some ungodly reason, OpenCart doesn't have an option to display it. You can display the product name, price, stock availability, etc, but not the SKU.

Does anyone know how to do this specifically in OC 3? They've switched from PHP to Twig for the templates, and I'm not sure what I'm doing wrong but the method I was using in OC 2.0 is NOT working in 3.0.

Radhika
  • 533
  • 5
  • 22
Navid
  • 65
  • 10

2 Answers2

2

If you want SKU in order_invoice in admin side then, you have to modify as below:

admin/model/sale/order.php

find :

public function getOrderProducts($order_id) {
    $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_product WHERE order_id = '" . (int)$order_id . "'");

    return $query->rows;
}

replace :

public function getOrderProducts($order_id) {
    $query = $this->db->query("SELECT op.*,p.sku FROM " . DB_PREFIX . "order_product op LEFT JOIN " . DB_PREFIX . "product p on op.product_id = p.product_id WHERE order_id = '" . (int)$order_id . "'");

    return $query->rows;
}

admin/controller/sale/order.php

in

`public function invoice()`

find:

 `$product_data[] = array(
    'name'     => $product['name'],`

add after that :

`'sku'  => $product['sku'],`

in admin/view/sale/order_invoice.twig

add:

`{{ product.sku }}`

So you have to fetch sku from product table first which is not available in default order invoice page.

Radhika
  • 533
  • 5
  • 22
0

Are you talking about it appearing in admin/view/sale/order_invoice.twig?

If so, first modify admin/controller/sale/order.php at around line 518:

    foreach ($products as $product) {
        $data['order_products'][] = array(
            'product_id' => $product['product_id'],
            'name'       => $product['name'],
            'model'      => $product['model'],
            'option'     => $this->model_sale_order->getOrderOptions($this->request->get['order_id'], $product['order_product_id']),
            'quantity'   => $product['quantity'],
            'price'      => $product['price'],
            'total'      => $product['total'],
            'reward'     => $product['reward']
        );
    }

include somewhere there (like after the model line, let's say), a line with:

'sku'      => $product['sku'],

Then in admin/view/sale/order_invoice.twig add where ever you want it to appear with:

{{ product.sku }}

You'll have to stylize it or make a column for it as you see fit of course. Hopefully, this points you in the right direction.

Nancy
  • 522
  • 4
  • 15