public function cancelAction() { $id_order = $_POST['id_order']; $id_store = $_POST['id_store']; $return_array = array(); //print_r($orders); //die(); try { if ($id_order != "") { // get order $orders = Object::getById($id_order); // check order exist if (count($orders) > 0 && $orders->o_className == 'Orders') { // check store which credential to canceling order if ($orders->Stores->o_id == $id_store) { $orders->setPublished(0); $orders->save(); //Set log $base_url = Website_P1GlobalFunction::getBaseUrl(); $url_api = $base_url . '/core/log/set'; $id_activity = Website_P1GlobalFunction::getActivities("agent_cancel_order"); $array_object = json_encode(array("id_order" => $orders->o_id, "isdn" => $orders->Customer->NRIC)); $data = array("user" => $orders->agen->o_id, "activities" => $id_activity, "object" => $array_object); $setLog = json_decode(Website_P1GlobalFunction::CallAPI("post", $url_api, $data)); $return_array['status'] = 'success'; $return_array['message'] = 'success'; $return_array['data'] = $array_object; } else { $return_array['status'] = 'failed'; $return_array['message'] = 'User cannot allow to canceling order'; $return_array['data'] = ''; } } else { $return_array['status'] = 'failed'; $return_array['message'] = 'Order not exsist'; $return_array['data'] = ''; } } else { $return_array['status'] = 'failed'; $return_array['message'] = 'Parameter invalid, id_order required'; $return_array['data'] = ''; } } catch (Exception $ex) { $return_array['status'] = 'failed'; $return_array['message'] = 'Internal service error'; $return_array['data'] = ''; } $return_json = $this->_helper->json($return_array); $this->sendResponse($return_json); }
public function getAgen($username, $password = "", $action = 'error') { $queryCondition; $agen = array(); $action; if (isset($username) and $password != "") { $queryCondition = "username='******' and password='******'"; $activiesName = "agen_create_new"; } else { if ($username != "") { $queryCondition = "username='******'"; if ($action == "logout") { $activiesName = "agen_logout"; } } else { $queryCondition = "invalid"; } } if ($queryCondition != "invalid") { $arrayReturn = array(); $agen; $getAgen = new Object\Agen\Listing(); $getAgen->setCondition($queryCondition); if (count($getAgen) > 0) { foreach ($getAgen as $key) { if ($key->isActive == '1') { //check active or deactive $agen = array("name" => $key->name, "username" => $key->username, "password" => $key->password, "email" => $key->email, "isSaleSmall" => $key->isSaleSmall, "isSaleLarge" => $key->isSaleLarge, "isTelesales" => $key->Istelesales, "isSales" => $key->isSales, "isActive" => $key->isActive, "role" => $key->role->name, "role_o_id" => $key->role->o_id); $getIdActivities = Website_P1GlobalFunction::getActivities($activiesName); //88 agen login $setLog = Website_P1GlobalFunction::setLog($key->o_id, $getIdActivities, $action); //88 agen login $arrayReturn = array("status" => "success", "message" => "{$Action} success", "data" => $agen); } else { $arrayReturn = array("status" => "failed", "message" => "user is deactive", "data" => ""); } } } else { $arrayReturn = array("status" => "failed", "message" => "user not found!", "data" => ""); } } else { $arrayReturn = array("status" => "failed", "message" => "invalid parameter username and password !", "data" => ""); } $json_agen = $this->_helper->json($arrayReturn); Website_P1GlobalFunction::sendResponse($json_agen); }
public function loginAction() { // print_r($_POST);die(); session_start(); $username = $_POST['username']; $password = $_POST['password']; $return_array = array(); $data; if (!empty($username) && !empty($password)) { $customer = new Object\Customer\Listing(); $customer->setCondition("username = ? AND password = ?", array($username, md5($password))); foreach ($customer as $value) { $_SESSION['username'] = $value->username; $_SESSION['name'] = $value->name; $_SESSION['o_id'] = $value->o_id; // $_SESSION['tes'] = "tes"; $data = array("name" => $value->name, "username" => $value->username, "oo_id" => $value->o_id); $return_array['status'] = 'success'; $return_array['message'] = 'Success'; $return_array['data'] = $data; $base_url = Website_P1GlobalFunction::getBaseUrl(); $url_api = $base_url . '/core/log/set'; $id_activity = Website_P1GlobalFunction::getActivities("customer_login"); $array_object = json_encode(array("customer_id" => $value->o_id)); $data = array("user" => $value->o_id, "activities" => $id_activity, "object" => $array_object); $setLog = json_decode(Website_P1GlobalFunction::CallAPI("post", $url_api, $data)); } } else { $return_array['status'] = 'failed'; $return_array['message'] = 'Username or Password is empty'; $return_array['data'] = ''; } $json_customer = $this->_helper->json($return_array); Website_P1GlobalFunction::sendResponse($json_customer); $this->sendResponse($json_customer); }
public function checkoutAction() { $id_customer = $_POST['id_customer']; $return_array = array(); try { // get cart open $carts = new Object\Carts\Listing(); $carts->setCondition("Customer__id = " . $id_customer . " and Status = 'open'"); $carts->setLimit(1); $cart = array(); if ($carts->Count() > 0) { foreach ($carts as $c) { $cart = $c; } // count detail on cart $carts_detail = new Object\CartsDetail\Listing(); $carts_detail->setCondition("Carts__id = " . $cart->o_id); $n_detail = $carts_detail->count(); if ($n_detail > 0) { // get object customer $customer = Object::getById($id_customer); $now = date("Y-m-d,H-i"); $get_time_now = new Pimcore_Date($now); $newOrder = Object\Orders::create(); $newOrder->setKey(\Pimcore\File::getValidFilename('order_' . $id_customer . '_' . $now)); //to get and set ID PARENT FOLDER $id_folder = new Object_List(); $id_folder->setCondition("o_key='orders-management'"); $o_Pid = 0; foreach ($id_folder as $parent) { $oidParent = $parent->getO_id(); } $newOrder->setParentId($oidParent); $newOrder->setCarts($cart); $newOrder->setCustomer($customer); $newOrder->setOrderDate($get_time_now); $newOrder->setPublished(1); $newOrder->save(); //Set log checkout cart $base_url = Website_P1GlobalFunction::getBaseUrl(); $url_api = $base_url . '/core/log/set'; $id_activity = Website_P1GlobalFunction::getActivities("customer_checkout_cart"); $array_object = json_encode(array("id_order" => $newOrder->o_id)); $data = array("user" => $id_customer, "activities" => $id_activity, "object" => $array_object); $setLogCheckout = json_decode(Website_P1GlobalFunction::CallAPI("post", $url_api, $data)); $cart->setstatus("close"); $cart->save(); //Set log close cart $id_activity = Website_P1GlobalFunction::getActivities("customer_close_cart"); $array_object = json_encode(array("id_cart" => $cart->o_id)); $data = array("user" => $id_customer, "activities" => $id_activity, "object" => $array_object); $setLogClose = json_decode(Website_P1GlobalFunction::CallAPI("post", $url_api, $data)); if ($setLogClose->status == "Success" && $setLogCheckout->status == "Success") { $return_data = json_encode(array("id_cart" => $cart->o_id, "id_order" => $newOrder->o_id)); $return_array['status'] = 'success'; $return_array['message'] = 'success'; $return_array['data'] = $return_data; } else { $return_array['status'] = 'Failed'; $return_array['message'] = 'Failed checkout cart'; $return_array['data'] = ''; } } else { $return_array['status'] = 'failed'; $return_array['message'] = 'Cart is empty'; $return_array['data'] = ''; } } else { $return_array['status'] = 'failed'; $return_array['message'] = 'Customer not have cart open'; $return_array['data'] = ''; } } catch (Exception $ex) { $return_array['status'] = 'failed'; $return_array['message'] = 'Internal service error'; $return_array['data'] = ''; } $return_json = $this->_helper->json($return_array); $this->sendResponse($return_json); }