/** * Process customer data if set * @return bool */ private function processCustomer() { // is updated data available if ($this->custdata != null) { // if customer record (id) exists if ($this->jsonobj->custid > 0) { if (WposAdminCustomers::updateCustomerData($this->custdata) === true) { unset($this->jsonobj->custdata); // unset customer data; we don't need to send this back return true; } else { return false; } } else { $id = WposAdminCustomers::addCustomerData($this->custdata); if (is_numeric($id)) { $this->jsonobj->custid = $id; unset($this->jsonobj->custdata); // unset customer data; we don't need to send this back return true; } else { return false; } } } else { // email only customers are not added for now (email only used for e-receipt); maybe an option. return true; } }
/** * Update the current customers details * @param $result * @return mixed */ public function saveCustomerDetails($result) { // Safety check if (!isset($_SESSION['cust_id'])) { $result['error'] = "Customer ID not found in current session"; return $result; } // input validation $jsonval = new JsonValidate($this->data, '{"name":"", "email":"@", "address":"", "suburb":"", "postcode":"", "state":"", "country":""}'); if (($errors = $jsonval->validate()) !== true) { $result['error'] = $errors; return $result; } if (!$this->data->phone && !$this->data->mobile) { $result['error'] = "At least one contact phone number must be specified."; return $result; } // set id $this->data->id = $_SESSION['cust_id']; $dres = WposAdminCustomers::updateCustomerData($this->data); if ($dres === false) { $result['error'] = "Failed to update customer details."; } return $result; }