Adding price and total column in shipping invoice in opencart

1.1k views Asked by At

Opencart by default doesn't show price and total in the print shipping at the admin side. So I added two more columns to the table in shipping invoice in order_shipping.tpl in admin/view/template/sale/order_shipping.tpl but I got the error as

Notice: Undefined variable: column_price in /home/blossewp/public_html/admin/view/template/sale/order_shipping.tpl on line 69 Notice: Undefined index: price in /home/blossewp/public_html/admin/view/template/sale/order_shipping.tpl on line 81

enter image description here

To me it seems the value is coming from the same controller order.php, I can't guess why then these variables are not visible inside order_shipping.tpl if they are visible in /home/blossewp/public_html/admin/view/template/sale/order_invoice.tpl.

Please help. The shipping invoice must have the price and total column.

2

There are 2 answers

1
Abdelrhman Adel On BEST ANSWER

The error is very clear

Notice: Undefined variable: column_price in /home/blossewp/public_html/admin/view/template/sale/order_shipping.tpl on line 69 Notice: Undefined index: price in /home/blossewp/public_html/admin/view/template/sale/order_shipping.tpl on line 81

It means that these variables are not defined, hence they are not passed from the controller to the view, the appropriate controller is located in <OC_ROOT>/admin/controller/sale/order.php , class ControllerSaleOrder @ function shipping() and I don't see your entries defined there

To solve the problem, just define them:
(1) Find $data['column_... = $this->language->get(... and add after $data['column_price'] = $this->language->get('column_price');
(2) Find $product_data[] = array( and add an entry 'price' => $product_info['price'], or $this->currency->format($product_info['price']) if you want to format it!

0
WЮ.С. On

admin/controller/sale/order.php find :

public function shipping() {

and before

$data['orders'][] = array(

add

        $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'])
        );
    }

Then after

$data['orders'][] = array(

add

'total'            => $total_data,

Next step, open admin/view/template/sale/order_shipping and add

{% set last_total = order.total|last %}{{ last_total.text }}