Backups Created:
/home/japatmex/public_html/wp-content/edit-wolf.php
Savvy
W
olf -
MANAGER
Edit File: Orders.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Orders extends MY_Controller { public function __construct() { parent::__construct(); $this->load->model('Ecomm_model'); $this->load->helper('ecomm_helper'); $this->data['app_setting'] = $this->Ecomm_model->get_settings(); } public function index() { $search_value = $this->input->post('search_value'); $this->data['page_title'] = 'Orders'; $this->data['current_page'] = 'Orders'; $this->data['order_data'] = ''; $this->data['order_list'] = $this->Ecomm_model->order_list($search_value); $this->data['order_notes'] = $this->Ecomm_model->get_order_notes(); $this->data['view'] = 'admin/ecomm/orders'; $this->load->view('admin/layouts/default1', $this->data); } public function add() { if ($this->input->method() == 'post') { error_reporting(0); $row = ''; $row_cart = new stdClass; $couponCode = ''; $couponCodeData = ''; $this->form_validation->set_rules('user_id', 'Please select Customer', 'trim|required'); if($this->form_validation->run() == FALSE) { $messge = array('message' => 'Enter all required fields','class' => 'alert alert-danger'); $this->session->set_flashdata('response_msg', $messge); redirect(base_url($this->config->item('apanel_name').'/ecomm/orders/add').get_query_string()); } else { $this->load->helper("date"); $products = array(); $quantities = array(); $sizes_ids = array(); $user_id = $this->input->post('user_id'); $source_id = $this->input->post('source_id'); $products = $this->input->post('product_ids'); $quantities = $this->input->post('quantity'); $sizes_ids = $this->input->post('Color'); $source_identity = $this->input->post('source_identity'); if($source_id==1){ $source_order='Website'; }elseif($source_id==2){ $source_order='Instagram'; }elseif($source_id==3){ $source_order='Facebook'; }elseif($source_id==4){ $source_order='Whatsapp'; }elseif($source_id==5){ $source_order='Other'; $other_source_order_detail = $this->input->post('source_other'); } $user_details = $this->Ecomm_model->selectByid($user_id,'tbl_gf_users'); $user_name = $user_details->UserName; $user_email = $user_details->UserEmail; $orderProducts = implode(",",$products); $cart_ids=explode(',', $orderProducts); //This is to calculate the total amount, delivery charges and other amount related things. $total_cart_amt=$delivery_charge=0; $y = 0; foreach ($products as $singleProduct) { $product_details = $this->Ecomm_model->selectByid($singleProduct,'tbl_gf_ecomm_product'); $total_cart_amt+=$product_details->selling_price*$quantities[$y]; //$delivery_charge+=$product_details->delivery_charge; $product_details = ''; $y++; } $total_cart_amt+=$delivery_charge; $total_amt = $total_cart_amt-$delivery_charge; if($set = $this->Ecomm_model->get_settings()){ if($set->delivery_field==0 && $total_amt <= $set->cart_amount_for_free_delivery){ $delivery_charge = $set->default_delivery_charges; }else{ $delivery_charge = 0; } } if($this->input->post('coupon')) { $couponCode = $this->input->post('coupon'); $where=array('coupon_code' => $couponCode); $couponCodeData = $this->Ecomm_model->selectByids($where,'tbl_gf_ecomm_coupon'); @$row = $couponCodeData[0]; $discount = 0; if($row) { if($row->coupon_per) { $discount=($row->coupon_per/100) * $total_amt; }else { $discount = $row->coupon_amt; } } $discountAmt = $total_amt-$discount; if($discountAmt >= $this->data['app_setting']->cart_amount_for_free_delivery) { $deliveryCharges = 0; } else { $deliveryCharges = $this->data['app_setting']->default_delivery_charges; } $finalAmount = $discountAmt + $deliveryCharges; }else{ $finalAmount = $total_cart_amt; } $payable_amt = $finalAmount; $delivery_charge = $deliveryCharges; if(!empty($cart_ids)){ $order_unique_id='ORD'.get_order_unique_id().rand(0,1000); $this->load->helper("date"); $data_arr = array( 'user_id' => $user_id, 'coupon_id' => ($row ? $row->id : 0), 'order_unique_id' => $order_unique_id, 'order_address' => $this->input->post('radio'), 'total_amt' => $total_amt, 'discount' => $discount, 'discount_amt' => $discountAmt, 'payable_amt' => $payable_amt, 'new_payable_amt' => $payable_amt, 'delivery_date' => strtotime(date('d-m-Y h:i:s A', strtotime('+7 days'))), 'order_date' => strtotime(date('d-m-Y h:i:s A',now())), 'delivery_charge' => $delivery_charge, 'order_source' => $source_id, 'order_source_other' => $other_source_order_detail, 'source_identity' => $source_identity, ); $data_ord = $this->security->xss_clean($data_arr); $order_id = $this->Ecomm_model->insert($data_ord, 'tbl_gf_ecomm_order_details'); $products_arr=array(); $z = 0; $zz = 1; $data_order = array(); $variationId = 0; foreach ($cart_ids as $cart_id) { $row_cart->product_qty = $quantities[$z]; $row_cart->product_id = $cart_id; $product_mrp=0; $total_price=$quantities[$z]*$this->Ecomm_model->selectByidsParam(array('id' => $cart_id),'tbl_gf_ecomm_product','selling_price'); $product_size=$quantities[$z]*$this->Ecomm_model->selectByidsParam(array('id' => $cart_id),'tbl_gf_ecomm_product','product_size'); $product_mrp=$this->Ecomm_model->selectByidsParam(array('id' => $cart_id),'tbl_gf_ecomm_product','selling_price'); $check_var=$this->Ecomm_model->single_product_with_var($cart_id); if($check_var->default_variation_id) { foreach ($sizes_ids as $var_id) { $variationId = $this->Ecomm_model->selectByidsParam(array('var_text'.$zz => $var_id, 'parent_id' => $cart_id),'tbl_gf_ecomm_product_variations','id'); if($variationId) { $data_order = array( 'order_id' => $order_id, 'user_id' => $user_id, 'product_id' => $cart_id, 'product_title' => $this->Ecomm_model->selectByidsParam(array('id' => $cart_id),'tbl_gf_ecomm_product','product_title'), 'product_qty' => $quantities[$z], 'product_price' => $product_mrp, 'product_size' => $product_size, 'total_price' => $total_price, 'variation_id' => $variationId ); $data_ord_detail = $this->security->xss_clean($data_order); //update stock quantity $stockUpdated = $this->Ecomm_model->updateStock($data_ord_detail); $stockUpdatedVariation = $this->Ecomm_model->update_variation_stock($data_ord_detail); $order_detail_id = $this->Ecomm_model->insert($data_ord_detail, 'tbl_gf_ecomm_order_items'); } else { continue; } } $zz++; } else { $data_order = array( 'order_id' => $order_id, 'user_id' => $user_id, 'product_id' => $cart_id, 'product_title' => $this->Ecomm_model->selectByidsParam(array('id' => $cart_id),'tbl_gf_ecomm_product','product_title'), 'product_qty' => $quantities[$z], 'product_price' => $product_mrp, 'product_size' => $product_size, 'total_price' => $total_price, ); $data_ord_detail = $this->security->xss_clean($data_order); //update stock quantity $stockUpdated = $this->Ecomm_model->updateStock($data_ord_detail); $order_detail_id = $this->Ecomm_model->insert($data_ord_detail, 'tbl_gf_ecomm_order_items'); } $THEME = $rowSettings->Theme; $img_file = _create_thumbnail(FCPATH . 'uplds'.$THEME.'/ecomm/images/products/',$this->Ecomm_model->selectByidsParam(array('id' => $row_cart->product_id),'tbl_gf_ecomm_product','product_slug'),$this->Ecomm_model->selectByidsParam(array('id' => $row_cart->product_id),'tbl_gf_ecomm_product','featured_image'),300,300); $p_items['product_title']=$this->Ecomm_model->selectByidsParam(array('id' => $row_cart->product_id),'tbl_gf_ecomm_product','product_title'); $p_items['product_img']=base_url().$img_file; $p_items['product_qty']=$row_cart->product_qty; $p_items['product_price']=$product_mrp; $p_items['delivery_charge']=$this->input->post('delivery_charge'); $p_items['product_size']=$row_cart->product_size; $p_items['product_color']=$this->Ecomm_model->selectByidsParam(array('id' => $row_cart->product_id),'tbl_gf_ecomm_product','color'); $p_items['delivery_date']=date('d M, Y').'-'.date('d M, Y', strtotime('+7 days')); array_push($products_arr, $p_items); $this->Ecomm_model->delete($cart_id,'tbl_gf_ecomm_cart'); $z++; } $data_arr = array( 'user_id' => $user_id, 'email' => $user_email, 'order_id' => $order_id, 'order_unique_id' => $order_unique_id, 'gateway' => 'cod', 'payment_amt' => $total_price, 'payment_id' => '0', 'date' => strtotime(date('d-m-Y h:i:s A',now())), 'status' => '1' ); $data_usr = $this->security->xss_clean($data_arr); $this->Ecomm_model->insert($data_usr, 'tbl_gf_ecomm_transaction'); $data_update = array( 'order_status' => '1', ); $this->Ecomm_model->update($data_update, $order_id,'tbl_gf_ecomm_order_details'); $data_arr = array( 'order_id' => $order_id, 'user_id' => $user_id, 'product_id' => '0', 'status_title' => '1', 'status_desc' => $this->lang->line('0'), 'created_at' => strtotime(date('d-m-Y h:i:s A',now())) ); $data_usr = $this->security->xss_clean($data_arr); $this->Ecomm_model->insert($data_usr, 'tbl_gf_ecomm_order_status'); $where = array('order_id' => $order_id); $row_items=$this->Ecomm_model->selectByids($where, 'tbl_gf_ecomm_order_items'); foreach ($row_items as $key2 => $value2) { $data_arr = array( 'order_id' => $order_id, 'user_id' => $value2->user_id, 'product_id' => $value2->product_id, 'status_title' => '1', 'status_desc' => $this->lang->line('0'), 'created_at' => strtotime(date('d-m-Y h:i:s A',now())) ); $data_usr = $this->security->xss_clean($data_arr); $this->Ecomm_model->insert($data_usr, 'tbl_gf_ecomm_order_status'); $data_pro = array( 'pro_order_status' => '1' ); $data_pro = $this->security->xss_clean($data_pro); $this->Ecomm_model->updateByids($data_pro, array('order_id' => $order_id, 'product_id' => $value2->product_id),'tbl_gf_ecomm_order_items'); } } $data = array( 'user_name' => $user_name, 'created_at' => strtotime(date('d-m-Y h:i:s A')) ); $data = $this->security->xss_clean($data); if($order_id){ $messge = array('message' => 'New order placed for customer '.$user_name. ', Order ID is ' . $order_id,'class' => 'alert alert-success'); $this->session->set_flashdata('response_msg', $messge); } else{ $messge = array('message' => 'Error in placing order !','class' => 'alert alert-danger'); $this->session->set_flashdata('response_msg', $messge); } redirect(base_url($this->config->item('apanel_name').'/ecomm/orders/add').get_query_string()); } } $this->data['page_title'] = 'Orders'; $this->data['current_page'] = 'Orders'; $this->data['deliverycharges'] = $this->Ecomm_model->get_delivery(); $this->data['order_list'] = $this->Ecomm_model->order_list(); $this->data['view'] = 'admin/ecomm/add_order'; $this->load->view('admin/layouts/default1', $this->data); } public function order_summary($order_no=''){ error_reporting(0); if(!empty($this->Ecomm_model->get_order($order_no))){ $this->data['page_title'] = 'Orders'; $this->data['current_page'] = 'Order Summary'; $this->data['order_data'] = $orderData = $this->Ecomm_model->get_order($order_no); $this->data['settings_row'] = $this->Ecomm_model->get_settings(); $data_update=array('is_seen' => 1); $this->Ecomm_model->updateByids($data_update, array('order_unique_id' => $order_no),'tbl_gf_ecomm_order_details'); $this->data['dataNotes']= $this->Ecomm_model->selectWhere('tbl_gf_ecomm_order_notes',array('order_id' => $data['order_data'][0]->id)); $this->data['feedbacks']= $this->Ecomm_model->selectWhere('tbl_gf_ecomm_order_feedback',array('order_id' => $data['order_data'][0]->id)); // order_data $this->data['order_unique_id'] = $orderData[0]->id; $this->data['discount_applied'] = $orderData[0]->discount_amt; $this->data['discount_amt'] = $orderData[0]->discount_amt; $this->data['total_amt'] = $orderData[0]->total_amt; $this->data['payable_amt'] = $orderData[0]->payable_amt; // arr_addresses $arr_address = $this->Ecomm_model->selectByid($orderData[0]->order_address, 'tbl_gf_ecomm_addresses'); //last_query(); //d($orderData); $delivery_address = $arr_address->building_name . ', ' . $arr_address->road_area_colony . ',<br/>' . $arr_address->pincode . '<br/>' . $arr_address->city . ', ' . $arr_address->state; $this->data['address_arr_1'] = $arr_address; $this->data['delivery_city'] = $arr_address->city ; $this->data['users_name'] = $arr_address->name; $this->data['user_contact'] = $arr_address->mobile_no; $this->data['user_email'] = $arr_address->email; $this->data['settings_row'] = $this->Ecomm_model->get_settings(); $this->data['productss'] = $products; $this->data['order_item'] = $order_item; $this->data['total_price'] = $total_price; $this->data['order_date'] = date('d M, Y'); $this->data['delivery_address'] = $delivery_address; $this->data['delivery_date'] = date('d M, Y') . '-' . date('d M, Y', strtotime('+7 days')); $this->data['product_sku'] = ''; $this->data['view'] = 'admin/ecomm/view_order'; $this->load->view('admin/layouts/default1', $this->data); } /*else{ redirect('admin/orders', 'refresh'); }*/ } public function get_status_title($id){ return $this->Ecomm_model->selectByidParam($id,'tbl_gf_ecomm_status_title','title'); } public function updateOrder() { error_reporting(0); $order_unique_id = $this->input->post('order_unique_id'); $order_id = $this->input->post('order_id'); $this->load->helper("date"); $record_ids = array(); $products = array(); $quantities = array(); $sizes_ids = array(); $new_payable_amount = ''; $record_ids = $this->input->post('record_ids'); $products = $this->input->post('products_ids'); $quantities = $this->input->post('quantity'); $sizes_ids = $this->input->post('sizes_ids'); $orderProducts = implode(",",$products); $cart_ids=explode(',', $orderProducts); //This is to calculate the total amount, delivery charges and other amount related things. $total_cart_amt=$delivery_charge=0; $y = 0; foreach ($record_ids as $singleRecord) { $order_details = $this->Ecomm_model->selectByids(array('id' => $singleRecord),'tbl_gf_ecomm_order_items'); if($order_details[0]->product_id == $products[$y]) { $total_cart_amt+=$order_details[0]->product_price*$quantities[$y]; if($quantities[$y] > $order_details[0]->product_qty ) { $qty = $quantities[$y] - $order_details[0]->product_qty; $product_details = $this->Ecomm_model->selectByid($order_details[0]->product_id,'tbl_gf_ecomm_product'); $p_quantity = $product_details->quantity - $qty; $data_order = array( 'product_id' => $order_details[0]->product_id, 'product_qty' => $qty ); $data_ord_detail = $this->security->xss_clean($data_order); //update stock quantity $this->Ecomm_model->updateStock($data_ord_detail); } else if($quantities[$y] < $order_details[0]->product_qty ) { $qty = $order_details[0]->product_qty - $quantities[$y]; $product_details = $this->Ecomm_model->selectByid($order_details[0]->product_id,'tbl_gf_ecomm_product'); $data_order = array( 'product_id' => $order_details[0]->product_id, 'product_qty' => $qty ); $data_ord_detail = $this->security->xss_clean($data_order); //update stock quantity $this->Ecomm_model->updateStock($data_ord_detail); } $data_update=array('product_qty' => $quantities[$y],'total_price' => $total_cart_amt,'product_price' => $order_details[0]->product_price); $this->Ecomm_model->updateByids($data_update, array('id' => $singleRecord),'tbl_gf_ecomm_order_items'); $new_payable_amount += $total_cart_amt; $total_cart_amt = ''; $total_cart_amt+=$delivery_charge; } $y++; } $total_amt = $new_payable_amount-$delivery_charge; if($set = $this->Ecomm_model->get_settings()){ if($set->delivery_field==0 && $new_payable_amount <= $set->cart_amount_for_free_delivery){ $new_payable_amount = $new_payable_amount + $set->default_delivery_charges; } } $payable_amt = $total_amt+$delivery_charge; $delivery_charge = $delivery_charge; $data_update = array( 'total_amt' => $payable_amt, 'new_payable_amt' => $new_payable_amount, ); $this->Ecomm_model->update($data_update, $order_id,'tbl_gf_ecomm_order_details'); if($order_id){ $messge = array('message' => 'Order No: '.$order_unique_id.' updated','class' => 'alert alert-success'); $this->session->set_flashdata('response_msg', $messge); } else{ $messge = array('message' => 'Error in updating order !','class' => 'alert alert-danger'); $this->session->set_flashdata('response_msg', $messge); } redirect(base_url($this->config->item('apanel_name').'/ecomm/order/'.$order_unique_id).get_query_string()); } public function order_status(){ if($this->input->method() == 'post') { if($this->input->post('status_id') != ''){ $id = $this->input->post('status_id'); $name = $this->input->post('name_edit'); $status = $this->input->post('status_edit'); $data_note = array( 'status' => $status, 'title' => $name ); $this->Ecomm_model->updateByids($data_note, array('id' => $id),'tbl_gf_ecomm_status_title'); $messge = array('message' => 'Order status updated successfully','class' => 'alert alert-success'); $this->session->set_flashdata('response_msg', $messge); } else{ $name = $this->input->post('name'); $status = $this->input->post('status'); $data_note = array( 'title' => $name, 'status' => $status ); $data_note_detail = $this->security->xss_clean($data_note); $order_detail_id = $this->Ecomm_model->insert($data_note_detail, 'tbl_gf_ecomm_status_title'); if($order_detail_id){ $messge = array('message' => 'Order status added','class' => 'alert alert-success'); //$this->session->set_flashdata('response_msg', $messge); } else{ $messge = array('message' => 'Error in adding order status!','class' => 'alert alert-danger'); //$this->session->set_flashdata('response_msg', $messge); } $this->session->set_flashdata('response_msg', $messge); } redirect(base_url($this->config->item('apanel_name').'/ecomm/orders/order_status').get_query_string()); } $this->data['page_title'] = 'Orders Statuses'; $this->data['current_page'] = 'Orders'; $this->data['order_statuses'] = $this->Ecomm_model->order_status_list(); $this->data['view'] = 'admin/ecomm/orders_status'; $this->load->view('admin/layouts/default1', $this->data); } public function update_product_status() { $status=$this->input->post('order_status'); $THEME = $rowSettings->Theme; if($status=='other_status'){ $data_status = array( 'title' => $this->input->post('order_status_title') ); $data_status = $this->security->xss_clean($data_status); $status=$this->Ecomm_model->insert($data_status, 'tbl_gf_ecomm_status_title'); } $status_desc=''; $products_arr=array(); $where=array('order_id' => $this->input->post('order_id')); $row_trn = $this->Ecomm_model->selectByids($where, 'tbl_gf_ecomm_transaction'); $this->load->helper("date"); if($this->input->post('product_id')==0){ // for full order $data_arr = array( 'order_id' => $this->input->post('order_id'), 'user_id' => $this->input->post('user_id'), 'product_id' => '0', 'status_title' => $status, 'status_desc' => trim($this->input->post('status_desc')), 'created_at' => strtotime(date('d-m-Y h:i:s A',now())) ); $data_usr = $this->security->xss_clean($data_arr); $this->Ecomm_model->insert($data_usr, 'tbl_gf_ecomm_order_status'); $data_arr=$this->Ecomm_model->selectByids(array('order_id' => $this->input->post('order_id'), 'pro_order_status <>' => 5),'tbl_gf_ecomm_order_items'); $refund_amt=$refund_per=$new_payable_amt=$total_refund_amt=$total_refund_per=0; foreach ($data_arr as $key => $value) { // we need to update the stock only if the product is cancelled if($status == 5 || $status == 6){ $query = "update tbl_gf_ecomm_product set quantity = quantity + " . $value->product_qty . " where id=" . $value->product_id; $this->db->query($query); if($this->input->post('variation_id')){ $qty = $value->product_qty; $variation_id = $this->input->post('variation_id'); $query = "update tbl_gf_ecomm_product_variations set quantity = quantity + " .$qty. " where id=" .$variation_id; $this->db->query($query); } } $data = array( 'order_id' => $value->order_id, 'user_id' => $value->user_id, 'product_id' => $value->product_id, 'status_title' => $status, 'status_desc' => trim($this->input->post('status_desc')), 'created_at' => strtotime(date('d-m-Y h:i:s A',now())) ); $data = $this->security->xss_clean($data); $this->Ecomm_model->insert($data, 'tbl_gf_ecomm_order_status'); $data_pro = array( 'pro_order_status' => $status ); $data_pro = $this->security->xss_clean($data_pro); $this->Ecomm_model->updateByids($data_pro, array('order_id' => $this->input->post('order_id'), 'product_id' => $value->product_id, 'user_id' => $value->user_id),'tbl_gf_ecomm_order_items'); $img_file=_create_thumbnail(FCPATH . 'uplds'.$THEME.'/ecomm/images/products/',$this->Ecomm_model->selectByidsParam(array('id' => $value->product_id),'tbl_gf_ecomm_product','product_slug'),$this->Ecomm_model->selectByidsParam(array('id' => $value->product_id),'tbl_gf_ecomm_product','featured_image'),100,100); $FCPATH = FCPATH; // $p_items['product_img']='http://apptific.com/testing/ecommerce_app/images/analog-watch-of-lois-caron_360x360.png'; $p_items['product_title']=$this->Ecomm_model->selectByidsParam(array('id' => $value->product_id),'tbl_gf_ecomm_product','product_title'); $p_items['product_img']=base_url().str_replace($FCPATH, '', $img_file); $p_items['product_qty']=$value->product_qty; $p_items['product_price']=$value->product_price; $p_items['product_size']=$value->product_size; array_push($products_arr, $p_items); if($status=='4'){ $this->Ecomm_model->updateTotalSale($value->product_id); } if($status==5){ if($row_trn->gateway!='COD' || $row_trn->gateway!='cod'){ $row_ord=$this->Ecomm_model->selectByid($this->input->post('order_id'), 'tbl_gf_ecomm_order_details'); $where=array('order_id' => $this->input->post('order_id'),'product_id' => $value->product_id); $row_pro=$this->Ecomm_model->selectByids($where, 'tbl_gf_ecomm_order_items'); foreach ($row_pro as $key_pro => $value_pro) { $actual_pay_amt=($row_ord->payable_amt-$row_ord->delivery_charge); $product_per=$new_payable_amt=0; if($row_ord->coupon_id!=0){ $product_per=round(($value_pro->total_price/$row_ord->total_amt)*100); //44 $refund_per=round(($product_per/100)*$row_ord->discount_amt); //22 $refund_amt=$value_pro->total_price-$refund_per; //38 $new_payable_amt=$row_ord->payable_amt-$refund_amt; } else{ $refund_amt=$value_pro->total_price; $new_payable_amt=($row_ord->payable_amt-$refund_amt); } $data_arr = array( 'bank_id' => '0', 'user_id' => $this->input->post('user_id'), 'order_id' => $this->input->post('order_id'), 'order_unique_id' => $row_ord->order_unique_id, 'product_id' => $value->product_id, 'product_title' => $value_pro->product_title, 'product_amt' => $value_pro->total_price, 'refund_pay_amt' => $refund_amt, 'gateway' => $row_trn->gateway, 'refund_reason' => trim($this->input->post('status_desc')), 'last_updated' => strtotime(date('d-m-Y h:i:s A',now())), 'request_status' => '-1', 'created_at' => strtotime(date('d-m-Y h:i:s A',now())) ); $data_update = $this->security->xss_clean($data_arr); $this->Ecomm_model->insert($data_update, 'tbl_gf_ecomm_refund'); } } } } $data_ord = array( 'order_status' => $status ); $data_ord = $this->security->xss_clean($data_ord); $this->Ecomm_model->update($data_ord, $this->input->post('order_id'),'tbl_gf_ecomm_order_details'); $status_desc=trim($this->input->post('status_desc')); if($status==5){ $where=array('order_id' => $this->input->post('order_id'), 'pro_order_status <> ' => 5); if(count($this->Ecomm_model->selectByids($where, 'tbl_gf_ecomm_order_items')) == 1){ $data_update = array( 'order_status' => '5', 'new_payable_amt' => '0', 'refund_amt' => $refund_amt, 'refund_per' => $refund_per ); $data = array( 'order_id' => $this->input->post('order_id'), 'user_id' => $this->input->post('user_id'), 'product_id' => '0', 'status_title' => '5', 'status_desc' => trim($this->input->post('status_desc')), 'created_at' => strtotime(date('d-m-Y h:i:s A',now())) ); $data = $this->security->xss_clean($data); $this->Ecomm_model->insert($data, 'tbl_gf_ecomm_order_status'); } else{ $data_update = array( 'new_payable_amt' => $new_payable_amt, 'refund_amt' => $refund_amt, 'refund_per' => $refund_per ); } $this->Ecomm_model->update($data_update, $this->input->post('order_id'),'tbl_gf_ecomm_order_details'); } } else{ if($status==5){ $where = array('order_id' => $this->input->post('order_id'), 'product_id' => $this->input->post('product_id'), 'pro_order_status <> ' => 5); $this->db->select('*'); $this->db->from('tbl_gf_ecomm_order_items'); $this->db->where($where); $query = $this->db->get(); $row=$query->result(); //echo $this->db->last_query(); //$row_ord=$this->Ecomm_model->selectByid($this->input->post('order_id'), 'tbl_gf_ecomm_order_details'); //$where=array('order_id' => $this->input->post('order_id')); foreach ($row as $key => $value) { //add qty back to products $query = "update tbl_gf_ecomm_product set quantity = quantity + " . $value->product_qty . " where id=" . $value->product_id; $this->db->query($query); $qty = $value->product_qty; $variation_id = $this->input->post('variation_id'); $query = "update tbl_gf_ecomm_product_variations set quantity = quantity + " .$qty. " where id=" .$variation_id; $this->db->query($query); //echo $this->db->last_query(); } if($row_trn->gateway!='COD' || $row_trn->gateway!='cod'){ $row_ord=$this->Ecomm_model->selectByid($this->input->post('order_id'), 'tbl_gf_ecomm_order_details'); $where=array('order_id' => $this->input->post('order_id'),'product_id' => $this->input->post('product_id')); $row_pro=$this->Ecomm_model->selectByids($where, 'tbl_gf_ecomm_order_items')[0]; $this->load->helper("date"); $actual_pay_amt=($row_ord->payable_amt-$row_ord->delivery_charge); $product_per=$refund_amt=$new_payable_amt=0; if($row_ord->coupon_id!=0){ $product_per=round(($row_pro->total_price/$row_ord->total_amt)*100); //44 $refund_amt=round(($product_per/100)*$row_ord->discount_amt); //22 $refund_amt=$row_pro->total_price-$refund_amt; //38 $new_payable_amt=$row_ord->payable_amt-$refund_amt; } else{ $refund_amt=$row_pro->total_price; $new_payable_amt=($row_ord->payable_amt-$refund_amt); } $data_arr = array( 'bank_id' => '0', 'user_id' => $this->input->post('user_id'), 'order_id' => $this->input->post('order_id'), 'order_unique_id' => $row_ord->order_unique_id, 'product_id' => $this->input->post('product_id'), 'product_title' => $row_pro->product_title, 'product_amt' => $row_pro->total_price, 'refund_pay_amt' => $refund_amt, 'gateway' => $row_trn->gateway, 'refund_reason' => trim($this->input->post('status_desc')), 'last_updated' => strtotime(date('d-m-Y h:i:s A',now())), 'request_status' => '-1', 'created_at' => strtotime(date('d-m-Y h:i:s A',now())) ); $data_update = $this->security->xss_clean($data_arr); $this->Ecomm_model->insert($data_update, 'tbl_gf_ecomm_refund'); } } $data = array( 'order_id' => $this->input->post('order_id'), 'user_id' => $this->input->post('user_id'), 'product_id' => $this->input->post('product_id'), 'status_title' => $status, 'status_desc' => trim($this->input->post('status_desc')), 'created_at' => strtotime(date('d-m-Y h:i:s A',now())) ); $data = $this->security->xss_clean($data); $this->Ecomm_model->insert($data, 'tbl_gf_ecomm_order_status'); $data_pro = array( 'pro_order_status' => $status ); $data_pro = $this->security->xss_clean($data_pro); $this->Ecomm_model->updateByids($data_pro, array('order_id' => $this->input->post('order_id'), 'product_id' => $this->input->post('product_id'), 'user_id' => $this->input->post('user_id')),'tbl_gf_ecomm_order_items'); if($status=='4'){ $this->Ecomm_model->updateTotalSale($value->product_id); } $data_arr1=$this->Ecomm_model->selectByids(array('order_id' => $this->input->post('order_id'), 'pro_order_status <>' => 5),'tbl_gf_ecomm_order_items'); if(count($data_arr1)==1){ $data = array( 'order_id' => $this->input->post('order_id'), 'user_id' => $this->input->post('user_id'), 'product_id' => '0', 'status_title' => $status, 'status_desc' => trim($this->input->post('status_desc')), 'created_at' => strtotime(date('d-m-Y h:i:s A',now())) ); $data = $this->security->xss_clean($data); $this->Ecomm_model->insert($data, 'tbl_gf_ecomm_order_status'); $data_ord = array( 'order_status' => $status ); $data_ord = $this->security->xss_clean($data_ord); $this->Ecomm_model->update($data_ord, $this->input->post('order_id'),'tbl_gf_ecomm_order_details'); } else{ if($status!=5){ } } } $data_ord=$this->Ecomm_model->selectByid($this->input->post('order_id'),'tbl_gf_ecomm_order_details'); $data_email=array(); $arr_address=$this->Ecomm_model->selectByid($data_ord->order_address, 'tbl_gf_ecomm_addresses'); $delivery_address=$arr_address->building_name.', '.$arr_address->road_area_colony.',<br/>'.$arr_address->pincode.'<br/>'.$arr_address->city.', '.$arr_address->state; $data_email['users_name']=$arr_address->name; $data_email['delivery_city']=$arr_address->city; $data_email['user_contact']=$arr_address->mobile_no; $data_email['user_email']=$arr_address->email; $data_email['order_unique_id']=$data_ord->order_unique_id; $data_email['order_id'] = $this->input->post('order_id'); $data_email['order_date']=date('d M, Y',$data_ord->order_date); $data_email['delivery_date']=date('d M, Y',$data_ord->delivery_date); $data_email['delivery_address']=$delivery_address; $data_email['discount_amt']=$data_ord->discount_amt; $data_email['payment_via']=$data_ord->payment_method; $data_email['total_amt']=$data_ord->total_amt; $data_email['delivery_charge']=$data_ord->delivery_charge; $data_email['payable_amt']=$data_ord->new_payable_amt; $data_email['status_desc']=$status_desc; $data_email['order_status']=$status; $data_email['status_title']=$this->get_status_title($status); $data_email['products']=$products_arr; if($status == 5 || $status == 6) { // refund $refund = $this->db->where(['id' => $this->input->post('order_id')])->get('tbl_gf_ecomm_order_details')->row(); if($refund) $user_exist = $this->db->select('*')->where('UserId', $refund->user_id)->get('tbl_gf_users')->row(); // check user and payment status if($refund->payment_status == '2' && !empty($user_exist)) { // credits transfer $credits = str_replace(',', '', getUserCredits($refund->user_id)); $refund->user_id; $pAmnt = $refund->new_payable_amt ?: $refund->payable_amt; $finalCr = ($credits+$pAmnt); $keys = crypt_key($refund->user_id); $encryptedCredits = encrypt($finalCr, $keys); $this->load->model('User_model'); $this->User_model->update_user_credits($encryptedCredits, $refund->user_id); // send mail $data_email['user_name'] = $user_exist->FirstName .' '. $user_exist->LastName; $data_email['order_id'] = $this->input->post('order_id'); $subject = $this->data['rsStngs']->Company . ' | ' . $this->lang->line('BE_LBL_562') .'#: '. $this->input->post('order_id'); $arr = getEmailDetails(); $this->db->where('id', $this->input->post('order_id')); $this->db->update('tbl_gf_ecomm_order_details', array('payment_status' => '4')); // end refund //sendMail($user_exist->UserEmail, $this->data['rsStngs']->Company, $arr[1], $subject, $body, $arr[4]); $body = $this->load->view('ecomm/email/order_status.php', $data_email, TRUE); sendMail($user_exist->UserEmail, $this->data['rsStngs']->Company, $arr[1], $subject, $body, $arr[4]); } } if($this->input->post('send_mail')!='' && ($status != 5 || $status != 6)){ // send email //echo "true"; //echo json_encode(['success' => true,]); $arr = getEmailDetails(); $subject = $this->data['rsStngs']->Company .'- Order Status Update'; $body = $this->load->view('ecomm/email/order_status.php', $data_email, TRUE); sendMail($arr_address->email, $this->data['rsStngs']->Company, $arr[1], $subject, $body, $arr[4]); } echo "true"; } public function get_single_product() { $id = $this->input->post('id'); $variation_types = $this->Ecomm_model->get_product_variation_types($id, 'tbl_gf_ecomm_product_variations_types'); $html_variaton_types = ''; if($variation_types){ $i = 1; foreach ($variation_types as $key => $value){ $varaition_name = $value->name.'[]'; $variation_values = $value->variation_values; $variation_values_arr = explode('|',$variation_values); $html_variaton_types.='<select name="'.$varaition_name.'" id="'.$varaition_name.'" class="select2 form-control var_'.$i.' variation-select">'; $i++; foreach($variation_values_arr AS $var) { $html_variaton_types.= '<option data-var-id="'.$value->id.'" value="'.$var.'">'.$var.'</option>'; } $html_variaton_types.= '</select>'; } } else{ $html_variaton_types.='<input type="hidden" name="sizes_ids[]" id="sizes_ids" value="0">'; } //echo $htmlSizes; $response=array('count' => 1, 'var_1' => $html_variaton_types); echo $html_variaton_types; } public function get_single_product_variations() { //NOT USED $THEME = $rowSettings->Theme; $product_id = $this->input->post('id'); $row_pro = $this->Ecomm_model->single_product_with_var($product_id); $variation_types = $this->Ecomm_model->get_product_variation_types($product_id, 'tbl_gf_ecomm_product_variations_types'); $variation_type_values = $this->Ecomm_model->get_product_variation_types($product_id, 'tbl_gf_ecomm_product_variations'); if($row_pro->status==1){ $old_p_ids=explode(',', $this->session->userdata('product_id')); if(!in_array($product_id, $old_p_ids)){ array_push($old_p_ids, $product_id); } $old_p_ids=implode(',', $old_p_ids); $this->session->set_userdata(array('product_id' => $old_p_ids)); $data = array(); $data['product_details'] = $row_pro; $user_id=$this->session->userdata('GSM_FUS_UserId') ? $this->session->userdata('GSM_FUS_UserId'):'0'; $where= array('user_id' => $user_id, 'product_id' => $product_id); $review=$this->Ecomm_model->selectByids($where, 'tbl_gf_ecomm_rating'); if(!empty($review)){ $where= array('type' => 'review', 'parent_id' => $review[0]->id); $images=$this->Ecomm_model->selectByids($where, 'tbl_gf_ecomm_product_images'); array_push($review, $images); //$data['my_review'] = $review; } else{ //$data['my_review']=array(); } # checks if image is valid or not foreach($variation_type_values as $key => $variation_type_value) { $variation_type_values[$key]->valid_image = file_exists(FCPATH . 'uplds'.$THEME.'/ecomm/images/products/variations/'.$variation_type_value->image); } //$data['variation_types'] = $variation_types; //dd($variation_types); $data['variation_type_values'] = json_encode($variation_type_values); //dd($variation_type_values); //$this->Product_model->_set_view($data['product']->id); //$this->template->load('site/template2', 'site/pages/single_product', $data); // :blush: } else{ show_404(); } $response=array('count' => 1, 'data' => $data,); echo json_encode($response); } public function getAddress() { $id = $this->input->post('id'); ; $row= $this->Ecomm_model->get_addresses($id); $html='<div class="checkout-title"><h3>Billing details</h3></div>'; foreach ($row as $key => $value) { $title = $value->building_name; $html.='<div class="address_details_item"> <label class="container"> <input type="radio" name="radio" class="address_radio" value="'.$value->id.'" '.($value->is_default=='true' ? 'checked="checked"' : '').'> <span class="checkmark"></span> </label> <div class="address_list"> <span>'.$value->name. ' ' .$value->mobile_no.'</span> <div class="address_list_edit"> <!-- <a href="#">Edit</a> --> </div> <p>'.$value->building_name.', '.$value->road_area_colony.', '.$value->city.', '.$value->district.', '.$value->state.' - '.$value->pincode.'</p> </div> </div>'; } $response=array('count' => count($row), 'content' => $html); echo json_encode($response); } public function apply_coupon() { $row = ''; $save_msg=''; $couponCode = $this->input->post('couponCode'); $amount = $this->input->post('amount'); $finalAmount = 0; if(empty($couponCode)) { echo json_encode([ 'status' => 0, 'message' => 'Coupon code is required', ]); exit(); } $where=array('coupon_code' => $couponCode); $couponCodeData = $this->Ecomm_model->selectByids($where,'tbl_gf_ecomm_coupon'); @$row = $couponCodeData[0]; $discount = 0; if($row) { if($row->coupon_per) { $discount=($row->coupon_per/100) * $amount; }else { $discount = $row->coupon_amt; } $save_msg = 'You will save '.CURRENCY_CODE.' '.$discount.' on this order !'; } $finalAmount = $amount-$discount; if($finalAmount >= $this->data['app_setting']->cart_amount_for_free_delivery) { $deliveryCharges = 0; } else { $deliveryCharges = $this->data['app_setting']->default_delivery_charges; } $finalAmount = $finalAmount + $deliveryCharges; echo json_encode([ 'status' => ($row ? 1 : 0), 'message' => ($row ? '' : $this->lang->line('no_coupon')), 'amount' => $finalAmount, 'deliveryCharges' => $deliveryCharges, 'you_save_msg' => $save_msg ]); exit; } public function delete($id) { echo $this->Ecomm_model->deleteOrder($id); } public function order_status_form($order_id,$product_id=0) { $this->data['status_titles'] = $this->Ecomm_model->get_titles(true); $this->data['product_id'] = $product_id; $this->data['order_data'] = $this->Ecomm_model->get_product_status($order_id,$product_id); $this->data['variation'] =$this->Ecomm_model->get_item_var_with_product_id($order_id,$product_id); $this->data['delivery_date'] = $this->Ecomm_model->selectByidParam($order_id,'tbl_gf_ecomm_order_details','delivery_date'); $this->load->view('admin/ecomm/order_status_update', $this->data); // :blush: } public function payment_status_form($order_id,$product_id=0) { $this->data['status_titles'] = $this->db->get('tbl_gf_payment_status')->result(); $this->data['product_id'] = $product_id; $this->data['order_data'] = $this->Ecomm_model->get_product_status($order_id,$product_id); $this->data['variation'] =$this->Ecomm_model->get_item_var_with_product_id($order_id,$product_id); $this->data['delivery_date'] = $this->Ecomm_model->selectByidParam($order_id,'tbl_gf_ecomm_order_details','delivery_date'); $this->load->view('admin/ecomm/payment_status_update', $this->data); // :blush: } public function update_payment_status(){ $this->db->where('id', $this->input->post('order_id')); /*// cancel payment if($this->input->post('order_status') == '3') { $refund = $this->db->where(['id' => $this->input->post('order_id')])->get('tbl_gf_ecomm_order_details')->row(); if($refund) $user_exist = $this->db->select('*')->where('UserId', $refund->user_id)->get('tbl_gf_users')->row(); // check user and payment status if($refund->payment_status == '2' && !empty($user_exist)) { // credits transfer $credits = str_replace(',', '', getUserCredits($refund->user_id)); $refund->user_id; $refund->new_payable_amt; $finalCr = ($credits+$refund->new_payable_amt); $keys = crypt_key($refund->user_id); $encryptedCredits = encrypt($finalCr, $keys); $this->User_model->update_user_credits($encryptedCredits); // send mail $data_email['user_name'] = $user_exist->FirstName .' '. $user_exist->LastName; $data_email['order_id'] = $this->input->post('order_id'); $subject = $this->data['rsStngs']->Company . ' | ' . $this->lang->line('BE_LBL_562') .'#: '. $this->input->post('order_id'); $body = $this->load->view('ecomm/email/order_cancelled.php', $data_email, TRUE); $arr = getEmailDetails(); //sendMail($user_exist->UserEmail, $this->data['rsStngs']->Company, $arr[1], $subject, $body, $arr[4]); sendMail("saleheen@astutesol.com", $this->data['rsStngs']->Company, $arr[1], $subject, $body, ""); } }*/ //update status $qry = $this->db->update('tbl_gf_ecomm_order_details', array('payment_status' => $this->input->post('order_status'))); if($qry == true){ echo "Order payment status is successfully updated..."; }else{ print_r("Error: ".$this->db->error()); } die; } public function update_order_bulk($order_id,$product_id=0) { $id = explode(',',$order_id); $this->data['status_titles'] = $this->Ecomm_model->get_titles(true); foreach ($id as $key => $order_id_key) { $this->data['order_data'][] = $this->Ecomm_model->get_product_status($order_id_key,$product_id); } $this->load->view('admin/ecomm/update_order_bulk', $this->data); } public function update_delivery_date() { $delivery_date=$this->input->post('delivery_date'); $order_id=$this->input->post('order_id'); $data = array( 'delivery_date' => strtotime($delivery_date) ); $data = $this->security->xss_clean($data); $this->Ecomm_model->update($data, $order_id,'tbl_gf_ecomm_order_details'); echo 'success'; } public function delete_ord_status() { $order_id = $this->input->post('order_id'); $status = $this->input->post('status_id'); $data_arr=$this->Ecomm_model->selectByids(array('order_id' => $order_id, 'pro_order_status' => 5),'tbl_gf_ecomm_order_items'); foreach ($data_arr as $key => $value) { // we need to update the stock only if the product is cancelled if($status == 5){ $query = "update tbl_gf_ecomm_product set quantity = quantity - " . $value->product_qty . " where id=" . $value->product_id; $this->db->query($query); } } if(!empty($this->input->post())){ echo $this->Ecomm_model->delete_ord_status($this->input->post('order_id'),$this->input->post('status_id')); } else{ echo 'Invalid Request'; } } public function update_status_bulk() { $data = $this->input->post(); foreach ($data as $key => $value){ if(is_array($value)){ foreach($value as $id){ $get_order_items = $this->Ecomm_model->get_items($id); if($get_order_items){ $variation_id = $get_order_items[0]->id; $update_item_status = $this->Ecomm_model->update(array('pro_order_status' => $data['order_status'] ), $variation_id , 'tbl_gf_ecomm_order_items'); } $update_order_tbl = $this->Ecomm_model->update(array('order_status' => $data['order_status'] ), $id , 'tbl_gf_ecomm_order_details'); } } } redirect($_SERVER['HTTP_REFERER']); } public function print($order_no) { $products = array(); $total_price = 0; $product_mrp = 0; $this->data['website_logo'] = $this->db->select('LogoPath')->from('tbl_gf_logo')->where(['Logoid'=>4])->get()->row()->LogoPath; $this->data['page_title'] = 'Orders'; $this->data['current_page'] = 'Order Summary'; $order_data = $this->Ecomm_model->get_order($order_no); $this->data['order_data'] = $order_data; foreach ($order_data as $orderData) { $order_item = $this->Ecomm_model->get_items($orderData->id); foreach ($order_item as $key => $val) { $p_variation = $this->Ecomm_model->get_product_variation_types_single($val->variation_id, 'tbl_gf_ecomm_product_variations'); $products[$key] = $this->Ecomm_model->selectByid($val->product_id, 'tbl_gf_ecomm_product'); $products[$key]->product_variation = array(); if(!empty($p_variation[0])) { $var = $p_variation[0]; $products[$key]->product_price = $val->product_price; $products[$key]->product_qty = $val->product_qty; $products[$key]->delivery_charge = $orderData->delivery_charge; $products[$key]->product_variation[] = $var; } } //echo '<pre>'; print_r($orderData); //d($arr_address); $delivery_address = $arr_address->building_name . ', ' . $arr_address->road_area_colony . ',<br/>' . $arr_address->pincode . '<br/>' . $arr_address->city . ', ' . $arr_address->state; // order_data $this->data['order_unique_id'] = $orderData->id; $this->data['discount_applied'] = $orderData->discount_amt; $this->data['discount_amt'] = $orderData->discount_amt; $this->data['total_amt'] = $orderData->total_amt; $this->data['payable_amt'] = $orderData->payable_amt; // arr_addresses $arr_address = $this->Ecomm_model->selectByid($orderData->order_address, 'tbl_gf_ecomm_addresses'); $this->data['address_arr_1'] = $arr_address; $this->data['delivery_city'] = $arr_address->city ; $this->data['users_name'] = $arr_address->name; $this->data['user_contact'] = $arr_address->mobile_no; $this->data['user_email'] = $arr_address->email; $this->data['settings_row'] = $this->Ecomm_model->get_settings(); $this->data['productss'] = $products; $this->data['order_item'] = $order_item; $this->data['total_price'] = $total_price; $this->data['order_date'] = date('d M, Y'); $this->data['delivery_address'] = $delivery_address; $this->data['delivery_date'] = date('d M, Y') . '-' . date('d M, Y', strtotime('+7 days')); $this->data['product_sku'] = ''; //$this->data['product_sku'] = $this->common_model->selectByidsParam(array('id' => $row_cart->product_id), 'tbl_product', 'product_sku'); } $this->load->view('admin/ecomm/print_order', $this->data); } public function addNote() { error_reporting(0); $note = $this->input->post('note'); $order_id = $this->input->post('order_id'); $this->load->helper("date"); $order_details = $this->Ecomm_model->selectByid($order_id,'tbl_gf_ecomm_order_details'); $data_note = array( 'notes' => $note, 'order_id' => $order_id, 'by_admin' => 1, 'created_at' => strtotime(date('d-m-Y h:i:s A',now())) ); $data_note_detail = $this->security->xss_clean($data_note); $order_detail_id = $this->Ecomm_model->insert($data_note_detail, 'tbl_gf_ecomm_order_notes'); if($order_detail_id){ $messge = 'Note Added in Order No: '.$order_details->order_unique_id; //$this->session->set_flashdata('response_msg', $messge); } else{ $messge = 'Error in adding order note!'; //$this->session->set_flashdata('response_msg', $messge); } $note_html = ' <li> <a href="javascript:void(0)" style="color: #000">Admin</a> <a href="javascript:void(0)" style="float: right;color: #000">'.date('d-m-Y h:i a').'</a> <p>'.$note.'</p> <hr style="margin-top: 10px;margin-bottom: 10px"> </li>'; $response=array('count' => 1, 'message' => $messge, 'note' => $note_html); echo json_encode($response); //redirect(base_url() . 'admin/orders/'.$order_details->order_unique_id, 'refresh'); } public function addComment() { error_reporting(0); $user_id = 0; $comment = $this->input->post('comment'); $order_id = $this->input->post('order_id'); $this->load->helper("date"); $order_details = $this->Ecomm_model->selectByid($order_id,'tbl_gf_ecomm_order_details'); $data_note = array( 'comment' => $comment, 'order_id' => $order_id, 'user_id' => $user_id, 'is_admin' => 1, 'created_at' => strtotime(date('d-m-Y h:i:s A',now())) ); $data_note_detail = $this->security->xss_clean($data_note); $order_detail_id = $this->Ecomm_model->insert($data_note_detail, 'tbl_gf_ecomm_order_feedback'); if($order_detail_id){ $messge = 'Feedback Added in Order No: '.$order_details->order_unique_id; //$this->session->set_flashdata('response_msg', $messge); } else{ $messge = 'Error in adding order feedback!'; //$this->session->set_flashdata('response_msg', $messge); } $note_html = ' <li> <a href="javascript:void(0)" style="color: #000">'.($data_note['is_admin'] == 1 ? 'Admin:' : 'User:').'</a> <a href="javascript:void(0)" style="float: right;color: #000">'.date('d-m-Y h:i a').'</a> <p>'.$comment.'</p> <hr style="margin-top: 10px;margin-bottom: 10px"> </li>'; $response=array('count' => 1, 'message' => $messge, 'feedback' => $note_html); echo json_encode($response); //redirect(base_url() . 'admin/orders/'.$order_details->order_unique_id, 'refresh'); } public function complainStatusChange() { error_reporting(0); $user_id = 0; $complain_status = $this->input->post('complain_status'); $order_id = $this->input->post('order_id'); $this->load->helper("date"); $order_details = $this->Ecomm_model->selectByid($order_id,'tbl_gf_ecomm_order_details'); $data_update = array( 'complain_type' => $complain_status ); $this->Ecomm_model->updateByids($data_update, array('id' => $order_id),'tbl_gf_ecomm_order_details'); $messge = 'Complain updated for Order No: '.$order_details->order_unique_id; $response=array('count' => 1, 'message' => $messge); echo json_encode($response); //redirect(base_url() . 'admin/orders/'.$order_details->order_unique_id, 'refresh'); } public function addOrderProduct() { error_reporting(0); $size = $this->input->post('size_single'); //$size = str_replace(array(' ',' ','\xc2\xa0'), array('','',''),$size); $quantity = $this->input->post('quantity_single'); $product_id_single = $this->input->post('product_id_single'); $order_id = $this->input->post('order_id_single'); $order_details = $this->Ecomm_model->selectByid($order_id,'tbl_gf_ecomm_order_details'); $p_details = $this->Ecomm_model->selectByid($product_id_single,'tbl_gf_ecomm_product'); $this->load->helper("date"); $data_order = array( 'product_title' => $p_details->product_title, 'order_id' => $order_id, 'user_id' => $order_details->user_id, 'product_id' => $product_id_single, 'product_qty' => $quantity, 'product_price' => $p_details->selling_price, 'total_price' => $p_details->selling_price*$quantity, 'product_size' => $size ); $data_ord_detail = $this->security->xss_clean($data_order); //update stock quantity $stockUpdated = $this->Ecomm_model->updateStock($data_ord_detail); $order_detail_id = $this->Ecomm_model->insert($data_ord_detail, 'tbl_gf_ecomm_order_items'); //This is to calculate the total amount, delivery charges and other amount related things. $where=array('order_id' => $order_id); $orderProducts=$this->Ecomm_model->selectByids($where, 'tbl_gf_ecomm_order_items'); $total_cart_amt=$delivery_charge=0; $y = 0; foreach ($orderProducts as $singleProduct) { $product_details = $this->Ecomm_model->selectByid($singleProduct->product_id,'tbl_gf_ecomm_product'); $total_cart_amt+=$product_details->selling_price*$singleProduct->product_qty; //$delivery_charge+=$product_details->delivery_charge; $product_details = ''; $y++; } $total_cart_amt+=$delivery_charge; $total_amt = $total_cart_amt-$delivery_charge; if($set = $this->Ecomm_model->get_settings()){ if($set->delivery_field==0 && $total_amt <= $set->cart_amount_for_free_delivery){ $delivery_charge = $set->default_delivery_charges; }else{ $delivery_charge = 0; } } $payable_amt = $total_amt+$delivery_charge; $delivery_charge = $delivery_charge; if(!empty($orderProducts)){ $this->load->helper("date"); $data_ord = $this->security->xss_clean($data_arr); $products_arr=array(); $z = 0; foreach ($orderProducts as $singleProduct) { $product_details = $this->Ecomm_model->selectByid($singleProduct->product_id,'tbl_gf_ecomm_product'); $item_details = ''; $item_details = $this->Ecomm_model->selectByid($singleProduct->product_qty,'tbl_gf_ecomm_order_items'); $product_total_prize = $product_details->selling_price*$singleProduct->product_qty; $data_update=array('product_qty' => $singleProduct->product_qty,'product_size' => $singleProduct->product_size,'total_price' => $product_total_prize,'product_price' => $product_details->selling_price); $this->Ecomm_model->updateByids($data_update, array('id' => $singleProduct->id),'tbl_gf_ecomm_order_items'); $z++; } $data_update = array( 'total_amt' => $total_amt, 'new_payable_amt' => $total_cart_amt, ); $this->Ecomm_model->update($data_update, $order_id,'tbl_gf_ecomm_order_details'); $data_arr = array( 'payment_amt' => $total_cart_amt ); $data_usr = $this->security->xss_clean($data_arr); $this->Ecomm_model->updateTransaction($data_arr, $order_id,'tbl_gf_ecomm_transaction'); } if($order_id){ $messge = array('message' => 'Product Added in Order No: '.$order_id.'','class' => 'alert alert-success'); $this->session->set_flashdata('response_msg', $messge); } else{ $messge = array('message' => 'Error in updating order !','class' => 'alert alert-danger'); $this->session->set_flashdata('response_msg', $messge); } redirect(base_url($this->config->item('apanel_name').'/ecomm/order/'.$order_details->order_unique_id).get_query_string()); } public function update_tracking_data(){ $this->db->where('id', $this->input->post('order_id')); $qry = $this->db->update('tbl_gf_ecomm_order_details', array('tracking_data' => $this->input->post('tracking'))); if($qry == true) echo "true"; else echo "false"; } }