PageRenderTime 50ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 1ms

/admin/model/sale/customer.php

https://bitbucket.org/monobasic/shop.volero.ch
PHP | 504 lines | 385 code | 119 blank | 0 comment | 60 complexity | b46a1c1ecde2a6ff34383ead727e9ea4 MD5 | raw file
  1. <?php
  2. class ModelSaleCustomer extends Model {
  3. public function addCustomer($data) {
  4. $this->db->query("INSERT INTO " . DB_PREFIX . "customer SET firstname = '" . $this->db->escape($data['firstname']) . "', lastname = '" . $this->db->escape($data['lastname']) . "', email = '" . $this->db->escape($data['email']) . "', telephone = '" . $this->db->escape($data['telephone']) . "', fax = '" . $this->db->escape($data['fax']) . "', newsletter = '" . (int)$data['newsletter'] . "', customer_group_id = '" . (int)$data['customer_group_id'] . "', password = '" . $this->db->escape(md5($data['password'])) . "', status = '" . (int)$data['status'] . "', date_added = NOW()");
  5. $customer_id = $this->db->getLastId();
  6. if (isset($data['address'])) {
  7. foreach ($data['address'] as $address) {
  8. $this->db->query("INSERT INTO " . DB_PREFIX . "address SET customer_id = '" . (int)$customer_id . "', firstname = '" . $this->db->escape($address['firstname']) . "', lastname = '" . $this->db->escape($address['lastname']) . "', company = '" . $this->db->escape($address['company']) . "', address_1 = '" . $this->db->escape($address['address_1']) . "', address_2 = '" . $this->db->escape($address['address_2']) . "', city = '" . $this->db->escape($address['city']) . "', postcode = '" . $this->db->escape($address['postcode']) . "', country_id = '" . (int)$address['country_id'] . "', zone_id = '" . (int)$address['zone_id'] . "'");
  9. if (isset($address['default'])) {
  10. $address_id = $this->db->getLastId();
  11. $this->db->query("UPDATE " . DB_PREFIX . "customer SET address_id = '" . $address_id . "' WHERE customer_id = '" . (int)$customer_id . "'");
  12. }
  13. }
  14. }
  15. }
  16. public function editCustomer($customer_id, $data) {
  17. $this->db->query("UPDATE " . DB_PREFIX . "customer SET firstname = '" . $this->db->escape($data['firstname']) . "', lastname = '" . $this->db->escape($data['lastname']) . "', email = '" . $this->db->escape($data['email']) . "', telephone = '" . $this->db->escape($data['telephone']) . "', fax = '" . $this->db->escape($data['fax']) . "', newsletter = '" . (int)$data['newsletter'] . "', customer_group_id = '" . (int)$data['customer_group_id'] . "', status = '" . (int)$data['status'] . "' WHERE customer_id = '" . (int)$customer_id . "'");
  18. if ($data['password']) {
  19. $this->db->query("UPDATE " . DB_PREFIX . "customer SET password = '" . $this->db->escape(md5($data['password'])) . "' WHERE customer_id = '" . (int)$customer_id . "'");
  20. }
  21. $this->db->query("DELETE FROM " . DB_PREFIX . "address WHERE customer_id = '" . (int)$customer_id . "'");
  22. if (isset($data['address'])) {
  23. foreach ($data['address'] as $address) {
  24. if ($address['address_id']) {
  25. $this->db->query("INSERT INTO " . DB_PREFIX . "address SET address_id = '" . $this->db->escape($address['address_id']) . "', customer_id = '" . (int)$customer_id . "', firstname = '" . $this->db->escape($address['firstname']) . "', lastname = '" . $this->db->escape($address['lastname']) . "', company = '" . $this->db->escape($address['company']) . "', address_1 = '" . $this->db->escape($address['address_1']) . "', address_2 = '" . $this->db->escape($address['address_2']) . "', city = '" . $this->db->escape($address['city']) . "', postcode = '" . $this->db->escape($address['postcode']) . "', country_id = '" . (int)$address['country_id'] . "', zone_id = '" . (int)$address['zone_id'] . "'");
  26. if (isset($address['default'])) {
  27. $this->db->query("UPDATE " . DB_PREFIX . "customer SET address_id = '" . (int)$address['address_id'] . "' WHERE customer_id = '" . (int)$customer_id . "'");
  28. }
  29. } else {
  30. $this->db->query("INSERT INTO " . DB_PREFIX . "address SET customer_id = '" . (int)$customer_id . "', firstname = '" . $this->db->escape($address['firstname']) . "', lastname = '" . $this->db->escape($address['lastname']) . "', company = '" . $this->db->escape($address['company']) . "', address_1 = '" . $this->db->escape($address['address_1']) . "', address_2 = '" . $this->db->escape($address['address_2']) . "', city = '" . $this->db->escape($address['city']) . "', postcode = '" . $this->db->escape($address['postcode']) . "', country_id = '" . (int)$address['country_id'] . "', zone_id = '" . (int)$address['zone_id'] . "'");
  31. if (isset($address['default'])) {
  32. $address_id = $this->db->getLastId();
  33. $this->db->query("UPDATE " . DB_PREFIX . "customer SET address_id = '" . (int)$address_id . "' WHERE customer_id = '" . (int)$customer_id . "'");
  34. }
  35. }
  36. }
  37. }
  38. }
  39. public function editToken($customer_id, $token) {
  40. $this->db->query("UPDATE " . DB_PREFIX . "customer SET token = '" . $this->db->escape($token) . "' WHERE customer_id = '" . (int)$customer_id . "'");
  41. }
  42. public function deleteCustomer($customer_id) {
  43. $this->db->query("DELETE FROM " . DB_PREFIX . "customer WHERE customer_id = '" . (int)$customer_id . "'");
  44. $this->db->query("DELETE FROM " . DB_PREFIX . "customer_reward WHERE customer_id = '" . (int)$customer_id . "'");
  45. $this->db->query("DELETE FROM " . DB_PREFIX . "customer_transaction WHERE customer_id = '" . (int)$customer_id . "'");
  46. $this->db->query("DELETE FROM " . DB_PREFIX . "customer_ip WHERE customer_id = '" . (int)$customer_id . "'");
  47. $this->db->query("DELETE FROM " . DB_PREFIX . "address WHERE customer_id = '" . (int)$customer_id . "'");
  48. }
  49. public function getCustomer($customer_id) {
  50. $query = $this->db->query("SELECT DISTINCT * FROM " . DB_PREFIX . "customer WHERE customer_id = '" . (int)$customer_id . "'");
  51. return $query->row;
  52. }
  53. public function getCustomerByEmail($email) {
  54. $query = $this->db->query("SELECT DISTINCT * FROM " . DB_PREFIX . "customer WHERE email = '" . $this->db->escape($email) . "'");
  55. return $query->row;
  56. }
  57. public function getCustomers($data = array()) {
  58. $sql = "SELECT *, CONCAT(c.firstname, ' ', c.lastname) AS name, cg.name AS customer_group FROM " . DB_PREFIX . "customer c LEFT JOIN " . DB_PREFIX . "customer_group cg ON (c.customer_group_id = cg.customer_group_id)";
  59. $implode = array();
  60. if (!empty($data['filter_name'])) {
  61. $implode[] = "LCASE(CONCAT(c.firstname, ' ', c.lastname)) LIKE '" . $this->db->escape(utf8_strtolower($data['filter_name'])) . "%'";
  62. }
  63. if (!empty($data['filter_email'])) {
  64. $implode[] = "LCASE(c.email) LIKE '" . $this->db->escape(utf8_strtolower($data['filter_email'])) . "%'";
  65. }
  66. if (!empty($data['filter_customer_group_id'])) {
  67. $implode[] = "cg.customer_group_id = '" . $this->db->escape($data['filter_customer_group_id']) . "'";
  68. }
  69. if (isset($data['filter_status']) && !is_null($data['filter_status'])) {
  70. $implode[] = "c.status = '" . (int)$data['filter_status'] . "'";
  71. }
  72. if (isset($data['filter_approved']) && !is_null($data['filter_approved'])) {
  73. $implode[] = "c.approved = '" . (int)$data['filter_approved'] . "'";
  74. }
  75. if (!empty($data['filter_ip'])) {
  76. $implode[] = "c.customer_id IN (SELECT customer_id FROM " . DB_PREFIX . "customer_ip WHERE ip = '" . $this->db->escape($data['filter_ip']) . "')";
  77. }
  78. if (!empty($data['filter_date_added'])) {
  79. $implode[] = "DATE(c.date_added) = DATE('" . $this->db->escape($data['filter_date_added']) . "')";
  80. }
  81. if ($implode) {
  82. $sql .= " WHERE " . implode(" AND ", $implode);
  83. }
  84. $sort_data = array(
  85. 'name',
  86. 'c.email',
  87. 'customer_group',
  88. 'c.status',
  89. 'c.ip',
  90. 'c.date_added'
  91. );
  92. if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
  93. $sql .= " ORDER BY " . $data['sort'];
  94. } else {
  95. $sql .= " ORDER BY name";
  96. }
  97. if (isset($data['order']) && ($data['order'] == 'DESC')) {
  98. $sql .= " DESC";
  99. } else {
  100. $sql .= " ASC";
  101. }
  102. if (isset($data['start']) || isset($data['limit'])) {
  103. if ($data['start'] < 0) {
  104. $data['start'] = 0;
  105. }
  106. if ($data['limit'] < 1) {
  107. $data['limit'] = 20;
  108. }
  109. $sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit'];
  110. }
  111. $query = $this->db->query($sql);
  112. return $query->rows;
  113. }
  114. public function approve($customer_id) {
  115. $customer_info = $this->getCustomer($customer_id);
  116. if ($customer_info) {
  117. $this->db->query("UPDATE " . DB_PREFIX . "customer SET approved = '1' WHERE customer_id = '" . (int)$customer_id . "'");
  118. $this->load->language('mail/customer');
  119. $this->load->model('setting/store');
  120. $store_info = $this->model_setting_store->getStore($customer_info['store_id']);
  121. if ($store_info) {
  122. $store_name = $store_info['name'];
  123. $store_url = $store_info['url'] . 'index.php?route=account/login';
  124. } else {
  125. $store_name = $this->config->get('config_name');
  126. $store_url = HTTP_CATALOG . 'index.php?route=account/login';
  127. }
  128. $message = sprintf($this->language->get('text_approve_welcome'), $store_name) . "\n\n";
  129. $message .= $this->language->get('text_approve_login') . "\n";
  130. $message .= $store_url . "\n\n";
  131. $message .= $this->language->get('text_approve_services') . "\n\n";
  132. $message .= $this->language->get('text_approve_thanks') . "\n";
  133. $message .= $store_name;
  134. $mail = new Mail();
  135. $mail->protocol = $this->config->get('config_mail_protocol');
  136. $mail->parameter = $this->config->get('config_mail_parameter');
  137. $mail->hostname = $this->config->get('config_smtp_host');
  138. $mail->username = $this->config->get('config_smtp_username');
  139. $mail->password = $this->config->get('config_smtp_password');
  140. $mail->port = $this->config->get('config_smtp_port');
  141. $mail->timeout = $this->config->get('config_smtp_timeout');
  142. $mail->setTo($customer_info['email']);
  143. $mail->setFrom($this->config->get('config_email'));
  144. $mail->setSender($store_name);
  145. $mail->setSubject(sprintf($this->language->get('text_approve_subject'), $store_name));
  146. $mail->setText(html_entity_decode($message, ENT_QUOTES, 'UTF-8'));
  147. $mail->send();
  148. }
  149. }
  150. public function getCustomersByNewsletter() {
  151. $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "customer WHERE newsletter = '1' ORDER BY firstname, lastname, email");
  152. return $query->rows;
  153. }
  154. public function getCustomersByCustomerGroupId($customer_group_id) {
  155. $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "customer WHERE customer_group_id = '" . (int)$customer_group_id . "' ORDER BY firstname, lastname, email");
  156. return $query->rows;
  157. }
  158. public function getCustomersByProduct($product_id) {
  159. if ($product_id) {
  160. $query = $this->db->query("SELECT DISTINCT `email` FROM `" . DB_PREFIX . "order` o LEFT JOIN " . DB_PREFIX . "order_product op ON (o.order_id = op.order_id) WHERE op.product_id = '" . (int)$product_id . "' AND o.order_status_id <> '0'");
  161. return $query->rows;
  162. } else {
  163. return array();
  164. }
  165. }
  166. public function getAddress($address_id) {
  167. $address_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "address WHERE address_id = '" . (int)$address_id . "'");
  168. $default_query = $this->db->query("SELECT address_id FROM " . DB_PREFIX . "customer WHERE customer_id = '" . (int)$address_query->row['customer_id'] . "'");
  169. if ($address_query->num_rows) {
  170. $country_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "country` WHERE country_id = '" . (int)$address_query->row['country_id'] . "'");
  171. if ($country_query->num_rows) {
  172. $country = $country_query->row['name'];
  173. $iso_code_2 = $country_query->row['iso_code_2'];
  174. $iso_code_3 = $country_query->row['iso_code_3'];
  175. $address_format = $country_query->row['address_format'];
  176. } else {
  177. $country = '';
  178. $iso_code_2 = '';
  179. $iso_code_3 = '';
  180. $address_format = '';
  181. }
  182. $zone_query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "zone` WHERE zone_id = '" . (int)$address_query->row['zone_id'] . "'");
  183. if ($zone_query->num_rows) {
  184. $zone = $zone_query->row['name'];
  185. $code = $zone_query->row['code'];
  186. } else {
  187. $zone = '';
  188. $code = '';
  189. }
  190. return array(
  191. 'address_id' => $address_query->row['address_id'],
  192. 'customer_id' => $address_query->row['customer_id'],
  193. 'firstname' => $address_query->row['firstname'],
  194. 'lastname' => $address_query->row['lastname'],
  195. 'company' => $address_query->row['company'],
  196. 'address_1' => $address_query->row['address_1'],
  197. 'address_2' => $address_query->row['address_2'],
  198. 'postcode' => $address_query->row['postcode'],
  199. 'city' => $address_query->row['city'],
  200. 'zone_id' => $address_query->row['zone_id'],
  201. 'zone' => $zone,
  202. 'zone_code' => $code,
  203. 'country_id' => $address_query->row['country_id'],
  204. 'country' => $country,
  205. 'iso_code_2' => $iso_code_2,
  206. 'iso_code_3' => $iso_code_3,
  207. 'address_format' => $address_format,
  208. 'default' => ($default_query->row['address_id'] == $address_query->row['address_id']) ? true : false
  209. );
  210. }
  211. }
  212. public function getAddresses($customer_id) {
  213. $address_data = array();
  214. $query = $this->db->query("SELECT address_id FROM " . DB_PREFIX . "address WHERE customer_id = '" . (int)$customer_id . "'");
  215. foreach ($query->rows as $result) {
  216. $address_info = $this->getAddress($result['address_id']);
  217. if ($address_info) {
  218. $address_data[] = $address_info;
  219. }
  220. }
  221. return $address_data;
  222. }
  223. public function getTotalCustomers($data = array()) {
  224. $sql = "SELECT COUNT(*) AS total FROM " . DB_PREFIX . "customer";
  225. $implode = array();
  226. if (!empty($data['filter_name'])) {
  227. $implode[] = "LCASE(CONCAT(firstname, ' ', lastname)) LIKE '" . $this->db->escape(utf8_strtolower($data['filter_name'])) . "%'";
  228. }
  229. if (!empty($data['filter_email'])) {
  230. $implode[] = "LCASE(email) LIKE '" . $this->db->escape(utf8_strtolower($data['filter_email'])) . "%'";
  231. }
  232. if (!empty($data['filter_customer_group_id'])) {
  233. $implode[] = "customer_group_id = '" . $this->db->escape($data['filter_customer_group_id']) . "'";
  234. }
  235. if (isset($data['filter_status']) && !is_null($data['filter_status'])) {
  236. $implode[] = "status = '" . (int)$data['filter_status'] . "'";
  237. }
  238. if (isset($data['filter_approved']) && !is_null($data['filter_approved'])) {
  239. $implode[] = "approved = '" . (int)$data['filter_approved'] . "'";
  240. }
  241. if (!empty($data['filter_date_added'])) {
  242. $implode[] = "DATE(date_added) = DATE('" . $this->db->escape($data['filter_date_added']) . "')";
  243. }
  244. if ($implode) {
  245. $sql .= " WHERE " . implode(" AND ", $implode);
  246. }
  247. $query = $this->db->query($sql);
  248. return $query->row['total'];
  249. }
  250. public function getTotalCustomersAwaitingApproval() {
  251. $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "customer WHERE status = '0' OR approved = '0'");
  252. return $query->row['total'];
  253. }
  254. public function getTotalAddressesByCustomerId($customer_id) {
  255. $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "address WHERE customer_id = '" . (int)$customer_id . "'");
  256. return $query->row['total'];
  257. }
  258. public function getTotalAddressesByCountryId($country_id) {
  259. $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "address WHERE country_id = '" . (int)$country_id . "'");
  260. return $query->row['total'];
  261. }
  262. public function getTotalAddressesByZoneId($zone_id) {
  263. $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "address WHERE zone_id = '" . (int)$zone_id . "'");
  264. return $query->row['total'];
  265. }
  266. public function getTotalCustomersByCustomerGroupId($customer_group_id) {
  267. $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "customer WHERE customer_group_id = '" . (int)$customer_group_id . "'");
  268. return $query->row['total'];
  269. }
  270. public function addTransaction($customer_id, $description = '', $amount = '', $order_id = 0) {
  271. $customer_info = $this->getCustomer($customer_id);
  272. if ($customer_info) {
  273. $this->db->query("INSERT INTO " . DB_PREFIX . "customer_transaction SET customer_id = '" . (int)$customer_id . "', order_id = '" . (int)$order_id . "', description = '" . $this->db->escape($description) . "', amount = '" . (float)$amount . "', date_added = NOW()");
  274. $this->language->load('mail/customer');
  275. if ($customer_info['store_id']) {
  276. $this->load->model('setting/store');
  277. $store_info = $this->model_setting_store->getStore($customer_info['store_id']);
  278. if ($store_info) {
  279. $store_name = $store_info['store_name'];
  280. } else {
  281. $store_name = $this->config->get('config_name');
  282. }
  283. } else {
  284. $store_name = $this->config->get('config_name');
  285. }
  286. $message = sprintf($this->language->get('text_transaction_received'), $this->currency->format($amount, $this->config->get('config_currency'))) . "\n\n";
  287. $message .= sprintf($this->language->get('text_transaction_total'), $this->currency->format($this->getTransactionTotal($customer_id)));
  288. $mail = new Mail();
  289. $mail->protocol = $this->config->get('config_mail_protocol');
  290. $mail->parameter = $this->config->get('config_mail_parameter');
  291. $mail->hostname = $this->config->get('config_smtp_host');
  292. $mail->username = $this->config->get('config_smtp_username');
  293. $mail->password = $this->config->get('config_smtp_password');
  294. $mail->port = $this->config->get('config_smtp_port');
  295. $mail->timeout = $this->config->get('config_smtp_timeout');
  296. $mail->setTo($customer_info['email']);
  297. $mail->setFrom($this->config->get('config_email'));
  298. $mail->setSender($store_name);
  299. $mail->setSubject(sprintf($this->language->get('text_transaction_subject'), $this->config->get('config_name')));
  300. $mail->setText($message);
  301. $mail->send();
  302. }
  303. }
  304. public function deleteTransaction($order_id) {
  305. $this->db->query("DELETE FROM " . DB_PREFIX . "customer_transaction WHERE order_id = '" . (int)$order_id . "'");
  306. }
  307. public function getTransactions($customer_id, $start = 0, $limit = 10) {
  308. $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "customer_transaction WHERE customer_id = '" . (int)$customer_id . "' ORDER BY date_added DESC LIMIT " . (int)$start . "," . (int)$limit);
  309. return $query->rows;
  310. }
  311. public function getTotalTransactions($customer_id) {
  312. $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "customer_transaction WHERE customer_id = '" . (int)$customer_id . "'");
  313. return $query->row['total'];
  314. }
  315. public function getTransactionTotal($customer_id) {
  316. $query = $this->db->query("SELECT SUM(amount) AS total FROM " . DB_PREFIX . "customer_transaction WHERE customer_id = '" . (int)$customer_id . "'");
  317. return $query->row['total'];
  318. }
  319. public function getTotalTransactionsByOrderId($order_id) {
  320. $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "customer_transaction WHERE order_id = '" . (int)$order_id . "'");
  321. return $query->row['total'];
  322. }
  323. public function addReward($customer_id, $description = '', $points = '', $order_id = 0) {
  324. $customer_info = $this->getCustomer($customer_id);
  325. if ($customer_info) {
  326. $this->db->query("INSERT INTO " . DB_PREFIX . "customer_reward SET customer_id = '" . (int)$customer_id . "', order_id = '" . (int)$order_id . "', points = '" . (int)$points . "', description = '" . $this->db->escape($description) . "', date_added = NOW()");
  327. $this->language->load('mail/customer');
  328. if ($order_id) {
  329. $this->load->model('sale/order');
  330. $order_info = $this->model_sale_order->getOrder($order_id);
  331. if ($order_info) {
  332. $store_name = $order_info['store_name'];
  333. } else {
  334. $store_name = $this->config->get('config_name');
  335. }
  336. } else {
  337. $store_name = $this->config->get('config_name');
  338. }
  339. $message = sprintf($this->language->get('text_reward_received'), $points) . "\n\n";
  340. $message .= sprintf($this->language->get('text_reward_total'), $this->getRewardTotal($customer_id));
  341. $mail = new Mail();
  342. $mail->protocol = $this->config->get('config_mail_protocol');
  343. $mail->parameter = $this->config->get('config_mail_parameter');
  344. $mail->hostname = $this->config->get('config_smtp_host');
  345. $mail->username = $this->config->get('config_smtp_username');
  346. $mail->password = $this->config->get('config_smtp_password');
  347. $mail->port = $this->config->get('config_smtp_port');
  348. $mail->timeout = $this->config->get('config_smtp_timeout');
  349. $mail->setTo($customer_info['email']);
  350. $mail->setFrom($this->config->get('config_email'));
  351. $mail->setSender($store_name);
  352. $mail->setSubject(sprintf($this->language->get('text_reward_subject'), $store_name));
  353. $mail->setText($message);
  354. $mail->send();
  355. }
  356. }
  357. public function deleteReward($order_id) {
  358. $this->db->query("DELETE FROM " . DB_PREFIX . "customer_reward WHERE order_id = '" . (int)$order_id . "'");
  359. }
  360. public function getRewards($customer_id, $start = 0, $limit = 10) {
  361. $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "customer_reward WHERE customer_id = '" . (int)$customer_id . "' ORDER BY date_added DESC LIMIT " . (int)$start . "," . (int)$limit);
  362. return $query->rows;
  363. }
  364. public function getTotalRewards($customer_id) {
  365. $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "customer_reward WHERE customer_id = '" . (int)$customer_id . "'");
  366. return $query->row['total'];
  367. }
  368. public function getRewardTotal($customer_id) {
  369. $query = $this->db->query("SELECT SUM(points) AS total FROM " . DB_PREFIX . "customer_reward WHERE customer_id = '" . (int)$customer_id . "'");
  370. return $query->row['total'];
  371. }
  372. public function getTotalCustomerRewardsByOrderId($order_id) {
  373. $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "customer_reward WHERE order_id = '" . (int)$order_id . "'");
  374. return $query->row['total'];
  375. }
  376. public function getIpsByCustomerId($customer_id) {
  377. $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "customer_ip WHERE customer_id = '" . (int)$customer_id . "'");
  378. return $query->rows;
  379. }
  380. public function getTotalCustomersByIp($ip) {
  381. $query = $this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "customer_ip WHERE ip = '" . $this->db->escape($ip) . "'");
  382. return $query->row['total'];
  383. }
  384. }
  385. ?>