register.php (10416B)
1 <?php 2 class ControllerCheckoutRegister extends Controller { 3 public function index() { 4 $this->load->language('checkout/checkout'); 5 6 $data['entry_newsletter'] = sprintf($this->language->get('entry_newsletter'), $this->config->get('config_name')); 7 8 $data['customer_groups'] = array(); 9 10 if (is_array($this->config->get('config_customer_group_display'))) { 11 $this->load->model('account/customer_group'); 12 13 $customer_groups = $this->model_account_customer_group->getCustomerGroups(); 14 15 foreach ($customer_groups as $customer_group) { 16 if (in_array($customer_group['customer_group_id'], $this->config->get('config_customer_group_display'))) { 17 $data['customer_groups'][] = $customer_group; 18 } 19 } 20 } 21 22 $data['customer_group_id'] = $this->config->get('config_customer_group_id'); 23 24 if (isset($this->session->data['shipping_address']['postcode'])) { 25 $data['postcode'] = $this->session->data['shipping_address']['postcode']; 26 } else { 27 $data['postcode'] = ''; 28 } 29 30 if (isset($this->session->data['shipping_address']['country_id'])) { 31 $data['country_id'] = $this->session->data['shipping_address']['country_id']; 32 } else { 33 $data['country_id'] = $this->config->get('config_country_id'); 34 } 35 36 if (isset($this->session->data['shipping_address']['zone_id'])) { 37 $data['zone_id'] = $this->session->data['shipping_address']['zone_id']; 38 } else { 39 $data['zone_id'] = ''; 40 } 41 42 $this->load->model('localisation/country'); 43 44 $data['countries'] = $this->model_localisation_country->getCountries(); 45 46 // Custom Fields 47 $this->load->model('account/custom_field'); 48 49 $data['custom_fields'] = $this->model_account_custom_field->getCustomFields(); 50 51 // Captcha 52 if ($this->config->get('captcha_' . $this->config->get('config_captcha') . '_status') && in_array('register', (array)$this->config->get('config_captcha_page'))) { 53 $data['captcha'] = $this->load->controller('extension/captcha/' . $this->config->get('config_captcha')); 54 } else { 55 $data['captcha'] = ''; 56 } 57 58 if ($this->config->get('config_account_id')) { 59 $this->load->model('catalog/information'); 60 61 $information_info = $this->model_catalog_information->getInformation($this->config->get('config_account_id')); 62 63 if ($information_info) { 64 $data['text_agree'] = sprintf($this->language->get('text_agree'), $this->url->link('information/information/agree', 'information_id=' . $this->config->get('config_account_id'), true), $information_info['title'], $information_info['title']); 65 } else { 66 $data['text_agree'] = ''; 67 } 68 } else { 69 $data['text_agree'] = ''; 70 } 71 72 $data['shipping_required'] = $this->cart->hasShipping(); 73 74 $this->response->setOutput($this->load->view('checkout/register', $data)); 75 } 76 77 public function save() { 78 $this->load->language('checkout/checkout'); 79 80 $json = array(); 81 82 // Validate if customer is already logged out. 83 if ($this->customer->isLogged()) { 84 $json['redirect'] = $this->url->link('checkout/checkout', '', true); 85 } 86 87 // Validate cart has products and has stock. 88 if ((!$this->cart->hasProducts() && empty($this->session->data['vouchers'])) || (!$this->cart->hasStock() && !$this->config->get('config_stock_checkout'))) { 89 $json['redirect'] = $this->url->link('checkout/cart'); 90 } 91 92 // Validate minimum quantity requirements. 93 $products = $this->cart->getProducts(); 94 95 foreach ($products as $product) { 96 $product_total = 0; 97 98 foreach ($products as $product_2) { 99 if ($product_2['product_id'] == $product['product_id']) { 100 $product_total += $product_2['quantity']; 101 } 102 } 103 104 if ($product['minimum'] > $product_total) { 105 $json['redirect'] = $this->url->link('checkout/cart'); 106 107 break; 108 } 109 } 110 111 if (!$json) { 112 $this->load->model('account/customer'); 113 114 if ((utf8_strlen(trim($this->request->post['firstname'])) < 1) || (utf8_strlen(trim($this->request->post['firstname'])) > 32)) { 115 $json['error']['firstname'] = $this->language->get('error_firstname'); 116 } 117 118 if ((utf8_strlen(trim($this->request->post['lastname'])) < 1) || (utf8_strlen(trim($this->request->post['lastname'])) > 32)) { 119 $json['error']['lastname'] = $this->language->get('error_lastname'); 120 } 121 122 if ((utf8_strlen($this->request->post['email']) > 96) || !filter_var($this->request->post['email'], FILTER_VALIDATE_EMAIL)) { 123 $json['error']['email'] = $this->language->get('error_email'); 124 } 125 126 if ($this->model_account_customer->getTotalCustomersByEmail($this->request->post['email'])) { 127 $json['error']['warning'] = $this->language->get('error_exists'); 128 } 129 130 if ((utf8_strlen($this->request->post['telephone']) < 3) || (utf8_strlen($this->request->post['telephone']) > 32)) { 131 $json['error']['telephone'] = $this->language->get('error_telephone'); 132 } 133 134 if ((utf8_strlen(trim($this->request->post['address_1'])) < 3) || (utf8_strlen(trim($this->request->post['address_1'])) > 128)) { 135 $json['error']['address_1'] = $this->language->get('error_address_1'); 136 } 137 138 if ((utf8_strlen(trim($this->request->post['city'])) < 2) || (utf8_strlen(trim($this->request->post['city'])) > 128)) { 139 $json['error']['city'] = $this->language->get('error_city'); 140 } 141 142 $this->load->model('localisation/country'); 143 144 $country_info = $this->model_localisation_country->getCountry($this->request->post['country_id']); 145 146 if ($country_info && $country_info['postcode_required'] && (utf8_strlen(trim($this->request->post['postcode'])) < 2 || utf8_strlen(trim($this->request->post['postcode'])) > 10)) { 147 $json['error']['postcode'] = $this->language->get('error_postcode'); 148 } 149 150 if ($this->request->post['country_id'] == '') { 151 $json['error']['country'] = $this->language->get('error_country'); 152 } 153 154 if (!isset($this->request->post['zone_id']) || $this->request->post['zone_id'] == '' || !is_numeric($this->request->post['zone_id'])) { 155 $json['error']['zone'] = $this->language->get('error_zone'); 156 } 157 158 if ((utf8_strlen(html_entity_decode($this->request->post['password'], ENT_QUOTES, 'UTF-8')) < 4) || (utf8_strlen(html_entity_decode($this->request->post['password'], ENT_QUOTES, 'UTF-8')) > 40)) { 159 $json['error']['password'] = $this->language->get('error_password'); 160 } 161 162 if ($this->request->post['confirm'] != $this->request->post['password']) { 163 $json['error']['confirm'] = $this->language->get('error_confirm'); 164 } 165 166 if ($this->config->get('config_account_id')) { 167 $this->load->model('catalog/information'); 168 169 $information_info = $this->model_catalog_information->getInformation($this->config->get('config_account_id')); 170 171 if ($information_info && !isset($this->request->post['agree'])) { 172 $json['error']['warning'] = sprintf($this->language->get('error_agree'), $information_info['title']); 173 } 174 } 175 176 // Customer Group 177 if (isset($this->request->post['customer_group_id']) && is_array($this->config->get('config_customer_group_display')) && in_array($this->request->post['customer_group_id'], $this->config->get('config_customer_group_display'))) { 178 $customer_group_id = $this->request->post['customer_group_id']; 179 } else { 180 $customer_group_id = $this->config->get('config_customer_group_id'); 181 } 182 183 // Custom field validation 184 $this->load->model('account/custom_field'); 185 186 $custom_fields = $this->model_account_custom_field->getCustomFields($customer_group_id); 187 188 foreach ($custom_fields as $custom_field) { 189 if ($custom_field['required'] && empty($this->request->post['custom_field'][$custom_field['location']][$custom_field['custom_field_id']])) { 190 $json['error']['custom_field' . $custom_field['custom_field_id']] = sprintf($this->language->get('error_custom_field'), $custom_field['name']); 191 } elseif (($custom_field['type'] == 'text') && !empty($custom_field['validation']) && !filter_var($this->request->post['custom_field'][$custom_field['location']][$custom_field['custom_field_id']], FILTER_VALIDATE_REGEXP, array('options' => array('regexp' => $custom_field['validation'])))) { 192 $json['error']['custom_field' . $custom_field['custom_field_id']] = sprintf($this->language->get('error_custom_field'), $custom_field['name']); 193 } 194 } 195 196 // Captcha 197 if ($this->config->get('captcha_' . $this->config->get('config_captcha') . '_status') && in_array('register', (array)$this->config->get('config_captcha_page'))) { 198 $captcha = $this->load->controller('extension/captcha/' . $this->config->get('config_captcha') . '/validate'); 199 200 if ($captcha) { 201 $json['error']['captcha'] = $captcha; 202 } 203 } 204 } 205 206 if (!$json) { 207 $customer_id = $this->model_account_customer->addCustomer($this->request->post); 208 209 // Default Payment Address 210 $this->load->model('account/address'); 211 212 $address_id = $this->model_account_address->addAddress($customer_id, $this->request->post); 213 214 // Set the address as default 215 $this->model_account_customer->editAddressId($customer_id, $address_id); 216 217 // Clear any previous login attempts for unregistered accounts. 218 $this->model_account_customer->deleteLoginAttempts($this->request->post['email']); 219 220 $this->session->data['account'] = 'register'; 221 222 $this->load->model('account/customer_group'); 223 224 $customer_group_info = $this->model_account_customer_group->getCustomerGroup($customer_group_id); 225 226 if ($customer_group_info && !$customer_group_info['approval']) { 227 $this->customer->login($this->request->post['email'], $this->request->post['password']); 228 229 $this->session->data['payment_address'] = $this->model_account_address->getAddress($this->customer->getAddressId()); 230 231 if (!empty($this->request->post['shipping_address'])) { 232 $this->session->data['shipping_address'] = $this->model_account_address->getAddress($this->customer->getAddressId()); 233 } 234 } else { 235 $json['redirect'] = $this->url->link('account/success'); 236 } 237 238 unset($this->session->data['guest']); 239 unset($this->session->data['shipping_method']); 240 unset($this->session->data['shipping_methods']); 241 unset($this->session->data['payment_method']); 242 unset($this->session->data['payment_methods']); 243 } 244 245 $this->response->addHeader('Content-Type: application/json'); 246 $this->response->setOutput(json_encode($json)); 247 } 248 }