docs/api/source-admin.controller.customer.customer.html
| 1: | <?php | | 2: | namespace Opencart\Admin\Controller\Customer; | | 3: | /** | | 4: | * Class Customer | | 5: | * | | 6: | * @package Opencart\Admin\Controller\Customer | | 7: | */ | | 8: | class Customer extends \Opencart\System\Engine\Controller { | | 9: | /** | | 10: | * Index | | 11: | * | | 12: | * @return void | | 13: | */ | | 14: | public function index(): void { | | 15: | $this->load->language('customer/customer'); | | 16: | | | 17: | $this->document->setTitle($this->language->get('heading_title')); | | 18: | | | 19: | if (isset($this->request->get['filter_name'])) { | | 20: | $filter_name = (string)$this->request->get['filter_name']; | | 21: | } else { | | 22: | $filter_name = ''; | | 23: | } | | 24: | | | 25: | if (isset($this->request->get['filter_email'])) { | | 26: | $filter_email = (string)$this->request->get['filter_email']; | | 27: | } else { | | 28: | $filter_email = ''; | | 29: | } | | 30: | | | 31: | if (isset($this->request->get['filter_customer_group_id'])) { | | 32: | $filter_customer_group_id = (int)$this->request->get['filter_customer_group_id']; | | 33: | } else { | | 34: | $filter_customer_group_id = ''; | | 35: | } | | 36: | | | 37: | if (isset($this->request->get['filter_status'])) { | | 38: | $filter_status = (bool)$this->request->get['filter_status']; | | 39: | } else { | | 40: | $filter_status = ''; | | 41: | } | | 42: | | | 43: | if (isset($this->request->get['filter_ip'])) { | | 44: | $filter_ip = (string)$this->request->get['filter_ip']; | | 45: | } else { | | 46: | $filter_ip = ''; | | 47: | } | | 48: | | | 49: | if (isset($this->request->get['filter_date_from'])) { | | 50: | $filter_date_from = (string)$this->request->get['filter_date_from']; | | 51: | } else { | | 52: | $filter_date_from = ''; | | 53: | } | | 54: | | | 55: | if (isset($this->request->get['filter_date_to'])) { | | 56: | $filter_date_to = (string)$this->request->get['filter_date_to']; | | 57: | } else { | | 58: | $filter_date_to = ''; | | 59: | } | | 60: | | | 61: | $url = ''; | | 62: | | | 63: | if (isset($this->request->get['filter_name'])) { | | 64: | $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8')); | | 65: | } | | 66: | | | 67: | if (isset($this->request->get['filter_email'])) { | | 68: | $url .= '&filter_email=' . urlencode(html_entity_decode($this->request->get['filter_email'], ENT_QUOTES, 'UTF-8')); | | 69: | } | | 70: | | | 71: | if (isset($this->request->get['filter_customer_group_id'])) { | | 72: | $url .= '&filter_customer_group_id=' . $this->request->get['filter_customer_group_id']; | | 73: | } | | 74: | | | 75: | if (isset($this->request->get['filter_status'])) { | | 76: | $url .= '&filter_status=' . $this->request->get['filter_status']; | | 77: | } | | 78: | | | 79: | if (isset($this->request->get['filter_ip'])) { | | 80: | $url .= '&filter_ip=' . $this->request->get['filter_ip']; | | 81: | } | | 82: | | | 83: | if (isset($this->request->get['filter_date_from'])) { | | 84: | $url .= '&filter_date_from=' . $this->request->get['filter_date_from']; | | 85: | } | | 86: | | | 87: | if (isset($this->request->get['filter_date_to'])) { | | 88: | $url .= '&filter_date_to=' . $this->request->get['filter_date_to']; | | 89: | } | | 90: | | | 91: | if (isset($this->request->get['sort'])) { | | 92: | $url .= '&sort=' . $this->request->get['sort']; | | 93: | } | | 94: | | | 95: | if (isset($this->request->get['order'])) { | | 96: | $url .= '&order=' . $this->request->get['order']; | | 97: | } | | 98: | | | 99: | if (isset($this->request->get['page'])) { | | 100: | $url .= '&page=' . $this->request->get['page']; | | 101: | } | | 102: | | | 103: | $data['breadcrumbs'] = []; | | 104: | | | 105: | $data['breadcrumbs'][] = [ | | 106: | 'text' => $this->language->get('text_home'), | | 107: | 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token']) | | 108: | ]; | | 109: | | | 110: | $data['breadcrumbs'][] = [ | | 111: | 'text' => $this->language->get('heading_title'), | | 112: | 'href' => $this->url->link('customer/customer', 'user_token=' . $this->session->data['user_token'] . $url) | | 113: | ]; | | 114: | | | 115: | $data['add'] = $this->url->link('customer/customer.form', 'user_token=' . $this->session->data['user_token'] . $url); | | 116: | $data['delete'] = $this->url->link('customer/customer.delete', 'user_token=' . $this->session->data['user_token']); | | 117: | | | 118: | $data['list'] = $this->getList(); | | 119: | | | 120: | $this->load->model('customer/customer_group'); | | 121: | | | 122: | $data['customer_groups'] = $this->model_customer_customer_group->getCustomerGroups(); | | 123: | | | 124: | $data['filter_name'] = $filter_name; | | 125: | $data['filter_email'] = $filter_email; | | 126: | $data['filter_customer_group_id'] = $filter_customer_group_id; | | 127: | $data['filter_status'] = $filter_status; | | 128: | $data['filter_ip'] = $filter_ip; | | 129: | $data['filter_date_from'] = $filter_date_from; | | 130: | $data['filter_date_to'] = $filter_date_to; | | 131: | | | 132: | $data['user_token'] = $this->session->data['user_token']; | | 133: | | | 134: | $data['header'] = $this->load->controller('common/header'); | | 135: | $data['column_left'] = $this->load->controller('common/column_left'); | | 136: | $data['footer'] = $this->load->controller('common/footer'); | | 137: | | | 138: | $this->response->setOutput($this->load->view('customer/customer', $data)); | | 139: | } | | 140: | | | 141: | /** | | 142: | * List | | 143: | * | | 144: | * @return void | | 145: | */ | | 146: | public function list(): void { | | 147: | $this->load->language('customer/customer'); | | 148: | | | 149: | $this->response->setOutput($this->getList()); | | 150: | } | | 151: | | | 152: | /** | | 153: | * Get List | | 154: | * | | 155: | * @return string | | 156: | */ | | 157: | protected function getList(): string { | | 158: | if (isset($this->request->get['filter_name'])) { | | 159: | $filter_name = $this->request->get['filter_name']; | | 160: | } else { | | 161: | $filter_name = ''; | | 162: | } | | 163: | | | 164: | if (isset($this->request->get['filter_email'])) { | | 165: | $filter_email = $this->request->get['filter_email']; | | 166: | } else { | | 167: | $filter_email = ''; | | 168: | } | | 169: | | | 170: | if (isset($this->request->get['filter_customer_group_id'])) { | | 171: | $filter_customer_group_id = (int)$this->request->get['filter_customer_group_id']; | | 172: | } else { | | 173: | $filter_customer_group_id = ''; | | 174: | } | | 175: | | | 176: | if (isset($this->request->get['filter_status'])) { | | 177: | $filter_status = (bool)$this->request->get['filter_status']; | | 178: | } else { | | 179: | $filter_status = ''; | | 180: | } | | 181: | | | 182: | if (isset($this->request->get['filter_ip'])) { | | 183: | $filter_ip = (string)$this->request->get['filter_ip']; | | 184: | } else { | | 185: | $filter_ip = ''; | | 186: | } | | 187: | | | 188: | if (isset($this->request->get['filter_date_from'])) { | | 189: | $filter_date_from = (string)$this->request->get['filter_date_from']; | | 190: | } else { | | 191: | $filter_date_from = ''; | | 192: | } | | 193: | | | 194: | if (isset($this->request->get['filter_date_to'])) { | | 195: | $filter_date_to = (string)$this->request->get['filter_date_to']; | | 196: | } else { | | 197: | $filter_date_to = ''; | | 198: | } | | 199: | | | 200: | if (isset($this->request->get['sort'])) { | | 201: | $sort = (string)$this->request->get['sort']; | | 202: | } else { | | 203: | $sort = 'name'; | | 204: | } | | 205: | | | 206: | if (isset($this->request->get['order'])) { | | 207: | $order = (string)$this->request->get['order']; | | 208: | } else { | | 209: | $order = 'ASC'; | | 210: | } | | 211: | | | 212: | if (isset($this->request->get['page'])) { | | 213: | $page = (int)$this->request->get['page']; | | 214: | } else { | | 215: | $page = 1; | | 216: | } | | 217: | | | 218: | $url = ''; | | 219: | | | 220: | if (isset($this->request->get['filter_name'])) { | | 221: | $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8')); | | 222: | } | | 223: | | | 224: | if (isset($this->request->get['filter_email'])) { | | 225: | $url .= '&filter_email=' . urlencode(html_entity_decode($this->request->get['filter_email'], ENT_QUOTES, 'UTF-8')); | | 226: | } | | 227: | | | 228: | if (isset($this->request->get['filter_customer_group_id'])) { | | 229: | $url .= '&filter_customer_group_id=' . $this->request->get['filter_customer_group_id']; | | 230: | } | | 231: | | | 232: | if (isset($this->request->get['filter_status'])) { | | 233: | $url .= '&filter_status=' . $this->request->get['filter_status']; | | 234: | } | | 235: | | | 236: | if (isset($this->request->get['filter_ip'])) { | | 237: | $url .= '&filter_ip=' . $this->request->get['filter_ip']; | | 238: | } | | 239: | | | 240: | if (isset($this->request->get['filter_date_from'])) { | | 241: | $url .= '&filter_date_from=' . $this->request->get['filter_date_from']; | | 242: | } | | 243: | | | 244: | if (isset($this->request->get['filter_date_to'])) { | | 245: | $url .= '&filter_date_to=' . $this->request->get['filter_date_to']; | | 246: | } | | 247: | | | 248: | if (isset($this->request->get['sort'])) { | | 249: | $url .= '&sort=' . $this->request->get['sort']; | | 250: | } | | 251: | | | 252: | if (isset($this->request->get['order'])) { | | 253: | $url .= '&order=' . $this->request->get['order']; | | 254: | } | | 255: | | | 256: | if (isset($this->request->get['page'])) { | | 257: | $url .= '&page=' . $this->request->get['page']; | | 258: | } | | 259: | | | 260: | $data['action'] = $this->url->link('customer/customer.list', 'user_token=' . $this->session->data['user_token'] . $url); | | 261: | | | 262: | $this->load->model('setting/store'); | | 263: | | | 264: | $stores = $this->model_setting_store->getStores(); | | 265: | | | 266: | $data['customers'] = []; | | 267: | | | 268: | $filter_data = [ | | 269: | 'filter_name' => $filter_name, | | 270: | 'filter_email' => $filter_email, | | 271: | 'filter_customer_group_id' => $filter_customer_group_id, | | 272: | 'filter_status' => $filter_status, | | 273: | 'filter_ip' => $filter_ip, | | 274: | 'filter_date_from' => $filter_date_from, | | 275: | 'filter_date_to' => $filter_date_to, | | 276: | 'sort' => $sort, | | 277: | 'order' => $order, | | 278: | 'start' => ($page - 1) * $this->config->get('config_pagination_admin'), | | 279: | 'limit' => $this->config->get('config_pagination_admin') | | 280: | ]; | | 281: | | | 282: | $this->load->model('customer/customer'); | | 283: | | | 284: | $results = $this->model_customer_customer->getCustomers($filter_data); | | 285: | | | 286: | foreach ($results as $result) { | | 287: | $login_info = $this->model_customer_customer->getTotalLoginAttempts($result['email']); | | 288: | | | 289: | if ($login_info && $login_info['total'] >= $this->config->get('config_login_attempts')) { | | 290: | $unlock = $this->url->link('customer/customer.unlock', 'user_token=' . $this->session->data['user_token'] . '&email=' . $result['email'] . $url); | | 291: | } else { | | 292: | $unlock = ''; | | 293: | } | | 294: | | | 295: | $store_data = []; | | 296: | | | 297: | $store_data[] = [ | | 298: | 'store_id' => 0, | | 299: | 'name' => $this->config->get('config_name'), | | 300: | 'href' => $this->url->link('customer/customer.login', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . $result['customer_id'] . '&store_id=0') | | 301: | ]; | | 302: | | | 303: | foreach ($stores as $store) { | | 304: | $store_data[] = [ | | 305: | 'store_id' => $store['store_id'], | | 306: | 'name' => $store['name'], | | 307: | 'href' => $this->url->link('customer/customer.login', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . $result['customer_id'] . '&store_id=' . $store['store_id']) | | 308: | ]; | | 309: | } | | 310: | | | 311: | $data['customers'][] = [ | | 312: | 'customer_id' => $result['customer_id'], | | 313: | 'name' => $result['name'], | | 314: | 'email' => $result['email'], | | 315: | 'store_id' => $result['store_id'], | | 316: | 'customer_group' => $result['customer_group'], | | 317: | 'status' => $result['status'], | | 318: | 'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])), | | 319: | 'unlock' => $unlock, | | 320: | 'store' => $store_data, | | 321: | 'edit' => $this->url->link('customer/customer.form', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . $result['customer_id'] . $url) | | 322: | ]; | | 323: | } | | 324: | | | 325: | $url = ''; | | 326: | | | 327: | if (isset($this->request->get['filter_name'])) { | | 328: | $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8')); | | 329: | } | | 330: | | | 331: | if (isset($this->request->get['filter_email'])) { | | 332: | $url .= '&filter_email=' . urlencode(html_entity_decode($this->request->get['filter_email'], ENT_QUOTES, 'UTF-8')); | | 333: | } | | 334: | | | 335: | if (isset($this->request->get['filter_customer_group_id'])) { | | 336: | $url .= '&filter_customer_group_id=' . $this->request->get['filter_customer_group_id']; | | 337: | } | | 338: | | | 339: | if (isset($this->request->get['filter_status'])) { | | 340: | $url .= '&filter_status=' . $this->request->get['filter_status']; | | 341: | } | | 342: | | | 343: | if (isset($this->request->get['filter_ip'])) { | | 344: | $url .= '&filter_ip=' . $this->request->get['filter_ip']; | | 345: | } | | 346: | | | 347: | if (isset($this->request->get['filter_date_from'])) { | | 348: | $url .= '&filter_date_from=' . $this->request->get['filter_date_from']; | | 349: | } | | 350: | | | 351: | if (isset($this->request->get['filter_date_to'])) { | | 352: | $url .= '&filter_date_to=' . $this->request->get['filter_date_to']; | | 353: | } | | 354: | | | 355: | if ($order == 'ASC') { | | 356: | $url .= '&order=DESC'; | | 357: | } else { | | 358: | $url .= '&order=ASC'; | | 359: | } | | 360: | | | 361: | $data['sort_name'] = $this->url->link('customer/customer.list', 'user_token=' . $this->session->data['user_token'] . '&sort=name' . $url); | | 362: | $data['sort_email'] = $this->url->link('customer/customer.list', 'user_token=' . $this->session->data['user_token'] . '&sort=c.email' . $url); | | 363: | $data['sort_customer_group'] = $this->url->link('customer/customer.list', 'user_token=' . $this->session->data['user_token'] . '&sort=customer_group' . $url); | | 364: | $data['sort_status'] = $this->url->link('customer/customer.list', 'user_token=' . $this->session->data['user_token'] . '&sort=c.status' . $url); | | 365: | $data['sort_date_added'] = $this->url->link('customer/customer.list', 'user_token=' . $this->session->data['user_token'] . '&sort=c.date_added' . $url); | | 366: | | | 367: | $url = ''; | | 368: | | | 369: | if (isset($this->request->get['filter_name'])) { | | 370: | $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8')); | | 371: | } | | 372: | | | 373: | if (isset($this->request->get['filter_email'])) { | | 374: | $url .= '&filter_email=' . urlencode(html_entity_decode($this->request->get['filter_email'], ENT_QUOTES, 'UTF-8')); | | 375: | } | | 376: | | | 377: | if (isset($this->request->get['filter_customer_group_id'])) { | | 378: | $url .= '&filter_customer_group_id=' . $this->request->get['filter_customer_group_id']; | | 379: | } | | 380: | | | 381: | if (isset($this->request->get['filter_status'])) { | | 382: | $url .= '&filter_status=' . $this->request->get['filter_status']; | | 383: | } | | 384: | | | 385: | if (isset($this->request->get['filter_ip'])) { | | 386: | $url .= '&filter_ip=' . $this->request->get['filter_ip']; | | 387: | } | | 388: | | | 389: | if (isset($this->request->get['filter_date_from'])) { | | 390: | $url .= '&filter_date_from=' . $this->request->get['filter_date_from']; | | 391: | } | | 392: | | | 393: | if (isset($this->request->get['filter_date_to'])) { | | 394: | $url .= '&filter_date_to=' . $this->request->get['filter_date_to']; | | 395: | } | | 396: | | | 397: | if (isset($this->request->get['sort'])) { | | 398: | $url .= '&sort=' . $this->request->get['sort']; | | 399: | } | | 400: | | | 401: | if (isset($this->request->get['order'])) { | | 402: | $url .= '&order=' . $this->request->get['order']; | | 403: | } | | 404: | | | 405: | $customer_total = $this->model_customer_customer->getTotalCustomers($filter_data); | | 406: | | | 407: | $data['pagination'] = $this->load->controller('common/pagination', [ | | 408: | 'total' => $customer_total, | | 409: | 'page' => $page, | | 410: | 'limit' => $this->config->get('config_pagination_admin'), | | 411: | 'url' => $this->url->link('customer/customer.list', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}') | | 412: | ]); | | 413: | | | 414: | $data['results'] = sprintf($this->language->get('text_pagination'), ($customer_total) ? (($page - 1) * $this->config->get('config_pagination_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_pagination_admin')) > ($customer_total - $this->config->get('config_pagination_admin'))) ? $customer_total : ((($page - 1) * $this->config->get('config_pagination_admin')) + $this->config->get('config_pagination_admin')), $customer_total, ceil($customer_total / $this->config->get('config_pagination_admin'))); | | 415: | | | 416: | $data['sort'] = $sort; | | 417: | $data['order'] = $order; | | 418: | | | 419: | return $this->load->view('customer/customer_list', $data); | | 420: | } | | 421: | | | 422: | /** | | 423: | * Form | | 424: | * | | 425: | * @return void | | 426: | */ | | 427: | public function form(): void { | | 428: | $this->load->language('customer/customer'); | | 429: | | | 430: | $this->document->setTitle($this->language->get('heading_title')); | | 431: | | | 432: | $data['text_form'] = !isset($this->request->get['customer_id']) ? $this->language->get('text_add') : $this->language->get('text_edit'); | | 433: | | | 434: | $data['error_upload_size'] = sprintf($this->language->get('error_upload_size'), $this->config->get('config_file_max_size')); | | 435: | | | 436: | $data['config_file_max_size'] = ((int)$this->config->get('config_file_max_size') * 1024 * 1024); | | 437: | $data['config_telephone_required'] = $this->config->get('config_telephone_required'); | | 438: | | | 439: | $url = ''; | | 440: | | | 441: | if (isset($this->request->get['filter_name'])) { | | 442: | $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8')); | | 443: | } | | 444: | | | 445: | if (isset($this->request->get['filter_email'])) { | | 446: | $url .= '&filter_email=' . urlencode(html_entity_decode($this->request->get['filter_email'], ENT_QUOTES, 'UTF-8')); | | 447: | } | | 448: | | | 449: | if (isset($this->request->get['filter_customer_group_id'])) { | | 450: | $url .= '&filter_customer_group_id=' . $this->request->get['filter_customer_group_id']; | | 451: | } | | 452: | | | 453: | if (isset($this->request->get['filter_status'])) { | | 454: | $url .= '&filter_status=' . $this->request->get['filter_status']; | | 455: | } | | 456: | | | 457: | if (isset($this->request->get['filter_ip'])) { | | 458: | $url .= '&filter_ip=' . $this->request->get['filter_ip']; | | 459: | } | | 460: | | | 461: | if (isset($this->request->get['filter_date_from'])) { | | 462: | $url .= '&filter_date_from=' . $this->request->get['filter_date_from']; | | 463: | } | | 464: | | | 465: | if (isset($this->request->get['filter_date_to'])) { | | 466: | $url .= '&filter_date_to=' . $this->request->get['filter_date_to']; | | 467: | } | | 468: | | | 469: | if (isset($this->request->get['sort'])) { | | 470: | $url .= '&sort=' . $this->request->get['sort']; | | 471: | } | | 472: | | | 473: | if (isset($this->request->get['order'])) { | | 474: | $url .= '&order=' . $this->request->get['order']; | | 475: | } | | 476: | | | 477: | if (isset($this->request->get['page'])) { | | 478: | $url .= '&page=' . $this->request->get['page']; | | 479: | } | | 480: | | | 481: | $data['breadcrumbs'] = []; | | 482: | | | 483: | $data['breadcrumbs'][] = [ | | 484: | 'text' => $this->language->get('text_home'), | | 485: | 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token']) | | 486: | ]; | | 487: | | | 488: | $data['breadcrumbs'][] = [ | | 489: | 'text' => $this->language->get('heading_title'), | | 490: | 'href' => $this->url->link('customer/customer', 'user_token=' . $this->session->data['user_token'] . $url) | | 491: | ]; | | 492: | | | 493: | $data['save'] = $this->url->link('customer/customer.save', 'user_token=' . $this->session->data['user_token']); | | 494: | $data['back'] = $this->url->link('customer/customer', 'user_token=' . $this->session->data['user_token'] . $url); | | 495: | $data['upload'] = $this->url->link('tool/upload.upload', 'user_token=' . $this->session->data['user_token']); | | 496: | | | 497: | if (isset($this->request->get['customer_id'])) { | | 498: | $data['orders'] = $this->url->link('sale/order', 'user_token=' . $this->session->data['user_token'] . '&filter_customer_id=' . $this->request->get['customer_id']); | | 499: | } else { | | 500: | $data['orders'] = ''; | | 501: | } | | 502: | | | 503: | if (isset($this->request->get['customer_id'])) { | | 504: | $this->load->model('customer/customer'); | | 505: | | | 506: | $customer_info = $this->model_customer_customer->getCustomer((int)$this->request->get['customer_id']); | | 507: | } | | 508: | | | 509: | if (isset($this->request->get['customer_id'])) { | | 510: | $data['customer_id'] = (int)$this->request->get['customer_id']; | | 511: | } else { | | 512: | $data['customer_id'] = 0; | | 513: | } | | 514: | | | 515: | $data['stores'] = []; | | 516: | | | 517: | $data['stores'][] = [ | | 518: | 'store_id' => 0, | | 519: | 'name' => $this->language->get('text_default') | | 520: | ]; | | 521: | | | 522: | $this->load->model('setting/store'); | | 523: | | | 524: | $stores = $this->model_setting_store->getStores(); | | 525: | | | 526: | foreach ($stores as $store) { | | 527: | $data['stores'][] = [ | | 528: | 'store_id' => $store['store_id'], | | 529: | 'name' => $store['name'] | | 530: | ]; | | 531: | } | | 532: | | | 533: | if (!empty($customer_info)) { | | 534: | $data['store_id'] = $customer_info['store_id']; | | 535: | } else { | | 536: | $data['store_id'] = [0]; | | 537: | } | | 538: | | | 539: | $this->load->model('customer/customer_group'); | | 540: | | | 541: | $data['customer_groups'] = $this->model_customer_customer_group->getCustomerGroups(); | | 542: | | | 543: | if (!empty($customer_info)) { | | 544: | $data['customer_group_id'] = $customer_info['customer_group_id']; | | 545: | } else { | | 546: | $data['customer_group_id'] = $this->config->get('config_customer_group_id'); | | 547: | } | | 548: | | | 549: | if (!empty($customer_info)) { | | 550: | $data['firstname'] = $customer_info['firstname']; | | 551: | } else { | | 552: | $data['firstname'] = ''; | | 553: | } | | 554: | | | 555: | if (!empty($customer_info)) { | | 556: | $data['lastname'] = $customer_info['lastname']; | | 557: | } else { | | 558: | $data['lastname'] = ''; | | 559: | } | | 560: | | | 561: | if (!empty($customer_info)) { | | 562: | $data['email'] = $customer_info['email']; | | 563: | } else { | | 564: | $data['email'] = ''; | | 565: | } | | 566: | | | 567: | if (!empty($customer_info)) { | | 568: | $data['telephone'] = $customer_info['telephone']; | | 569: | } else { | | 570: | $data['telephone'] = ''; | | 571: | } | | 572: | | | 573: | // Custom Fields | | 574: | $data['custom_fields'] = []; | | 575: | | | 576: | $filter_data = [ | | 577: | 'filter_location' => 'account', | | 578: | 'sort' => 'cf.sort_order', | | 579: | 'order' => 'ASC' | | 580: | ]; | | 581: | | | 582: | $this->load->model('customer/custom_field'); | | 583: | | | 584: | $custom_fields = $this->model_customer_custom_field->getCustomFields($filter_data); | | 585: | | | 586: | foreach ($custom_fields as $custom_field) { | | 587: | if ($custom_field['status']) { | | 588: | $data['custom_fields'][] = [ | | 589: | 'custom_field_id' => $custom_field['custom_field_id'], | | 590: | 'custom_field_value' => $this->model_customer_custom_field->getValues($custom_field['custom_field_id']), | | 591: | 'name' => $custom_field['name'], | | 592: | 'value' => $custom_field['value'], | | 593: | 'type' => $custom_field['type'], | | 594: | 'location' => $custom_field['location'], | | 595: | 'sort_order' => $custom_field['sort_order'] | | 596: | ]; | | 597: | } | | 598: | } | | 599: | | | 600: | if (!empty($customer_info)) { | | 601: | $data['account_custom_field'] = $customer_info['custom_field']; | | 602: | } else { | | 603: | $data['account_custom_field'] = []; | | 604: | } | | 605: | | | 606: | $data['password'] = ''; | | 607: | $data['confirm'] = ''; | | 608: | | | 609: | if (!empty($customer_info)) { | | 610: | $data['newsletter'] = $customer_info['newsletter']; | | 611: | } else { | | 612: | $data['newsletter'] = 0; | | 613: | } | | 614: | | | 615: | if (!empty($customer_info)) { | | 616: | $data['status'] = $customer_info['status']; | | 617: | } else { | | 618: | $data['status'] = 1; | | 619: | } | | 620: | | | 621: | if (!empty($customer_info)) { | | 622: | $data['safe'] = $customer_info['safe']; | | 623: | } else { | | 624: | $data['safe'] = 0; | | 625: | } | | 626: | | | 627: | if (!empty($customer_info)) { | | 628: | $data['commenter'] = $customer_info['commenter']; | | 629: | } else { | | 630: | $data['commenter'] = 0; | | 631: | } | | 632: | | | 633: | $this->load->model('localisation/country'); | | 634: | | | 635: | $data['countries'] = $this->model_localisation_country->getCountries(); | | 636: | | | 637: | $data['address'] = $this->load->controller('customer/address.getAddress'); | | 638: | $data['history'] = $this->getHistory(); | | 639: | $data['transaction'] = $this->getTransaction(); | | 640: | $data['reward'] = $this->getReward(); | | 641: | $data['ip'] = $this->getIp(); | | 642: | $data['authorize'] = $this->getAuthorize(); | | 643: | | | 644: | $data['user_token'] = $this->session->data['user_token']; | | 645: | | | 646: | $data['header'] = $this->load->controller('common/header'); | | 647: | $data['column_left'] = $this->load->controller('common/column_left'); | | 648: | $data['footer'] = $this->load->controller('common/footer'); | | 649: | | | 650: | $this->response->setOutput($this->load->view('customer/customer_form', $data)); | | 651: | } | | 652: | | | 653: | /** | | 654: | * Save | | 655: | * | | 656: | * @return void | | 657: | */ | | 658: | public function save(): void { | | 659: | $this->load->language('customer/customer'); | | 660: | | | 661: | $json = []; | | 662: | | | 663: | if (!$this->user->hasPermission('modify', 'customer/customer')) { | | 664: | $json['error']['warning'] = $this->language->get('error_permission'); | | 665: | } | | 666: | | | 667: | if (!oc_validate_length($this->request->post['firstname'], 1, 32)) { | | 668: | $json['error']['firstname'] = $this->language->get('error_firstname'); | | 669: | } | | 670: | | | 671: | if (!oc_validate_length($this->request->post['lastname'], 1, 32)) { | | 672: | $json['error']['lastname'] = $this->language->get('error_lastname'); | | 673: | } | | 674: | | | 675: | if ((oc_strlen($this->request->post['email']) > 96) || !filter_var($this->request->post['email'], FILTER_VALIDATE_EMAIL)) { | | 676: | $json['error']['email'] = $this->language->get('error_email'); | | 677: | } | | 678: | | | 679: | $this->load->model('customer/customer'); | | 680: | | | 681: | $customer_info = $this->model_customer_customer->getCustomerByEmail($this->request->post['email']); | | 682: | | | 683: | if (!$this->request->post['customer_id']) { | | 684: | if ($customer_info) { | | 685: | $json['error']['warning'] = $this->language->get('error_exists'); | | 686: | } | | 687: | } else { | | 688: | if ($customer_info && ($this->request->post['customer_id'] != $customer_info['customer_id'])) { | | 689: | $json['error']['warning'] = $this->language->get('error_exists'); | | 690: | } | | 691: | } | | 692: | | | 693: | if ($this->config->get('config_telephone_required') && (oc_strlen($this->request->post['telephone']) < 3) || (oc_strlen($this->request->post['telephone']) > 32)) { | | 694: | $json['error']['telephone'] = $this->language->get('error_telephone'); | | 695: | } | | 696: | | | 697: | // Custom field validation | | 698: | $this->load->model('customer/custom_field'); | | 699: | | | 700: | $filter_data = [ | | 701: | 'filter_location' => 'account', | | 702: | 'filter_customer_group_id' => $this->request->post['customer_group_id'], | | 703: | 'filter_status' => 1 | | 704: | ]; | | 705: | | | 706: | $custom_fields = $this->model_customer_custom_field->getCustomFields($filter_data); | | 707: | | | 708: | foreach ($custom_fields as $custom_field) { | | 709: | if ($custom_field['required'] && empty($this->request->post['custom_field'][$custom_field['custom_field_id']])) { | | 710: | $json['error']['custom_field_' . $custom_field['custom_field_id']] = sprintf($this->language->get('error_custom_field'), $custom_field['name']); | | 711: | } elseif (($custom_field['type'] == 'text') && !empty($custom_field['validation']) && !preg_match(html_entity_decode($custom_field['validation'], ENT_QUOTES, 'UTF-8'), $this->request->post['custom_field'][$custom_field['custom_field_id']])) { | | 712: | $json['error']['custom_field_' . $custom_field['custom_field_id']] = sprintf($this->language->get('error_regex'), $custom_field['name']); | | 713: | } | | 714: | } | | 715: | | | 716: | if ($this->request->post['password'] || (!isset($this->request->post['customer_id']))) { | | 717: | if ((oc_strlen(html_entity_decode($this->request->post['password'], ENT_QUOTES, 'UTF-8')) < 6) || (oc_strlen(html_entity_decode($this->request->post['password'], ENT_QUOTES, 'UTF-8')) > 40)) { | | 718: | $json['error']['password'] = $this->language->get('error_password'); | | 719: | } | | 720: | | | 721: | if ($this->request->post['password'] != $this->request->post['confirm']) { | | 722: | $json['error']['confirm'] = $this->language->get('error_confirm'); | | 723: | } | | 724: | } | | 725: | | | 726: | if (isset($json['error']) && !isset($json['error']['warning'])) { | | 727: | $json['error']['warning'] = $this->language->get('error_warning'); | | 728: | } | | 729: | | | 730: | if (!$json) { | | 731: | if (!$this->request->post['customer_id']) { | | 732: | $json['customer_id'] = $this->model_customer_customer->addCustomer($this->request->post); | | 733: | } else { | | 734: | $this->model_customer_customer->editCustomer($this->request->post['customer_id'], $this->request->post); | | 735: | } | | 736: | | | 737: | $json['success'] = $this->language->get('text_success'); | | 738: | } | | 739: | | | 740: | $this->response->addHeader('Content-Type: application/json'); | | 741: | $this->response->setOutput(json_encode($json)); | | 742: | } | | 743: | | | 744: | /** | | 745: | * Unlock | | 746: | * | | 747: | * @return void | | 748: | */ | | 749: | public function unlock(): void { | | 750: | $this->load->language('customer/customer'); | | 751: | | | 752: | $json = []; | | 753: | | | 754: | if (!$this->user->hasPermission('modify', 'customer/customer')) { | | 755: | $json['error'] = $this->language->get('error_permission'); | | 756: | } | | 757: | | | 758: | if (empty($this->request->get['email'])) { | | 759: | $json['error'] = $this->language->get('error_email'); | | 760: | } | | 761: | | | 762: | if (!$json) { | | 763: | $this->load->model('customer/customer'); | | 764: | | | 765: | $this->model_customer_customer->deleteLoginAttempts($this->request->get['email']); | | 766: | | | 767: | $json['success'] = $this->language->get('text_success'); | | 768: | } | | 769: | | | 770: | $this->response->addHeader('Content-Type: application/json'); | | 771: | $this->response->setOutput(json_encode($json)); | | 772: | } | | 773: | | | 774: | /** | | 775: | * Delete | | 776: | * | | 777: | * @return void | | 778: | */ | | 779: | public function delete(): void { | | 780: | $this->load->language('customer/customer'); | | 781: | | | 782: | $json = []; | | 783: | | | 784: | if (isset($this->request->post['selected'])) { | | 785: | $selected = $this->request->post['selected']; | | 786: | } else { | | 787: | $selected = []; | | 788: | } | | 789: | | | 790: | if (!$this->user->hasPermission('modify', 'customer/customer')) { | | 791: | $json['error'] = $this->language->get('error_permission'); | | 792: | } | | 793: | | | 794: | if (!$json) { | | 795: | $this->load->model('customer/customer'); | | 796: | | | 797: | foreach ($selected as $customer_id) { | | 798: | $this->model_customer_customer->deleteCustomer($customer_id); | | 799: | } | | 800: | | | 801: | $json['success'] = $this->language->get('text_success'); | | 802: | } | | 803: | | | 804: | $this->response->addHeader('Content-Type: application/json'); | | 805: | $this->response->setOutput(json_encode($json)); | | 806: | } | | 807: | | | 808: | /** | | 809: | * Login | | 810: | * | | 811: | * @return \Opencart\System\Engine\Action|null | | 812: | */ | | 813: | public function login(): ?\Opencart\System\Engine\Action { | | 814: | if (isset($this->request->get['customer_id'])) { | | 815: | $customer_id = (int)$this->request->get['customer_id']; | | 816: | } else { | | 817: | $customer_id = 0; | | 818: | } | | 819: | | | 820: | $this->load->model('customer/customer'); | | 821: | | | 822: | $customer_info = $this->model_customer_customer->getCustomer($customer_id); | | 823: | | | 824: | if ($customer_info) { | | 825: | // Create token to login with | | 826: | $token = oc_token(64); | | 827: | | | 828: | $this->model_customer_customer->editToken($customer_id, $token); | | 829: | | | 830: | if (isset($this->request->get['store_id'])) { | | 831: | $store_id = (int)$this->request->get['store_id']; | | 832: | } else { | | 833: | $store_id = 0; | | 834: | } | | 835: | | | 836: | $this->load->model('setting/store'); | | 837: | | | 838: | $store_info = $this->model_setting_store->getStore($store_id); | | 839: | | | 840: | if ($store_info) { | | 841: | $this->response->redirect($store_info['url'] . 'index.php?route=account/login.token&email=' . urlencode($customer_info['email']) . '&login_token=' . $token); | | 842: | } else { | | 843: | $this->response->redirect(HTTP_CATALOG . 'index.php?route=account/login.token&email=' . urlencode($customer_info['email']) . '&login_token=' . $token); | | 844: | } | | 845: | | | 846: | return null; | | 847: | } else { | | 848: | return new \Opencart\System\Engine\Action('error/not_found'); | | 849: | } | | 850: | } | | 851: | | | 852: | /** | | 853: | * Payment | | 854: | * | | 855: | * @return void | | 856: | */ | | 857: | public function payment(): void { | | 858: | $this->load->language('customer/customer'); | | 859: | | | 860: | $this->response->setOutput($this->getPayment()); | | 861: | } | | 862: | | | 863: | /** | | 864: | * Get Payment | | 865: | * | | 866: | * @return string | | 867: | */ | | 868: | private function getPayment(): string { | | 869: | if (isset($this->request->get['customer_id'])) { | | 870: | $customer_id = (int)$this->request->get['customer_id']; | | 871: | } else { | | 872: | $customer_id = 0; | | 873: | } | | 874: | | | 875: | if (isset($this->request->get['page']) && $this->request->get['route'] == 'customer/customer.payment') { | | 876: | $page = (int)$this->request->get['page']; | | 877: | } else { | | 878: | $page = 1; | | 879: | } | | 880: | | | 881: | $limit = 10; | | 882: | | | 883: | $data['payment_methods'] = []; | | 884: | | | 885: | $this->load->model('sale/subscription'); | | 886: | | | 887: | $results = $this->model_sale_subscription->getSubscriptions(['filter_customer_id' => $customer_id]); | | 888: | | | 889: | foreach ($results as $result) { | | 890: | if (isset($result['image'])) { | | 891: | $image = DIR_IMAGE . 'payment/' . $result['image']; | | 892: | } else { | | 893: | $image = ''; | | 894: | } | | 895: | | | 896: | $data['payment_methods'][] = [ | | 897: | 'customer_payment_id' => $result['customer_payment_id'], | | 898: | 'name' => $result['name'], | | 899: | 'image' => $image, | | 900: | 'type' => $result['type'], | | 901: | 'status' => $result['status'], | | 902: | 'date_expire' => date($this->language->get('date_format_short'), strtotime($result['date_expire'])), | | 903: | 'delete' => $this->url->link('customer/customer.deletePayment', 'user_token=' . $this->session->data['user_token'] . '&customer_payment_id=' . $result['customer_payment_id']) | | 904: | ]; | | 905: | } | | 906: | | | 907: | $payment_total = $this->model_sale_subscription->getTotalSubscriptions(['filter_customer_id' => $customer_id]); | | 908: | | | 909: | $data['pagination'] = $this->load->controller('common/pagination', [ | | 910: | 'total' => $payment_total, | | 911: | 'page' => $page, | | 912: | 'limit' => $limit, | | 913: | 'url' => $this->url->link('customer/customer.payment', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . $customer_id . '&page={page}') | | 914: | ]); | | 915: | | | 916: | $data['results'] = sprintf($this->language->get('text_pagination'), ($payment_total) ? (($page - 1) * $limit) + 1 : 0, ((($page - 1) * $limit) > ($payment_total - $limit)) ? $payment_total : ((($page - 1) * $limit) + $limit), $payment_total, ceil($payment_total / $limit)); | | 917: | | | 918: | return $this->load->view('customer/customer_payment', $data); | | 919: | } | | 920: | | | 921: | /** | | 922: | * Delete Payment | | 923: | * | | 924: | * @return void | | 925: | */ | | 926: | public function deletePayment(): void { | | 927: | $this->load->language('customer/customer'); | | 928: | | | 929: | $json = []; | | 930: | | | 931: | if (isset($this->request->get['customer_payment_id'])) { | | 932: | $customer_payment_id = (int)$this->request->get['customer_payment_id']; | | 933: | } else { | | 934: | $customer_payment_id = 0; | | 935: | } | | 936: | | | 937: | if (!$this->user->hasPermission('modify', 'customer/customer')) { | | 938: | $json['error'] = $this->language->get('error_permission'); | | 939: | } | | 940: | | | 941: | if (!$json) { | | 942: | $this->load->model('sale/subscription'); | | 943: | | | 944: | $this->model_sale_subscription->deleteSubscriptionByCustomerPaymentId($customer_payment_id); | | 945: | | | 946: | $json['success'] = $this->language->get('text_success'); | | 947: | } | | 948: | | | 949: | $this->response->addHeader('Content-Type: application/json'); | | 950: | $this->response->setOutput(json_encode($json)); | | 951: | } | | 952: | | | 953: | /** | | 954: | * History | | 955: | * | | 956: | * @return void | | 957: | */ | | 958: | public function history(): void { | | 959: | $this->load->language('customer/customer'); | | 960: | | | 961: | $this->response->setOutput($this->getHistory()); | | 962: | } | | 963: | | | 964: | /** | | 965: | * Get History | | 966: | * | | 967: | * @return string | | 968: | */ | | 969: | public function getHistory(): string { | | 970: | if (isset($this->request->get['customer_id'])) { | | 971: | $customer_id = (int)$this->request->get['customer_id']; | | 972: | } else { | | 973: | $customer_id = 0; | | 974: | } | | 975: | | | 976: | if (isset($this->request->get['page']) && $this->request->get['route'] == 'customer/customer.history') { | | 977: | $page = (int)$this->request->get['page']; | | 978: | } else { | | 979: | $page = 1; | | 980: | } | | 981: | | | 982: | $limit = 10; | | 983: | | | 984: | $data['histories'] = []; | | 985: | | | 986: | $this->load->model('customer/customer'); | | 987: | | | 988: | $results = $this->model_customer_customer->getHistories($customer_id, ($page - 1) * $limit, $limit); | | 989: | | | 990: | foreach ($results as $result) { | | 991: | $data['histories'][] = [ | | 992: | 'comment' => nl2br($result['comment']), | | 993: | 'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])) | | 994: | ]; | | 995: | } | | 996: | | | 997: | $history_total = $this->model_customer_customer->getTotalHistories($customer_id); | | 998: | | | 999: | $data['pagination'] = $this->load->controller('common/pagination', [ | | 1000: | 'total' => $history_total, | | 1001: | 'page' => $page, | | 1002: | 'limit' => $limit, | | 1003: | 'url' => $this->url->link('customer/customer.history', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . $customer_id . '&page={page}') | | 1004: | ]); | | 1005: | | | 1006: | $data['results'] = sprintf($this->language->get('text_pagination'), ($history_total) ? (($page - 1) * $limit) + 1 : 0, ((($page - 1) * $limit) > ($history_total - $limit)) ? $history_total : ((($page - 1) * $limit) + $limit), $history_total, ceil($history_total / $limit)); | | 1007: | | | 1008: | return $this->load->view('customer/customer_history', $data); | | 1009: | } | | 1010: | | | 1011: | /** | | 1012: | * Add History | | 1013: | * | | 1014: | * @return void | | 1015: | */ | | 1016: | public function addHistory(): void { | | 1017: | $this->load->language('customer/customer'); | | 1018: | | | 1019: | $json = []; | | 1020: | | | 1021: | if (isset($this->request->get['customer_id'])) { | | 1022: | $customer_id = (int)$this->request->get['customer_id']; | | 1023: | } else { | | 1024: | $customer_id = 0; | | 1025: | } | | 1026: | | | 1027: | if (!$this->user->hasPermission('modify', 'customer/customer')) { | | 1028: | $json['error'] = $this->language->get('error_permission'); | | 1029: | } | | 1030: | | | 1031: | $this->load->model('customer/customer'); | | 1032: | | | 1033: | $customer_info = $this->model_customer_customer->getCustomer($customer_id); | | 1034: | | | 1035: | if (!$customer_info) { | | 1036: | $json['error'] = $this->language->get('error_customer'); | | 1037: | } | | 1038: | | | 1039: | if (!$json) { | | 1040: | $this->model_customer_customer->addHistory($customer_id, $this->request->post['comment']); | | 1041: | | | 1042: | $json['success'] = $this->language->get('text_success'); | | 1043: | } | | 1044: | | | 1045: | $this->response->addHeader('Content-Type: application/json'); | | 1046: | $this->response->setOutput(json_encode($json)); | | 1047: | } | | 1048: | | | 1049: | /** | | 1050: | * Transaction | | 1051: | * | | 1052: | * @return void | | 1053: | */ | | 1054: | public function transaction(): void { | | 1055: | $this->load->language('customer/customer'); | | 1056: | | | 1057: | $this->response->setOutput($this->getTransaction()); | | 1058: | } | | 1059: | | | 1060: | /** | | 1061: | * Get Transaction | | 1062: | * | | 1063: | * @return string | | 1064: | */ | | 1065: | public function getTransaction(): string { | | 1066: | if (isset($this->request->get['customer_id'])) { | | 1067: | $customer_id = (int)$this->request->get['customer_id']; | | 1068: | } else { | | 1069: | $customer_id = 0; | | 1070: | } | | 1071: | | | 1072: | if (isset($this->request->get['page']) && $this->request->get['route'] == 'customer/customer.transaction') { | | 1073: | $page = (int)$this->request->get['page']; | | 1074: | } else { | | 1075: | $page = 1; | | 1076: | } | | 1077: | | | 1078: | $limit = 10; | | 1079: | | | 1080: | $data['transactions'] = []; | | 1081: | | | 1082: | $this->load->model('customer/customer'); | | 1083: | | | 1084: | $results = $this->model_customer_customer->getTransactions($customer_id, ($page - 1) * $limit, $limit); | | 1085: | | | 1086: | foreach ($results as $result) { | | 1087: | $data['transactions'][] = [ | | 1088: | 'amount' => $this->currency->format($result['amount'], $this->config->get('config_currency')), | | 1089: | 'description' => $result['description'], | | 1090: | 'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])) | | 1091: | ]; | | 1092: | } | | 1093: | | | 1094: | $data['balance'] = $this->currency->format($this->model_customer_customer->getTransactionTotal($customer_id), $this->config->get('config_currency')); | | 1095: | | | 1096: | $transaction_total = $this->model_customer_customer->getTotalTransactions($customer_id); | | 1097: | | | 1098: | $data['pagination'] = $this->load->controller('common/pagination', [ | | 1099: | 'total' => $transaction_total, | | 1100: | 'page' => $page, | | 1101: | 'limit' => $limit, | | 1102: | 'url' => $this->url->link('customer/customer.transaction', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . $customer_id . '&page={page}') | | 1103: | ]); | | 1104: | | | 1105: | $data['results'] = sprintf($this->language->get('text_pagination'), ($transaction_total) ? (($page - 1) * $limit) + 1 : 0, ((($page - 1) * $limit) > ($transaction_total - $limit)) ? $transaction_total : ((($page - 1) * $limit) + $limit), $transaction_total, ceil($transaction_total / $limit)); | | 1106: | | | 1107: | return $this->load->view('customer/customer_transaction', $data); | | 1108: | } | | 1109: | | | 1110: | /** | | 1111: | * Add Transaction | | 1112: | * | | 1113: | * @return void | | 1114: | */ | | 1115: | public function addTransaction(): void { | | 1116: | $this->load->language('customer/customer'); | | 1117: | | | 1118: | $json = []; | | 1119: | | | 1120: | if (isset($this->request->get['customer_id'])) { | | 1121: | $customer_id = (int)$this->request->get['customer_id']; | | 1122: | } else { | | 1123: | $customer_id = 0; | | 1124: | } | | 1125: | | | 1126: | if (!$this->user->hasPermission('modify', 'customer/customer')) { | | 1127: | $json['error'] = $this->language->get('error_permission'); | | 1128: | } | | 1129: | | | 1130: | $this->load->model('customer/customer'); | | 1131: | | | 1132: | $customer_info = $this->model_customer_customer->getCustomer($customer_id); | | 1133: | | | 1134: | if (!$customer_info) { | | 1135: | $json['error'] = $this->language->get('error_customer'); | | 1136: | } | | 1137: | | | 1138: | if (!$json) { | | 1139: | $this->load->model('customer/customer'); | | 1140: | | | 1141: | $this->model_customer_customer->addTransaction($customer_id, (string)$this->request->post['description'], (float)$this->request->post['amount']); | | 1142: | | | 1143: | $json['success'] = $this->language->get('text_success'); | | 1144: | } | | 1145: | | | 1146: | $this->response->addHeader('Content-Type: application/json'); | | 1147: | $this->response->setOutput(json_encode($json)); | | 1148: | } | | 1149: | | | 1150: | /** | | 1151: | * Reward | | 1152: | * | | 1153: | * @return void | | 1154: | */ | | 1155: | public function reward(): void { | | 1156: | $this->load->language('customer/customer'); | | 1157: | | | 1158: | $this->response->setOutput($this->getReward()); | | 1159: | } | | 1160: | | | 1161: | /** | | 1162: | * Get Reward | | 1163: | * | | 1164: | * @return string | | 1165: | */ | | 1166: | public function getReward(): string { | | 1167: | if (isset($this->request->get['customer_id'])) { | | 1168: | $customer_id = (int)$this->request->get['customer_id']; | | 1169: | } else { | | 1170: | $customer_id = 0; | | 1171: | } | | 1172: | | | 1173: | if (isset($this->request->get['page']) && $this->request->get['route'] == 'customer/customer.reward') { | | 1174: | $page = (int)$this->request->get['page']; | | 1175: | } else { | | 1176: | $page = 1; | | 1177: | } | | 1178: | | | 1179: | $limit = 10; | | 1180: | | | 1181: | $data['rewards'] = []; | | 1182: | | | 1183: | $this->load->model('customer/customer'); | | 1184: | | | 1185: | $results = $this->model_customer_customer->getRewards($customer_id, ($page - 1) * $limit, $limit); | | 1186: | | | 1187: | foreach ($results as $result) { | | 1188: | $data['rewards'][] = [ | | 1189: | 'points' => $result['points'], | | 1190: | 'description' => $result['description'], | | 1191: | 'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])) | | 1192: | ]; | | 1193: | } | | 1194: | | | 1195: | $data['balance'] = $this->model_customer_customer->getRewardTotal($customer_id); | | 1196: | | | 1197: | $reward_total = $this->model_customer_customer->getTotalRewards($customer_id); | | 1198: | | | 1199: | $data['pagination'] = $this->load->controller('common/pagination', [ | | 1200: | 'total' => $reward_total, | | 1201: | 'page' => $page, | | 1202: | 'limit' => $limit, | | 1203: | 'url' => $this->url->link('customer/customer.reward', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . $customer_id . '&page={page}') | | 1204: | ]); | | 1205: | | | 1206: | $data['results'] = sprintf($this->language->get('text_pagination'), ($reward_total) ? (($page - 1) * $limit) + 1 : 0, ((($page - 1) * $limit) > ($reward_total - $limit)) ? $reward_total : ((($page - 1) * $limit) + $limit), $reward_total, ceil($reward_total / $limit)); | | 1207: | | | 1208: | return $this->load->view('customer/customer_reward', $data); | | 1209: | } | | 1210: | | | 1211: | /** | | 1212: | * Add Reward | | 1213: | * | | 1214: | * @return void | | 1215: | */ | | 1216: | public function addReward(): void { | | 1217: | $this->load->language('customer/customer'); | | 1218: | | | 1219: | $json = []; | | 1220: | | | 1221: | if (isset($this->request->get['customer_id'])) { | | 1222: | $customer_id = (int)$this->request->get['customer_id']; | | 1223: | } else { | | 1224: | $customer_id = 0; | | 1225: | } | | 1226: | | | 1227: | if (!$this->user->hasPermission('modify', 'customer/customer')) { | | 1228: | $json['error'] = $this->language->get('error_permission'); | | 1229: | } | | 1230: | | | 1231: | $this->load->model('customer/customer'); | | 1232: | | | 1233: | $customer_info = $this->model_customer_customer->getCustomer($customer_id); | | 1234: | | | 1235: | if (!$customer_info) { | | 1236: | $json['error'] = $this->language->get('error_customer'); | | 1237: | } | | 1238: | | | 1239: | if (!$json) { | | 1240: | $this->load->model('customer/customer'); | | 1241: | | | 1242: | $this->model_customer_customer->addReward($customer_id, (string)$this->request->post['description'], (int)$this->request->post['points']); | | 1243: | | | 1244: | $json['success'] = $this->language->get('text_success'); | | 1245: | } | | 1246: | | | 1247: | $this->response->addHeader('Content-Type: application/json'); | | 1248: | $this->response->setOutput(json_encode($json)); | | 1249: | } | | 1250: | | | 1251: | /** | | 1252: | * Ip | | 1253: | * | | 1254: | * @return void | | 1255: | */ | | 1256: | public function ip(): void { | | 1257: | $this->load->language('customer/customer'); | | 1258: | | | 1259: | $this->response->setOutput($this->getIp()); | | 1260: | } | | 1261: | | | 1262: | /** | | 1263: | * Get Ip | | 1264: | * | | 1265: | * @return string | | 1266: | */ | | 1267: | public function getIp(): string { | | 1268: | if (isset($this->request->get['customer_id'])) { | | 1269: | $customer_id = (int)$this->request->get['customer_id']; | | 1270: | } else { | | 1271: | $customer_id = 0; | | 1272: | } | | 1273: | | | 1274: | if (isset($this->request->get['page']) && $this->request->get['route'] == 'customer/customer.ip') { | | 1275: | $page = (int)$this->request->get['page']; | | 1276: | } else { | | 1277: | $page = 1; | | 1278: | } | | 1279: | | | 1280: | $limit = 10; | | 1281: | | | 1282: | $data['ips'] = []; | | 1283: | | | 1284: | $this->load->model('customer/customer'); | | 1285: | $this->load->model('setting/store'); | | 1286: | | | 1287: | $results = $this->model_customer_customer->getIps($customer_id, ($page - 1) * $limit, $limit); | | 1288: | | | 1289: | foreach ($results as $result) { | | 1290: | $store_info = $this->model_setting_store->getStore($result['store_id']); | | 1291: | | | 1292: | if ($store_info) { | | 1293: | $store = $store_info['name']; | | 1294: | } elseif (!$result['store_id']) { | | 1295: | $store = $this->config->get('config_name'); | | 1296: | } else { | | 1297: | $store = ''; | | 1298: | } | | 1299: | | | 1300: | $data['ips'][] = [ | | 1301: | 'ip' => $result['ip'], | | 1302: | 'account' => $this->model_customer_customer->getTotalCustomersByIp($result['ip']), | | 1303: | 'store' => $store, | | 1304: | 'country' => $result['country'], | | 1305: | 'date_added' => date($this->language->get('datetime_format'), strtotime($result['date_added'])), | | 1306: | 'filter_ip' => $this->url->link('customer/customer', 'user_token=' . $this->session->data['user_token'] . '&filter_ip=' . $result['ip']) | | 1307: | ]; | | 1308: | } | | 1309: | | | 1310: | $ip_total = $this->model_customer_customer->getTotalIps($customer_id); | | 1311: | | | 1312: | $data['pagination'] = $this->load->controller('common/pagination', [ | | 1313: | 'total' => $ip_total, | | 1314: | 'page' => $page, | | 1315: | 'limit' => $limit, | | 1316: | 'url' => $this->url->link('customer/customer.ip', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . $customer_id . '&page={page}') | | 1317: | ]); | | 1318: | | | 1319: | $data['results'] = sprintf($this->language->get('text_pagination'), ($ip_total) ? (($page - 1) * $limit) + 1 : 0, ((($page - 1) * $limit) > ($ip_total - $limit)) ? $ip_total : ((($page - 1) * $limit) + $limit), $ip_total, ceil($ip_total / $limit)); | | 1320: | | | 1321: | return $this->load->view('customer/customer_ip', $data); | | 1322: | } | | 1323: | | | 1324: | /** | | 1325: | * Authorize | | 1326: | * | | 1327: | * @return void | | 1328: | */ | | 1329: | public function authorize(): void { | | 1330: | $this->load->language('customer/customer'); | | 1331: | | | 1332: | $this->response->setOutput($this->getAuthorize()); | | 1333: | } | | 1334: | | | 1335: | /** | | 1336: | * Get Authorize | | 1337: | * | | 1338: | * @return string | | 1339: | */ | | 1340: | public function getAuthorize(): string { | | 1341: | if (isset($this->request->get['customer_id'])) { | | 1342: | $customer_id = (int)$this->request->get['customer_id']; | | 1343: | } else { | | 1344: | $customer_id = 0; | | 1345: | } | | 1346: | | | 1347: | if (isset($this->request->get['page']) && $this->request->get['route'] == 'customer/customer.login') { | | 1348: | $page = (int)$this->request->get['page']; | | 1349: | } else { | | 1350: | $page = 1; | | 1351: | } | | 1352: | | | 1353: | $limit = 10; | | 1354: | | | 1355: | $data['authorizes'] = []; | | 1356: | | | 1357: | $this->load->model('customer/customer'); | | 1358: | | | 1359: | $results = $this->model_customer_customer->getAuthorizes($customer_id, ($page - 1) * $limit, $limit); | | 1360: | | | 1361: | foreach ($results as $result) { | | 1362: | $data['authorizes'][] = [ | | 1363: | 'token' => $result['token'], | | 1364: | 'ip' => $result['ip'], | | 1365: | 'user_agent' => $result['user_agent'], | | 1366: | 'status' => $result['status'] ? $this->language->get('text_enabled') : $this->language->get('text_disabled'), | | 1367: | 'total' => $result['total'], | | 1368: | 'date_added' => date($this->language->get('datetime_format'), strtotime($result['date_added'])), | | 1369: | 'delete' => $this->url->link('customer/customer.deleteAuthorize', 'user_token=' . $this->session->data['user_token'] . '&user_authorize_id=' . $result['user_authorize_id']) | | 1370: | ]; | | 1371: | } | | 1372: | | | 1373: | $authorize_total = $this->model_customer_customer->getTotalAuthorizes($customer_id); | | 1374: | | | 1375: | $data['pagination'] = $this->load->controller('common/pagination', [ | | 1376: | 'total' => $authorize_total, | | 1377: | 'page' => $page, | | 1378: | 'limit' => $limit, | | 1379: | 'url' => $this->url->link('customer/customer.authorize', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . $customer_id . '&page={page}') | | 1380: | ]); | | 1381: | | | 1382: | $data['results'] = sprintf($this->language->get('text_pagination'), ($authorize_total) ? (($page - 1) * $limit) + 1 : 0, ((($page - 1) * $limit) > ($authorize_total - $limit)) ? $authorize_total : ((($page - 1) * $limit) + $limit), $authorize_total, ceil($authorize_total / $limit)); | | 1383: | | | 1384: | return $this->load->view('customer/customer_authorize', $data); | | 1385: | } | | 1386: | | | 1387: | /** | | 1388: | * Delete Authorize | | 1389: | * | | 1390: | * @return void | | 1391: | */ | | 1392: | public function deleteAuthorize(): void { | | 1393: | $this->load->language('customer/customer'); | | 1394: | | | 1395: | $json = []; | | 1396: | | | 1397: | if (isset($this->request->get['customer_authorize_id'])) { | | 1398: | $customer_authorize_id = (int)$this->request->get['customer_authorize_id']; | | 1399: | } else { | | 1400: | $customer_authorize_id = 0; | | 1401: | } | | 1402: | | | 1403: | if (isset($this->request->cookie['authorize'])) { | | 1404: | $token = $this->request->cookie['authorize']; | | 1405: | } else { | | 1406: | $token = ''; | | 1407: | } | | 1408: | | | 1409: | if (!$this->user->hasPermission('modify', 'customer/customer')) { | | 1410: | $json['error'] = $this->language->get('error_permission'); | | 1411: | } | | 1412: | | | 1413: | $this->load->model('user/user'); | | 1414: | | | 1415: | $authorize_info = $this->model_user_user->getAuthorize($customer_authorize_id); | | 1416: | | | 1417: | if (!$authorize_info) { | | 1418: | $json['error'] = $this->language->get('error_authorize'); | | 1419: | } | | 1420: | | | 1421: | if (!$json) { | | 1422: | $this->load->model('customer/customer'); | | 1423: | | | 1424: | $this->model_customer_customer->deleteAuthorizes($authorize_info['customer_id'], $customer_authorize_id); | | 1425: | | | 1426: | $json['success'] = $this->language->get('text_success'); | | 1427: | } | | 1428: | | | 1429: | $this->response->addHeader('Content-Type: application/json'); | | 1430: | $this->response->setOutput(json_encode($json)); | | 1431: | } | | 1432: | | | 1433: | /** | | 1434: | * Autocomplete | | 1435: | * | | 1436: | * @return void | | 1437: | */ | | 1438: | public function autocomplete(): void { | | 1439: | $json = []; | | 1440: | | | 1441: | if (isset($this->request->get['filter_name']) || isset($this->request->get['filter_email'])) { | | 1442: | if (isset($this->request->get['filter_name'])) { | | 1443: | $filter_name = $this->request->get['filter_name']; | | 1444: | } else { | | 1445: | $filter_name = ''; | | 1446: | } | | 1447: | | | 1448: | if (isset($this->request->get['filter_email'])) { | | 1449: | $filter_email = $this->request->get['filter_email']; | | 1450: | } else { | | 1451: | $filter_email = ''; | | 1452: | } | | 1453: | | | 1454: | $filter_data = [ | | 1455: | 'filter_name' => $filter_name, | | 1456: | 'filter_email' => $filter_email, | | 1457: | 'start' => 0, | | 1458: | 'limit' => 5 | | 1459: | ]; | | 1460: | | | 1461: | $this->load->model('customer/customer'); | | 1462: | | | 1463: | $results = $this->model_customer_customer->getCustomers($filter_data); | | 1464: | | | 1465: | foreach ($results as $result) { | | 1466: | $json[] = [ | | 1467: | 'customer_id' => $result['customer_id'], | | 1468: | 'customer_group_id' => $result['customer_group_id'], | | 1469: | 'name' => strip_tags(html_entity_decode($result['name'], ENT_QUOTES, 'UTF-8')), | | 1470: | 'customer_group' => $result['customer_group'], | | 1471: | 'firstname' => $result['firstname'], | | 1472: | 'lastname' => $result['lastname'], | | 1473: | 'email' => $result['email'], | | 1474: | 'telephone' => $result['telephone'], | | 1475: | 'custom_field' => $result['custom_field'], | | 1476: | 'address' => $this->model_customer_customer->getAddresses($result['customer_id']) | | 1477: | ]; | | 1478: | } | | 1479: | } | | 1480: | | | 1481: | $sort_order = []; | | 1482: | | | 1483: | foreach ($json as $key => $value) { | | 1484: | $sort_order[$key] = $value['name']; | | 1485: | } | | 1486: | | | 1487: | array_multisort($sort_order, SORT_ASC, $json); | | 1488: | | | 1489: | $this->response->addHeader('Content-Type: application/json'); | | 1490: | $this->response->setOutput(json_encode($json)); | | 1491: | } | | 1492: | | | 1493: | /** | | 1494: | * Customfield | | 1495: | * | | 1496: | * @return void | | 1497: | */ | | 1498: | public function customfield(): void { | | 1499: | $json = []; | | 1500: | | | 1501: | // Customer Group | | 1502: | if (isset($this->request->get['customer_group_id'])) { | | 1503: | $customer_group_id = (int)$this->request->get['customer_group_id']; | | 1504: | } else { | | 1505: | $customer_group_id = $this->config->get('config_customer_group_id'); | | 1506: | } | | 1507: | | | 1508: | $this->load->model('customer/custom_field'); | | 1509: | | | 1510: | $custom_fields = $this->model_customer_custom_field->getCustomFields(['filter_customer_group_id' => $customer_group_id]); | | 1511: | | | 1512: | foreach ($custom_fields as $custom_field) { | | 1513: | $json[] = [ | | 1514: | 'custom_field_id' => $custom_field['custom_field_id'], | | 1515: | 'required' => empty($custom_field['required']) || $custom_field['required'] == 0 ? false : true | | 1516: | ]; | | 1517: | } | | 1518: | | | 1519: | $this->response->addHeader('Content-Type: application/json'); | | 1520: | $this->response->setOutput(json_encode($json)); | | 1521: | } | | 1522: | } | | 1523: | |
OpenCart API API documentation generated by ApiGen dev-master