Orders::edit PHP Method

edit() public method

public edit ( )
    public function edit()
    {
        $order_info = $this->Orders_model->getOrder((int) $this->input->get('id'));
        if ($order_info) {
            $order_id = $order_info['order_id'];
            $data['_action'] = site_url('orders/edit?id=' . $order_id);
        } else {
            $order_id = 0;
            //$data['_action']	= site_url('orders/edit');
            redirect('orders');
        }
        $title = isset($order_info['order_id']) ? $order_info['order_id'] : $this->lang->line('text_new');
        $this->template->setTitle(sprintf($this->lang->line('text_edit_heading'), $title));
        $this->template->setHeading(sprintf($this->lang->line('text_edit_heading'), $title));
        $this->template->setButton($this->lang->line('button_save'), array('class' => 'btn btn-primary', 'onclick' => '$(\'#edit-form\').submit();'));
        $this->template->setButton($this->lang->line('button_save_close'), array('class' => 'btn btn-default', 'onclick' => 'saveClose();'));
        $this->template->setButton($this->lang->line('button_icon_back'), array('class' => 'btn btn-default', 'href' => site_url('orders')));
        if ($this->input->post() and $this->_updateOrder() === TRUE) {
            if ($this->input->post('save_close') === '1') {
                redirect('orders');
            }
            redirect('orders/edit?id=' . $order_id);
        }
        $data['order_id'] = $order_info['order_id'];
        $data['invoice_no'] = !empty($order_info['invoice_no']) ? $order_info['invoice_prefix'] . $order_info['invoice_no'] : '';
        $data['customer_id'] = $order_info['customer_id'];
        $data['customer_edit'] = site_url('customers/edit?id=' . $order_info['customer_id']);
        $data['first_name'] = $order_info['first_name'];
        $data['last_name'] = $order_info['last_name'];
        $data['email'] = $order_info['email'];
        $data['telephone'] = $order_info['telephone'];
        $data['date_added'] = mdate('%d %M %y - %H:%i', strtotime($order_info['date_added']));
        $data['date_modified'] = mdate('%d %M %y', strtotime($order_info['date_modified']));
        $data['order_time'] = mdate('%H:%i', strtotime($order_info['order_time']));
        $data['order_type'] = $order_info['order_type'] === '1' ? $this->lang->line('text_delivery') : $this->lang->line('text_collection');
        $data['status_id'] = $order_info['status_id'];
        $data['status_name'] = $order_info['status_name'];
        $data['assignee_id'] = $order_info['assignee_id'];
        $data['comment'] = $order_info['comment'];
        $data['notify'] = $order_info['notify'];
        $data['ip_address'] = $order_info['ip_address'];
        $data['user_agent'] = $order_info['user_agent'];
        $data['check_order_type'] = $order_info['order_type'];
        $data['paypal_details'] = array();
        if ($payment = $this->extension->getPayment($order_info['payment'])) {
            if ($payment['name'] === 'paypal_express') {
                $this->load->model('paypal_express/Paypal_model');
                $data['paypal_details'] = isset($this->Paypal_model) ? $this->Paypal_model->getPaypalDetails($order_info['order_id'], $order_info['customer_id']) : array();
            }
            $data['payment'] = !empty($payment['ext_data']['title']) ? $payment['ext_data']['title'] : $payment['title'];
        } else {
            $data['payment'] = $this->lang->line('text_no_payment');
        }
        $data['countries'] = array();
        $results = $this->Countries_model->getCountries();
        foreach ($results as $result) {
            $data['countries'][] = array('country_id' => $result['country_id'], 'name' => $result['country_name']);
        }
        $data['staffs'] = array();
        $staffs = $this->Staffs_model->getStaffs();
        foreach ($staffs as $staff) {
            $data['staffs'][] = array('staff_id' => $staff['staff_id'], 'staff_name' => $staff['staff_name']);
        }
        $data['statuses'] = array();
        $statuses = $this->Statuses_model->getStatuses('order');
        foreach ($statuses as $statuses) {
            $data['statuses'][] = array('status_id' => $statuses['status_id'], 'status_name' => $statuses['status_name'], 'notify' => $statuses['notify_customer'], 'status_comment' => nl2br($statuses['status_comment']));
        }
        $data['status_history'] = array();
        $status_history = $this->Statuses_model->getStatusHistories('order', $order_id);
        foreach ($status_history as $history) {
            $data['status_history'][] = array('history_id' => $history['status_history_id'], 'date_time' => mdate('%d %M %y - %H:%i', strtotime($history['date_added'])), 'staff_name' => $history['staff_name'], 'assignee_id' => $history['assignee_id'], 'status_name' => $history['status_name'], 'status_color' => $history['status_color'], 'notify' => $history['notify'], 'comment' => nl2br($history['comment']));
        }
        $this->load->library('country');
        $data['location_name'] = $data['location_address'] = '';
        if (!empty($order_info['location_id'])) {
            $location_address = $this->Locations_model->getAddress($order_info['location_id']);
            if ($location_address) {
                $data['location_name'] = $location_address['location_name'];
                $data['location_address'] = $this->country->addressFormat($location_address);
            }
        }
        $data['customer_address'] = '';
        if (!empty($order_info['customer_id'])) {
            $customer_address = $this->Addresses_model->getAddress($order_info['customer_id'], $order_info['address_id']);
            $data['customer_address'] = $this->country->addressFormat($customer_address);
        } else {
            if (!empty($order_info['address_id'])) {
                $customer_address = $this->Addresses_model->getGuestAddress($order_info['address_id']);
                $data['customer_address'] = $this->country->addressFormat($customer_address);
            }
        }
        $data['cart_items'] = array();
        $cart_items = $this->Orders_model->getOrderMenus($order_info['order_id']);
        $menu_options = $this->Orders_model->getOrderMenuOptions($order_info['order_id']);
        foreach ($cart_items as $cart_item) {
            $option_data = array();
            if (!empty($menu_options)) {
                foreach ($menu_options as $menu_option) {
                    if ($cart_item['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['cart_items'][] = array('id' => $cart_item['menu_id'], 'name' => $cart_item['name'], 'qty' => $cart_item['quantity'], 'price' => $this->currency->format($cart_item['price']), 'subtotal' => $this->currency->format($cart_item['subtotal']), 'comment' => $cart_item['comment'], 'options' => implode('<br /> ', $option_data));
        }
        $data['totals'] = array();
        $order_totals = $this->Orders_model->getOrderTotals($order_info['order_id']);
        foreach ($order_totals as $total) {
            if ($order_info['order_type'] === '2' and $total['code'] == 'delivery') {
                continue;
            }
            $data['totals'][] = array('code' => $total['code'], 'title' => htmlspecialchars_decode($total['title']), 'value' => $this->currency->format($total['value']), 'priority' => $total['priority']);
        }
        $data['order_total'] = $this->currency->format($order_info['order_total']);
        $data['total_items'] = $order_info['total_items'];
        $this->template->render('orders_edit', $data);
    }

Usage Example

 public function actionEdit($id)
 {
     $model = new Orders();
     $order_id = Yii::app()->request->getPost('order_id');
     $price = Yii::app()->request->getPost('price');
     $description = Yii::app()->request->getPost('description');
     $available = Yii::app()->request->getPost('available');
     $data = array('description' => $description, 'order_id' => $order_id, 'price' => $price, 'description' => $description, 'available' => $available);
     if (Yii::app()->request->isPostRequest) {
         $model->edit($data, $id);
     }
     $editOrders = $model->selectFromId($id);
     $this->render('edit', array('editOrders' => $editOrders));
 }