Madhumitha
Madhumitha

Reputation: 348

How to show all status orders in Order List Page

Am new in Opencart, I need to show all status orders in order list page.

I mean my dashboard shows only pending status orders list. But i need to show processing, Missing Order, complete, ect...

This is my code in controller

order.php:

$results = $this->model_sale_order->getOrders($filter_data);

        foreach ($results as $result) {
            $data['orders'][] = array(
                'order_id'      => $result['order_id'],
                'customer'      => $result['customer'],
                'selected_customer_name'=>$result['selected_customer_name'],
                'is_sales_person'=>$result['is_sales_person'],
                'status'        => $result['status'],
                'total'         => $this->currency->format($result['total'], $result['currency_code'], $result['currency_value']),
                'date_added'    => date($this->language->get('date_format_short'), strtotime($result['date_added'])),
                'date_modified' => date($this->language->get('date_format_short'), strtotime($result['date_modified'])),
                'shipping_code' => $result['shipping_code'],
                'view'          => $this->url->link('sale/order/info', 'token=' . $this->session->data['token'] . '&order_id=' . $result['order_id'] . $url, 'SSL'),
                'edit'          => $this->url->link('sale/order/edit', 'token=' . $this->session->data['token'] . '&order_id=' . $result['order_id'] . $url, 'SSL'),
                'delete'        => $this->url->link('sale/order/delete', 'token=' . $this->session->data['token'] . '&order_id=' . $result['order_id'] . $url, 'SSL')
            );

Following code for model

order.php

public function getOrders($data = array()) {

        //$sql = "SELECT o.order_id, CONCAT(o.firstname, ' ', o.lastname) AS customer, (SELECT os.name FROM " . DB_PREFIX . "order_status os WHERE os.order_status_id = o.order_status_id AND os.language_id = '" . (int)$this->config->get('config_language_id') . "') AS status, o.shipping_code, o.total, o.currency_code, o.currency_value, o.date_added, o.date_modified FROM `" . DB_PREFIX . "order` o";
        $sql =  "SELECT o.order_id, CONCAT(o.firstname, ' ', o.lastname) AS customer, (SELECT os.name FROM " . DB_PREFIX . "order_status os WHERE os.order_status_id = o.order_status_id) AS status, o.shipping_code, o.total, o.currency_code, o.currency_value, o.date_added, o.date_modified,o.is_sales_person,o.selected_customer_name FROM `" . DB_PREFIX . "order` o";

        if (isset($data['filter_order_status'])) {
            $implode = array();

            $order_statuses = explode(',', $data['filter_order_status']);

            foreach ($order_statuses as $order_status_id) {
                $implode[] = "o.order_status_id = '" . (int)$order_status_id . "'";
            }

            if ($implode) {
                $sql .= " WHERE (" . implode(" OR ", $implode) . ")";
            } else {

            }
        } else {
            $sql .= " WHERE o.order_status_id > '0'";
        }

        if (!empty($data['filter_order_id'])) {
            $sql .= " AND o.order_id = '" . (int)$data['filter_order_id'] . "'";
        }

        if (!empty($data['filter_customer'])) {
            $sql .= " AND CONCAT(o.firstname, ' ', o.lastname) LIKE '%" . $this->db->escape($data['filter_customer']) . "%'";
        }



        if (!empty($data['filter_route'])) {
            $query1 = $this->db->query("SELECT r.route_id FROM " . DB_PREFIX . "route r left join ".DB_PREFIX."route_description rd on r.route_id=rd.route_id WHERE rd.name = '" . $data['filter_route']. "'");
            $route_id=$query1->row['route_id'];
            $tempArray=array();

            $query2 = $this->db->query("SELECT c.customer_id FROM " . DB_PREFIX . "customer c WHERE c.route_id = '" . $route_id. "'");
            $customerIdList=$query2->rows;
             if(!empty($customerIdList))
             {
                 foreach($customerIdList as $customer)
                 {
                     array_push($tempArray,$customer['customer_id']);
                 }
                 $customer_id=implode(',',$tempArray);

                 $sql .= " AND o.customer_id in(" . $customer_id . ")";
             }

        }

        if (!empty($data['filter_date_added'])) {
            $sql .= " AND DATE(o.date_added) = DATE('" . $this->db->escape($data['filter_date_added']) . "')";
        }

        if (!empty($data['filter_date_modified'])) {
            $sql .= " AND DATE(o.date_modified) = DATE('" . $this->db->escape($data['filter_date_modified']) . "')";
        }

        if (!empty($data['filter_total'])) {
            $sql .= " AND o.total = '" . (float)$data['filter_total'] . "'";
        }
    $status=1;
        $sql.="AND o.order_status_id='".$status."'";


$admin_user=$_COOKIE['admin_user'];
if($admin_user=='sales_01')
{
$sql.="AND o.customer_group_id!=3";
}
elseif($admin_user=='mmd_bangalore')
{
$sql.="AND o.customer_group_id in(3)";
}

        $sort_data = array(
            'o.order_id',
            'customer',
            'status',
            'o.date_added',
            'o.date_modified',
            'o.total'
        );

        if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
            $sql .= " ORDER BY " . $data['sort'];
        } else {
            $sql .= " ORDER BY o.order_id";
        }

        if (isset($data['order']) && ($data['order'] == 'DESC')) {
            $sql .= " DESC";
        } else {
            $sql .= " ASC";
        }

        if (isset($data['start']) || isset($data['limit'])) {
            if ($data['start'] < 0) {
                $data['start'] = 0;
            }

            if ($data['limit'] < 1) {
                $data['limit'] = 20;
            }

            $sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit'];
        }

        $query = $this->db->query($sql);

        return $query->rows;
    }

I try to change this code $sql .= " WHERE o.order_status_id > '0'"; but it not working.

And this is my order list page image:

enter image description here

See here in this page showing only pending status orders.

And this is my database image

enter image description here

And here order_id 35434 not showing in order list page . because order_status_id in 2

How can i show all orders?

Upvotes: 3

Views: 1759

Answers (1)

Pradeep Sapkota
Pradeep Sapkota

Reputation: 2082

Possible without programming

When order is completed you can edit the order and then set order status to completed, cancelled etc. You don't need to edit order list page.

  1. Click in edit order(pencil icon) button.
  2. Scroll down to add order history section.
  3. Then set the status you want.

Upvotes: 0

Related Questions