Back to Opencart

File catalog\controller\checkout\register.php

docs/api/source-catalog.controller.checkout.register.html

4.1.0.341.0 KB
Original Source

Namespaces

Classes

| 1: | <?php | | 2: | namespace Opencart\Catalog\Controller\Checkout; | | 3: | /** | | 4: | * Class Register | | 5: | * | | 6: | * @package Opencart\Catalog\Controller\Checkout | | 7: | */ | | 8: | class Register extends \Opencart\System\Engine\Controller { | | 9: | /** | | 10: | * @return string | | 11: | */ | | 12: | public function index(): string { | | 13: | $this->load->language('checkout/register'); | | 14: | | | 15: | $data['text_login'] = sprintf($this->language->get('text_login'), $this->url->link('account/login', 'language=' . $this->config->get('config_language') . '&redirect=' . urlencode($this->url->link('checkout/checkout', 'language=' . $this->config->get('config_language'), true)))); | | 16: | | | 17: | $data['entry_newsletter'] = sprintf($this->language->get('entry_newsletter'), $this->config->get('config_name')); | | 18: | | | 19: | $data['error_upload_size'] = sprintf($this->language->get('error_upload_size'), $this->config->get('config_file_max_size')); | | 20: | | | 21: | $data['config_checkout_payment_address'] = $this->config->get('config_checkout_payment_address'); | | 22: | $data['config_checkout_guest'] = ($this->config->get('config_checkout_guest') && !$this->config->get('config_customer_price') && !$this->cart->hasDownload() && !$this->cart->hasSubscription()); | | 23: | $data['config_file_max_size'] = ((int)$this->config->get('config_file_max_size') * 1024 * 1024); | | 24: | $data['config_telephone_display'] = $this->config->get('config_telephone_display'); | | 25: | $data['config_telephone_required'] = $this->config->get('config_telephone_required'); | | 26: | | | 27: | $data['shipping_required'] = $this->cart->hasShipping(); | | 28: | | | 29: | $this->session->data['upload_token'] = oc_token(32); | | 30: | | | 31: | $data['upload'] = $this->url->link('tool/upload', 'language=' . $this->config->get('config_language') . '&upload_token=' . $this->session->data['upload_token']); | | 32: | | | 33: | $data['customer_groups'] = []; | | 34: | | | 35: | if (is_array($this->config->get('config_customer_group_display'))) { | | 36: | $this->load->model('account/customer_group'); | | 37: | | | 38: | $customer_groups = $this->model_account_customer_group->getCustomerGroups(); | | 39: | | | 40: | foreach ($customer_groups as $customer_group) { | | 41: | if (in_array($customer_group['customer_group_id'], $this->config->get('config_customer_group_display'))) { | | 42: | $data['customer_groups'][] = $customer_group; | | 43: | } | | 44: | } | | 45: | } | | 46: | | | 47: | if (isset($this->session->data['customer']['customer_id'])) { | | 48: | $data['account'] = $this->session->data['customer']['customer_id']; | | 49: | } else { | | 50: | $data['account'] = 1; | | 51: | } | | 52: | | | 53: | if (isset($this->session->data['customer'])) { | | 54: | $data['customer_group_id'] = $this->session->data['customer']['customer_group_id']; | | 55: | $data['firstname'] = $this->session->data['customer']['firstname']; | | 56: | $data['lastname'] = $this->session->data['customer']['lastname']; | | 57: | $data['email'] = $this->session->data['customer']['email']; | | 58: | $data['telephone'] = $this->session->data['customer']['telephone']; | | 59: | $data['account_custom_field'] = $this->session->data['customer']['custom_field']; | | 60: | } else { | | 61: | $data['customer_group_id'] = $this->config->get('config_customer_group_id'); | | 62: | $data['firstname'] = ''; | | 63: | $data['lastname'] = ''; | | 64: | $data['email'] = ''; | | 65: | $data['telephone'] = ''; | | 66: | $data['account_custom_field'] = []; | | 67: | } | | 68: | | | 69: | if (isset($this->session->data['payment_address'])) { | | 70: | $data['payment_firstname'] = $this->session->data['payment_address']['firstname']; | | 71: | $data['payment_lastname'] = $this->session->data['payment_address']['lastname']; | | 72: | $data['payment_company'] = $this->session->data['payment_address']['company']; | | 73: | $data['payment_address_1'] = $this->session->data['payment_address']['address_1']; | | 74: | $data['payment_address_2'] = $this->session->data['payment_address']['address_2']; | | 75: | $data['payment_postcode'] = $this->session->data['payment_address']['postcode']; | | 76: | $data['payment_city'] = $this->session->data['payment_address']['city']; | | 77: | $data['payment_country_id'] = (int)$this->session->data['payment_address']['country_id']; | | 78: | $data['payment_zone_id'] = $this->session->data['payment_address']['zone_id']; | | 79: | $data['payment_custom_field'] = $this->session->data['payment_address']['custom_field']; | | 80: | } else { | | 81: | $data['payment_firstname'] = ''; | | 82: | $data['payment_lastname'] = ''; | | 83: | $data['payment_company'] = ''; | | 84: | $data['payment_address_1'] = ''; | | 85: | $data['payment_address_2'] = ''; | | 86: | $data['payment_postcode'] = ''; | | 87: | $data['payment_city'] = ''; | | 88: | $data['payment_country_id'] = $this->config->get('config_country_id'); | | 89: | $data['payment_zone_id'] = ''; | | 90: | $data['payment_custom_field'] = []; | | 91: | } | | 92: | | | 93: | if (isset($this->session->data['shipping_address']['address_id'])) { | | 94: | $data['shipping_firstname'] = $this->session->data['shipping_address']['firstname']; | | 95: | $data['shipping_lastname'] = $this->session->data['shipping_address']['lastname']; | | 96: | $data['shipping_company'] = $this->session->data['shipping_address']['company']; | | 97: | $data['shipping_address_1'] = $this->session->data['shipping_address']['address_1']; | | 98: | $data['shipping_address_2'] = $this->session->data['shipping_address']['address_2']; | | 99: | $data['shipping_postcode'] = $this->session->data['shipping_address']['postcode']; | | 100: | $data['shipping_city'] = $this->session->data['shipping_address']['city']; | | 101: | $data['shipping_country_id'] = (int)$this->session->data['shipping_address']['country_id']; | | 102: | $data['shipping_zone_id'] = $this->session->data['shipping_address']['zone_id']; | | 103: | $data['shipping_custom_field'] = $this->session->data['shipping_address']['custom_field']; | | 104: | } else { | | 105: | $data['shipping_firstname'] = ''; | | 106: | $data['shipping_lastname'] = ''; | | 107: | $data['shipping_company'] = ''; | | 108: | $data['shipping_address_1'] = ''; | | 109: | $data['shipping_address_2'] = ''; | | 110: | | | 111: | if (isset($this->session->data['shipping_address']['postcode'])) { | | 112: | $data['shipping_postcode'] = $this->session->data['shipping_address']['postcode']; | | 113: | } else { | | 114: | $data['shipping_postcode'] = ''; | | 115: | } | | 116: | | | 117: | $data['shipping_city'] = ''; | | 118: | | | 119: | if (isset($this->session->data['shipping_address']['country_id'])) { | | 120: | $data['shipping_country_id'] = $this->session->data['shipping_address']['country_id']; | | 121: | } else { | | 122: | $data['shipping_country_id'] = $this->config->get('config_country_id'); | | 123: | } | | 124: | | | 125: | if (isset($this->session->data['shipping_address']['zone_id'])) { | | 126: | $data['shipping_zone_id'] = $this->session->data['shipping_address']['zone_id']; | | 127: | } else { | | 128: | $data['shipping_zone_id'] = ''; | | 129: | } | | 130: | | | 131: | $data['shipping_custom_field'] = []; | | 132: | } | | 133: | | | 134: | $this->load->model('localisation/country'); | | 135: | | | 136: | $data['countries'] = $this->model_localisation_country->getCountries(); | | 137: | | | 138: | // Custom Fields | | 139: | $this->load->model('account/custom_field'); | | 140: | | | 141: | $data['custom_fields'] = $this->model_account_custom_field->getCustomFields(); | | 142: | | | 143: | // Captcha | | 144: | $this->load->model('setting/extension'); | | 145: | | | 146: | $extension_info = $this->model_setting_extension->getExtensionByCode('captcha', $this->config->get('config_captcha')); | | 147: | | | 148: | if ($extension_info && $this->config->get('captcha_' . $this->config->get('config_captcha') . '_status') && in_array('register', (array)$this->config->get('config_captcha_page'))) { | | 149: | $data['captcha'] = $this->load->controller('extension/' . $extension_info['extension'] . '/captcha/' . $extension_info['code']); | | 150: | } else { | | 151: | $data['captcha'] = ''; | | 152: | } | | 153: | | | 154: | $this->load->model('catalog/information'); | | 155: | | | 156: | $information_info = $this->model_catalog_information->getInformation($this->config->get('config_account_id')); | | 157: | | | 158: | if ($information_info) { | | 159: | $data['text_agree'] = sprintf($this->language->get('text_agree'), $this->url->link('information/information.info', 'language=' . $this->config->get('config_language') . '&information_id=' . $this->config->get('config_account_id')), $information_info['title']); | | 160: | } else { | | 161: | $data['text_agree'] = ''; | | 162: | } | | 163: | | | 164: | $data['language'] = $this->config->get('config_language'); | | 165: | | | 166: | return $this->load->view('checkout/register', $data); | | 167: | } | | 168: | | | 169: | /** | | 170: | * Save | | 171: | * | | 172: | * @return void | | 173: | */ | | 174: | public function save(): void { | | 175: | $this->load->language('checkout/register'); | | 176: | | | 177: | $json = []; | | 178: | | | 179: | $keys = [ | | 180: | 'account', | | 181: | 'customer_group_id', | | 182: | 'firstname', | | 183: | 'lastname', | | 184: | 'email', | | 185: | 'telephone', | | 186: | 'payment_company', | | 187: | 'payment_address_1', | | 188: | 'payment_address_2', | | 189: | 'payment_city', | | 190: | 'payment_postcode', | | 191: | 'payment_country_id', | | 192: | 'payment_zone_id', | | 193: | 'payment_custom_field', | | 194: | 'address_match', | | 195: | 'shipping_firstname', | | 196: | 'shipping_lastname', | | 197: | 'shipping_company', | | 198: | 'shipping_address_1', | | 199: | 'shipping_address_2', | | 200: | 'shipping_city', | | 201: | 'shipping_postcode', | | 202: | 'shipping_country_id', | | 203: | 'shipping_zone_id', | | 204: | 'shipping_custom_field', | | 205: | 'password', | | 206: | 'agree' | | 207: | ]; | | 208: | | | 209: | foreach ($keys as $key) { | | 210: | if (!isset($this->request->post[$key])) { | | 211: | $this->request->post[$key] = ''; | | 212: | } | | 213: | } | | 214: | | | 215: | // Force account requires subscript or is a downloadable product. | | 216: | if ($this->cart->hasDownload() || $this->cart->hasSubscription()) { | | 217: | $this->request->post['account'] = 1; | | 218: | } | | 219: | | | 220: | // Validate cart has products and has stock. | | 221: | if ((!$this->cart->hasProducts() && empty($this->session->data['vouchers'])) || (!$this->cart->hasStock() && !$this->config->get('config_stock_checkout'))) { | | 222: | $json['redirect'] = $this->url->link('checkout/cart', 'language=' . $this->config->get('config_language'), true); | | 223: | } | | 224: | | | 225: | // Validate minimum quantity requirements. | | 226: | $products = $this->cart->getProducts(); | | 227: | | | 228: | foreach ($products as $product) { | | 229: | if (!$product['minimum']) { | | 230: | $json['redirect'] = $this->url->link('checkout/cart', 'language=' . $this->config->get('config_language'), true); | | 231: | | | 232: | break; | | 233: | } | | 234: | } | | 235: | | | 236: | if (!$json) { | | 237: | // If not guest checkout disabled, login require price or cart has downloads | | 238: | if (!$this->request->post['account'] && (!$this->config->get('config_checkout_guest') || $this->config->get('config_customer_price'))) { | | 239: | $json['error']['warning'] = $this->language->get('error_guest'); | | 240: | } | | 241: | | | 242: | // Customer Group | | 243: | if ($this->request->post['customer_group_id']) { | | 244: | $customer_group_id = (int)$this->request->post['customer_group_id']; | | 245: | } else { | | 246: | $customer_group_id = (int)$this->config->get('config_customer_group_id'); | | 247: | } | | 248: | | | 249: | $this->load->model('account/customer_group'); | | 250: | | | 251: | $customer_group_info = $this->model_account_customer_group->getCustomerGroup($customer_group_id); | | 252: | | | 253: | if (!$customer_group_info || !in_array($customer_group_id, (array)$this->config->get('config_customer_group_display'))) { | | 254: | $json['error']['warning'] = $this->language->get('error_customer_group'); | | 255: | } | | 256: | | | 257: | if ((oc_strlen($this->request->post['firstname']) < 1) || (oc_strlen($this->request->post['firstname']) > 32)) { | | 258: | $json['error']['firstname'] = $this->language->get('error_firstname'); | | 259: | } | | 260: | | | 261: | if ((oc_strlen($this->request->post['lastname']) < 1) || (oc_strlen($this->request->post['lastname']) > 32)) { | | 262: | $json['error']['lastname'] = $this->language->get('error_lastname'); | | 263: | } | | 264: | | | 265: | if ((oc_strlen($this->request->post['email']) > 96) || !filter_var($this->request->post['email'], FILTER_VALIDATE_EMAIL)) { | | 266: | $json['error']['email'] = $this->language->get('error_email'); | | 267: | } | | 268: | | | 269: | $this->load->model('account/customer'); | | 270: | | | 271: | if ($this->request->post['account'] && $this->model_account_customer->getTotalCustomersByEmail($this->request->post['email'])) { | | 272: | $json['error']['warning'] = $this->language->get('error_exists'); | | 273: | } | | 274: | | | 275: | // Logged in, so add customer details | | 276: | if ($this->customer->isLogged()) { | | 277: | $customer_info = $this->model_account_customer->getCustomerByEmail($this->request->post['email']); | | 278: | | | 279: | if ($customer_info['customer_id'] != $this->customer->getId()) { | | 280: | $json['error']['warning'] = $this->language->get('error_exists'); | | 281: | } | | 282: | } | | 283: | | | 284: | if ($this->config->get('config_telephone_required') && (oc_strlen($this->request->post['telephone']) < 3) || (oc_strlen($this->request->post['telephone']) > 32)) { | | 285: | $json['error']['telephone'] = $this->language->get('error_telephone'); | | 286: | } | | 287: | | | 288: | // Custom field validation | | 289: | $this->load->model('account/custom_field'); | | 290: | | | 291: | $custom_fields = $this->model_account_custom_field->getCustomFields($customer_group_id); | | 292: | | | 293: | foreach ($custom_fields as $custom_field) { | | 294: | if ($custom_field['location'] == 'account') { | | 295: | if ($custom_field['required'] && empty($this->request->post['custom_field'][$custom_field['location']][$custom_field['custom_field_id']])) { | | 296: | $json['error']['custom_field_' . $custom_field['custom_field_id']] = sprintf($this->language->get('error_custom_field'), $custom_field['name']); | | 297: | } 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['location']][$custom_field['custom_field_id']])) { | | 298: | $json['error']['custom_field_' . $custom_field['custom_field_id']] = sprintf($this->language->get('error_regex'), $custom_field['name']); | | 299: | } | | 300: | } | | 301: | } | | 302: | | | 303: | if ($this->config->get('config_checkout_payment_address')) { | | 304: | if ((oc_strlen($this->request->post['payment_address_1']) < 3) || (oc_strlen($this->request->post['payment_address_1']) > 128)) { | | 305: | $json['error']['payment_address_1'] = $this->language->get('error_address_1'); | | 306: | } | | 307: | | | 308: | if ((oc_strlen($this->request->post['payment_city']) < 2) || (oc_strlen($this->request->post['payment_city']) > 128)) { | | 309: | $json['error']['payment_city'] = $this->language->get('error_city'); | | 310: | } | | 311: | | | 312: | $this->load->model('localisation/country'); | | 313: | | | 314: | $payment_country_info = $this->model_localisation_country->getCountry((int)$this->request->post['payment_country_id']); | | 315: | | | 316: | if ($payment_country_info && $payment_country_info['postcode_required'] && (oc_strlen($this->request->post['payment_postcode']) < 2 || oc_strlen($this->request->post['payment_postcode']) > 10)) { | | 317: | $json['error']['payment_postcode'] = $this->language->get('error_postcode'); | | 318: | } | | 319: | | | 320: | if ($this->request->post['payment_country_id'] == '') { | | 321: | $json['error']['payment_country'] = $this->language->get('error_country'); | | 322: | } | | 323: | | | 324: | if ($this->request->post['payment_zone_id'] == '') { | | 325: | $json['error']['payment_zone'] = $this->language->get('error_zone'); | | 326: | } | | 327: | | | 328: | // Custom field validation | | 329: | foreach ($custom_fields as $custom_field) { | | 330: | if ($custom_field['location'] == 'address') { | | 331: | if ($custom_field['required'] && empty($this->request->post['payment_custom_field'][$custom_field['location']][$custom_field['custom_field_id']])) { | | 332: | $json['error']['payment_custom_field_' . $custom_field['custom_field_id']] = sprintf($this->language->get('error_custom_field'), $custom_field['name']); | | 333: | } elseif (($custom_field['type'] == 'text') && !empty($custom_field['validation']) && !preg_match(html_entity_decode($custom_field['validation'], ENT_QUOTES, 'UTF-8'), $this->request->post['payment_custom_field'][$custom_field['location']][$custom_field['custom_field_id']])) { | | 334: | $json['error']['payment_custom_field_' . $custom_field['custom_field_id']] = sprintf($this->language->get('error_regex'), $custom_field['name']); | | 335: | } | | 336: | } | | 337: | } | | 338: | } | | 339: | | | 340: | if ($this->cart->hasShipping() && !$this->request->post['address_match']) { | | 341: | // If payment address not required we need to use the firstname and lastname from the account. | | 342: | if ($this->config->get('config_checkout_payment_address')) { | | 343: | if ((oc_strlen($this->request->post['shipping_firstname']) < 1) || (oc_strlen($this->request->post['shipping_firstname']) > 32)) { | | 344: | $json['error']['shipping_firstname'] = $this->language->get('error_firstname'); | | 345: | } | | 346: | | | 347: | if ((oc_strlen($this->request->post['shipping_lastname']) < 1) || (oc_strlen($this->request->post['shipping_lastname']) > 32)) { | | 348: | $json['error']['shipping_lastname'] = $this->language->get('error_lastname'); | | 349: | } | | 350: | } | | 351: | | | 352: | if ((oc_strlen($this->request->post['shipping_address_1']) < 3) || (oc_strlen($this->request->post['shipping_address_1']) > 128)) { | | 353: | $json['error']['shipping_address_1'] = $this->language->get('error_address_1'); | | 354: | } | | 355: | | | 356: | if ((oc_strlen($this->request->post['shipping_city']) < 2) || (oc_strlen($this->request->post['shipping_city']) > 128)) { | | 357: | $json['error']['shipping_city'] = $this->language->get('error_city'); | | 358: | } | | 359: | | | 360: | $this->load->model('localisation/country'); | | 361: | | | 362: | $shipping_country_info = $this->model_localisation_country->getCountry((int)$this->request->post['shipping_country_id']); | | 363: | | | 364: | if ($shipping_country_info && $shipping_country_info['postcode_required'] && (oc_strlen($this->request->post['shipping_postcode']) < 2 || oc_strlen($this->request->post['shipping_postcode']) > 10)) { | | 365: | $json['error']['shipping_postcode'] = $this->language->get('error_postcode'); | | 366: | } | | 367: | | | 368: | if ($this->request->post['shipping_country_id'] == '') { | | 369: | $json['error']['shipping_country'] = $this->language->get('error_country'); | | 370: | } | | 371: | | | 372: | if ($this->request->post['shipping_zone_id'] == '') { | | 373: | $json['error']['shipping_zone'] = $this->language->get('error_zone'); | | 374: | } | | 375: | | | 376: | // Custom field validation | | 377: | foreach ($custom_fields as $custom_field) { | | 378: | if ($custom_field['location'] == 'address') { | | 379: | if ($custom_field['required'] && empty($this->request->post['shipping_custom_field'][$custom_field['location']][$custom_field['custom_field_id']])) { | | 380: | $json['error']['shipping_custom_field_' . $custom_field['custom_field_id']] = sprintf($this->language->get('error_custom_field'), $custom_field['name']); | | 381: | } elseif (($custom_field['type'] == 'text') && !empty($custom_field['validation']) && !preg_match(html_entity_decode($custom_field['validation'], ENT_QUOTES, 'UTF-8'), $this->request->post['shipping_custom_field'][$custom_field['location']][$custom_field['custom_field_id']])) { | | 382: | $json['error']['shipping_custom_field_' . $custom_field['custom_field_id']] = sprintf($this->language->get('error_regex'), $custom_field['name']); | | 383: | } | | 384: | } | | 385: | } | | 386: | } | | 387: | | | 388: | // If account register password required | | 389: | if ($this->request->post['account'] && (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)) { | | 390: | $json['error']['password'] = $this->language->get('error_password'); | | 391: | } | | 392: | | | 393: | if ($this->request->post['account']) { | | 394: | $this->load->model('catalog/information'); | | 395: | | | 396: | $information_info = $this->model_catalog_information->getInformation($this->config->get('config_account_id')); | | 397: | | | 398: | if ($information_info && !$this->request->post['agree']) { | | 399: | $json['error']['warning'] = sprintf($this->language->get('error_agree'), $information_info['title']); | | 400: | } | | 401: | } | | 402: | | | 403: | // Captcha | | 404: | $this->load->model('setting/extension'); | | 405: | | | 406: | if (!$this->customer->isLogged()) { | | 407: | $extension_info = $this->model_setting_extension->getExtensionByCode('captcha', $this->config->get('config_captcha')); | | 408: | | | 409: | if ($extension_info && $this->config->get('captcha_' . $this->config->get('config_captcha') . '_status') && in_array('register', (array)$this->config->get('config_captcha_page'))) { | | 410: | $captcha = $this->load->controller('extension/' . $extension_info['extension'] . '/captcha/' . $extension_info['code'] . '.validate'); | | 411: | | | 412: | if ($captcha) { | | 413: | $json['error']['captcha'] = $captcha; | | 414: | } | | 415: | } | | 416: | } | | 417: | } | | 418: | | | 419: | if (!$json) { | | 420: | // Add customer details into session | | 421: | $customer_data = [ | | 422: | 'customer_id' => 0, | | 423: | 'customer_group_id' => $customer_group_id, | | 424: | 'firstname' => $this->request->post['firstname'], | | 425: | 'lastname' => $this->request->post['lastname'], | | 426: | 'email' => $this->request->post['email'], | | 427: | 'telephone' => $this->request->post['telephone'], | | 428: | 'custom_field' => $this->request->post['custom_field'] ?? [] | | 429: | ]; | | 430: | | | 431: | // Register | | 432: | if ($this->request->post['account']) { | | 433: | $customer_data['customer_id'] = $this->model_account_customer->addCustomer($this->request->post); | | 434: | } | | 435: | | | 436: | // Logged in, so edit customer details | | 437: | if ($this->customer->isLogged()) { | | 438: | $this->model_account_customer->editCustomer($this->customer->getId(), $this->request->post); | | 439: | } | | 440: | | | 441: | // Check if current customer group requires approval | | 442: | if (!$customer_group_info['approval']) { | | 443: | $this->session->data['customer'] = $customer_data; | | 444: | } | | 445: | | | 446: | $this->load->model('account/address'); | | 447: | | | 448: | // Payment Address | | 449: | if ($this->config->get('config_checkout_payment_address')) { | | 450: | if (isset($this->session->data['payment_address']['address_id'])) { | | 451: | $address_id = $this->session->data['payment_address']['address_id']; | | 452: | } else { | | 453: | $address_id = 0; | | 454: | } | | 455: | | | 456: | if ($payment_country_info) { | | 457: | $country = $payment_country_info['name']; | | 458: | $iso_code_2 = $payment_country_info['iso_code_2']; | | 459: | $iso_code_3 = $payment_country_info['iso_code_3']; | | 460: | $address_format = $payment_country_info['address_format']; | | 461: | } else { | | 462: | $country = ''; | | 463: | $iso_code_2 = ''; | | 464: | $iso_code_3 = ''; | | 465: | $address_format = ''; | | 466: | } | | 467: | | | 468: | $this->load->model('localisation/zone'); | | 469: | | | 470: | $zone_info = $this->model_localisation_zone->getZone($this->request->post['payment_zone_id']); | | 471: | | | 472: | if ($zone_info) { | | 473: | $zone = $zone_info['name']; | | 474: | $zone_code = $zone_info['code']; | | 475: | } else { | | 476: | $zone = ''; | | 477: | $zone_code = ''; | | 478: | } | | 479: | | | 480: | $payment_address_data = [ | | 481: | 'address_id' => $address_id, | | 482: | 'firstname' => $this->request->post['firstname'], | | 483: | 'lastname' => $this->request->post['lastname'], | | 484: | 'company' => $this->request->post['payment_company'], | | 485: | 'address_1' => $this->request->post['payment_address_1'], | | 486: | 'address_2' => $this->request->post['payment_address_2'], | | 487: | 'city' => $this->request->post['payment_city'], | | 488: | 'postcode' => $this->request->post['payment_postcode'], | | 489: | 'zone_id' => $this->request->post['payment_zone_id'], | | 490: | 'zone' => $zone, | | 491: | 'zone_code' => $zone_code, | | 492: | 'country_id' => $this->request->post['payment_country_id'], | | 493: | 'country' => $country, | | 494: | 'iso_code_2' => $iso_code_2, | | 495: | 'iso_code_3' => $iso_code_3, | | 496: | 'address_format' => $address_format, | | 497: | 'custom_field' => $this->request->post['payment_custom_field'] ?? [] | | 498: | ]; | | 499: | | | 500: | // Add | | 501: | if ($this->request->post['account']) { | | 502: | $payment_address_data['default'] = 1; | | 503: | | | 504: | $payment_address_data['address_id'] = $this->model_account_address->addAddress($customer_data['customer_id'], $payment_address_data); | | 505: | } | | 506: | | | 507: | // Edit | | 508: | if ($this->customer->isLogged() && $payment_address_data['address_id']) { | | 509: | $this->model_account_address->editAddress($payment_address_data['address_id'], $payment_address_data); | | 510: | } | | 511: | | | 512: | // Requires Approval | | 513: | if (!$customer_group_info['approval']) { | | 514: | $this->session->data['payment_address'] = $payment_address_data; | | 515: | } | | 516: | } | | 517: | | | 518: | // Shipping Address | | 519: | if ($this->cart->hasShipping()) { | | 520: | if (!$this->request->post['address_match']) { | | 521: | if (isset($this->session->data['shipping_address']['address_id'])) { | | 522: | $address_id = $this->session->data['shipping_address']['address_id']; | | 523: | } else { | | 524: | $address_id = 0; | | 525: | } | | 526: | | | 527: | if (!$this->config->get('config_checkout_payment_address')) { | | 528: | $firstname = $this->request->post['firstname']; | | 529: | $lastname = $this->request->post['lastname']; | | 530: | } else { | | 531: | $firstname = $this->request->post['shipping_firstname']; | | 532: | $lastname = $this->request->post['shipping_lastname']; | | 533: | } | | 534: | | | 535: | if ($shipping_country_info) { | | 536: | $country = $shipping_country_info['name']; | | 537: | $iso_code_2 = $shipping_country_info['iso_code_2']; | | 538: | $iso_code_3 = $shipping_country_info['iso_code_3']; | | 539: | $address_format = $shipping_country_info['address_format']; | | 540: | } else { | | 541: | $country = ''; | | 542: | $iso_code_2 = ''; | | 543: | $iso_code_3 = ''; | | 544: | $address_format = ''; | | 545: | } | | 546: | | | 547: | $this->load->model('localisation/zone'); | | 548: | | | 549: | $zone_info = $this->model_localisation_zone->getZone($this->request->post['shipping_zone_id']); | | 550: | | | 551: | if ($zone_info) { | | 552: | $zone = $zone_info['name']; | | 553: | $zone_code = $zone_info['code']; | | 554: | } else { | | 555: | $zone = ''; | | 556: | $zone_code = ''; | | 557: | } | | 558: | | | 559: | $shipping_address_data = [ | | 560: | 'address_id' => $address_id, | | 561: | 'firstname' => $firstname, | | 562: | 'lastname' => $lastname, | | 563: | 'company' => $this->request->post['shipping_company'], | | 564: | 'address_1' => $this->request->post['shipping_address_1'], | | 565: | 'address_2' => $this->request->post['shipping_address_2'], | | 566: | 'city' => $this->request->post['shipping_city'], | | 567: | 'postcode' => $this->request->post['shipping_postcode'], | | 568: | 'zone_id' => $this->request->post['shipping_zone_id'], | | 569: | 'zone' => $zone, | | 570: | 'zone_code' => $zone_code, | | 571: | 'country_id' => $this->request->post['shipping_country_id'], | | 572: | 'country' => $country, | | 573: | 'iso_code_2' => $iso_code_2, | | 574: | 'iso_code_3' => $iso_code_3, | | 575: | 'address_format' => $address_format, | | 576: | 'custom_field' => $this->request->post['shipping_custom_field'] ?? [] | | 577: | ]; | | 578: | | | 579: | // Add | | 580: | if ($this->request->post['account']) { | | 581: | if (!$this->config->get('config_checkout_payment_address')) { | | 582: | $shipping_address_data['default'] = 1; | | 583: | } | | 584: | | | 585: | $shipping_address_data['address_id'] = $this->model_account_address->addAddress($customer_data['customer_id'], $shipping_address_data); | | 586: | } | | 587: | | | 588: | // Edit | | 589: | if ($this->customer->isLogged() && $shipping_address_data['address_id']) { | | 590: | $this->model_account_address->editAddress($shipping_address_data['address_id'], $shipping_address_data); | | 591: | } | | 592: | | | 593: | // Requires Approval | | 594: | if (!$customer_group_info['approval']) { | | 595: | $this->session->data['shipping_address'] = $shipping_address_data; | | 596: | } | | 597: | } elseif (!$customer_group_info['approval'] && $this->config->get('config_checkout_payment_address')) { | | 598: | $this->session->data['shipping_address'] = $this->session->data['payment_address']; | | 599: | | | 600: | // Remove the address id so if the customer changes their mind and requires changing a different shipping address it will create a new address. | | 601: | $this->session->data['shipping_address']['address_id'] = 0; | | 602: | } | | 603: | } | | 604: | | | 605: | // If everything good login | | 606: | if (!$customer_group_info['approval']) { | | 607: | if ($this->request->post['account']) { | | 608: | $this->customer->login($this->request->post['email'], $this->request->post['password']); | | 609: | | | 610: | // Create customer token | | 611: | $this->session->data['customer_token'] = oc_token(26); | | 612: | | | 613: | $json['success'] = $this->language->get('text_add_success'); | | 614: | } elseif ($this->customer->isLogged()) { | | 615: | $json['success'] = $this->language->get('text_edit_success'); | | 616: | } else { | | 617: | $json['success'] = $this->language->get('text_guest_success'); | | 618: | } | | 619: | } else { | | 620: | // If account needs approval we redirect to the account success / requires approval page. | | 621: | $json['redirect'] = $this->url->link('account/success', 'language=' . $this->config->get('config_language'), true); | | 622: | } | | 623: | | | 624: | unset($this->session->data['shipping_method']); | | 625: | unset($this->session->data['shipping_methods']); | | 626: | unset($this->session->data['payment_method']); | | 627: | unset($this->session->data['payment_methods']); | | 628: | | | 629: | // Clear any previous login attempts for unregistered accounts. | | 630: | $this->model_account_customer->deleteLoginAttempts($this->request->post['email']); | | 631: | } | | 632: | | | 633: | $this->response->addHeader('Content-Type: application/json'); | | 634: | $this->response->setOutput(json_encode($json)); | | 635: | } | | 636: | } | | 637: | |

OpenCart API API documentation generated by ApiGen dev-master