Orders::view PHP Method

view() public method

public view ( )
    public function view()
    {
        if ($result = $this->Orders_model->getOrder($this->uri->rsegment(3), $this->customer->getId())) {
            // check if customer_id is set in uri string
            $order_id = (int) $this->uri->rsegment(3);
        } else {
            redirect('account/orders');
        }
        $this->template->setBreadcrumb('<i class="fa fa-home"></i>', '/');
        $this->template->setBreadcrumb($this->lang->line('text_my_account'), 'account/account');
        $this->template->setBreadcrumb($this->lang->line('text_heading'), 'account/orders');
        $this->template->setBreadcrumb($this->lang->line('text_view_heading'), 'account/orders/view');
        $this->template->setTitle($this->lang->line('text_view_heading'));
        $this->template->setHeading($this->lang->line('text_view_heading'));
        $data['reorder_url'] = site_url('account/orders/reorder/' . $order_id . '/' . $result['location_id']);
        $data['back_url'] = site_url('account/orders');
        $date_format = $this->config->item('date_format') ? $this->config->item('date_format') : '%d %M %y';
        $time_format = $this->config->item('time_format') ? $this->config->item('time_format') : '%h:%i %a';
        $data['order_id'] = $result['order_id'];
        $data['date_added'] = mdate($date_format, strtotime($result['date_added']));
        $data['order_time'] = mdate($time_format, strtotime($result['order_time']));
        $data['order_date'] = mdate($date_format, strtotime($result['order_date']));
        $data['order_type'] = $result['order_type'];
        $this->load->library('country');
        $this->load->model('Locations_model');
        // load orders model
        $location_address = $this->Locations_model->getAddress($result['location_id']);
        $data['location_name'] = $location_address ? $location_address['location_name'] : '';
        $data['location_address'] = $location_address ? $this->country->addressFormat($location_address) : '';
        $delivery_address = $this->Addresses_model->getAddress($result['customer_id'], $result['address_id']);
        $data['delivery_address'] = $this->country->addressFormat($delivery_address);
        $data['menus'] = array();
        $order_menus = $this->Orders_model->getOrderMenus($result['order_id']);
        $order_menu_options = $this->Orders_model->getOrderMenuOptions($result['order_id']);
        foreach ($order_menus as $order_menu) {
            $option_data = array();
            if (!empty($order_menu_options)) {
                foreach ($order_menu_options as $menu_option) {
                    if ($order_menu['order_menu_id'] === $menu_option['order_menu_id']) {
                        $option_data[] = $menu_option['order_option_name'] . $this->lang->line('text_equals') . $this->currency->format($menu_option['order_option_price']);
                    }
                }
            }
            $data['menus'][] = array('id' => $order_menu['menu_id'], 'name' => $order_menu['name'], 'qty' => $order_menu['quantity'], 'price' => $this->currency->format($order_menu['price']), 'subtotal' => $this->currency->format($order_menu['subtotal']), 'comment' => $order_menu['comment'], 'options' => implode(', ', $option_data));
        }
        $data['totals'] = array();
        $order_totals = $this->Orders_model->getOrderTotals($result['order_id']);
        foreach ($order_totals as $order_total) {
            if ($data['order_type'] !== '1' and $order_total['code'] === 'delivery') {
                continue;
            }
            $data['totals'][] = array('code' => $order_total['code'], 'title' => htmlspecialchars_decode($order_total['title']), 'value' => $this->currency->format($order_total['value']), 'priority' => $order_total['priority']);
        }
        $data['order_total'] = $this->currency->format($result['order_total']);
        $data['total_items'] = $result['total_items'];
        if ($payment = $this->extension->getPayment($result['payment'])) {
            $data['payment'] = !empty($payment['ext_data']['title']) ? $payment['ext_data']['title'] : $payment['title'];
        } else {
            $data['payment'] = $this->lang->line('text_no_payment');
        }
        $this->template->render('account/orders_view', $data);
    }