DavKan
DavKan

Reputation: 59

OpenCart - Want to add comments in invoice if order status is shipped

I tried a lot but was not successful.

In opencart order admin -> Any order -> History.

There we see below fields:

  1. Order Status (processing, processed, shipped etc etc)
  2. Notify customer
  3. Comments

Problem:

As of now only customer comments are published when we click PRINT INVOICE (if customer comments are present)

Code for this in order_invoice.tpl (admin\view\template\sale)

         <?php if ($order['comment']) { ?>
  <table class="comment">
    <tr class="heading">
      <td><b><?php echo $column_comment; ?></b></td>
    </tr>
    <tr>
      <td><?php echo $order['comment']; ?></td>
    </tr>
  </table>    

I want to also show comments when admin select "Shipped" in order status.

If order_status=shipped then show comments by admin in order_invoice.tpl

Because when admin selects SHIPPED in order status and fills tracking number in comments, TRACKING NUMBER thus will be visible in INVOICE which will help customers to retain proof of tracking as well.

I think in opencart there are two variables order_status and order_status_id

I do not know the exact format and linking of these ...Could you please help me with this?

Thanks in advance

Upvotes: 2

Views: 3539

Answers (1)

jx12345
jx12345

Reputation: 1670

Try this,

First amend the data array in the controller (/admin/controller/sale/order.php) to add the order_status_id and the admin comments / histories:

$this->data['orders'][] = array(
  'order_id'             => $order_id,
  'invoice_no'         => $invoice_no,
  'date_added'         => date($this->language->get('date_format_short'), strtotime($order_info['date_added'])),
  'store_name'         => $order_info['store_name'],
  'store_url'          => rtrim($order_info['store_url'], '/'),
  'store_address'      => nl2br($store_address),
  'store_email'        => $store_email,
  'store_telephone'    => $store_telephone,
  'store_fax'          => $store_fax,
  'email'              => $order_info['email'],
  'telephone'          => $order_info['telephone'],
  'shipping_address'   => $shipping_address,
  'shipping_method'    => $order_info['shipping_method'],
  'payment_address'    => $payment_address,
  'payment_company_id' => $order_info['payment_company_id'],
  'payment_tax_id'     => $order_info['payment_tax_id'],
  'payment_method'     => $order_info['payment_method'],
  'product'            => $product_data,
  'voucher'            => $voucher_data,
  'total'              => $total_data,
  'comment'            => nl2br($order_info['comment']),
  'status'             => $order_info['order_status_id'],
  'admin_comments'     => $this->model_sale_order->getOrderHistories($order_id)
);

Then right at the end of the order_invoice.tpl view you can add this:

  <?php if ($order['status'] == 3) { ?>
  <table class="comment">
    <tr class="heading">
      <td><b><?php echo $column_comment; ?></b></td>
    </tr>
    <?php foreach ($order['admin_comments'] as $admin_comment) { ?>
        <?php if ($admin_comment['status'] == 'Shipped') { ?>
           <tr>
                <td><?php echo $admin_comment['comment']; ?></td>
           </tr>
        <?php } ?>
    <?php } ?>
  </table>
  <?php } ?>
</div>
<?php } ?>
</body>
</html>

order_status_id == 3 being shipped.

Upvotes: 1

Related Questions