/catalog/controller/checkout/register.php

https://github.com/sansanwawa/e-commerse · PHP · 187 lines · 139 code · 48 blank · 0 comment · 51 complexity · 0d1d766b8d14c05a97422393cd17009d MD5 · raw file

  1. <?php
  2. class ControllerCheckoutRegister extends Controller {
  3. public function index() {
  4. $this->language->load('checkout/checkout');
  5. $this->load->model('account/customer');
  6. $json = array();
  7. if ($this->customer->isLogged()) {
  8. $json['redirect'] = $this->url->link('checkout/checkout', '', 'SSL');
  9. }
  10. if ((!$this->cart->hasProducts() && (!isset($this->session->data['vouchers']) || !$this->session->data['vouchers'])) || (!$this->cart->hasStock() && !$this->config->get('config_stock_checkout'))) {
  11. $json['redirect'] = $this->url->link('checkout/cart');
  12. }
  13. if ($this->request->server['REQUEST_METHOD'] == 'POST') {
  14. if (!$json) {
  15. if ((strlen(utf8_decode($this->request->post['firstname'])) < 1) || (strlen(utf8_decode($this->request->post['firstname'])) > 32)) {
  16. $json['error']['firstname'] = $this->language->get('error_firstname');
  17. }
  18. if ((strlen(utf8_decode($this->request->post['lastname'])) < 1) || (strlen(utf8_decode($this->request->post['lastname'])) > 32)) {
  19. $json['error']['lastname'] = $this->language->get('error_lastname');
  20. }
  21. if ((strlen(utf8_decode($this->request->post['email'])) > 96) || !preg_match('/^[^\@]+@.*\.[a-z]{2,6}$/i', $this->request->post['email'])) {
  22. $json['error']['email'] = $this->language->get('error_email');
  23. }
  24. if ($this->model_account_customer->getTotalCustomersByEmail($this->request->post['email'])) {
  25. $json['error']['warning'] = $this->language->get('error_exists');
  26. }
  27. if ((strlen(utf8_decode($this->request->post['telephone'])) < 3) || (strlen(utf8_decode($this->request->post['telephone'])) > 32)) {
  28. $json['error']['telephone'] = $this->language->get('error_telephone');
  29. }
  30. if ((strlen(utf8_decode($this->request->post['address_1'])) < 3) || (strlen(utf8_decode($this->request->post['address_1'])) > 128)) {
  31. $json['error']['address_1'] = $this->language->get('error_address_1');
  32. }
  33. if ((strlen(utf8_decode($this->request->post['city'])) < 2) || (strlen(utf8_decode($this->request->post['city'])) > 128)) {
  34. $json['error']['city'] = $this->language->get('error_city');
  35. }
  36. $this->load->model('localisation/country');
  37. $country_info = $this->model_localisation_country->getCountry($this->request->post['country_id']);
  38. if ($country_info && $country_info['postcode_required'] && (strlen(utf8_decode($this->request->post['postcode'])) < 2) || (strlen(utf8_decode($this->request->post['postcode'])) > 10)) {
  39. $json['error']['postcode'] = $this->language->get('error_postcode');
  40. }
  41. if ($this->request->post['country_id'] == '') {
  42. $json['error']['country'] = $this->language->get('error_country');
  43. }
  44. if ($this->request->post['zone_id'] == '') {
  45. $json['error']['zone'] = $this->language->get('error_zone');
  46. }
  47. if ((strlen(utf8_decode($this->request->post['password'])) < 4) || (strlen(utf8_decode($this->request->post['password'])) > 20)) {
  48. $json['error']['password'] = $this->language->get('error_password');
  49. }
  50. if ($this->request->post['confirm'] != $this->request->post['password']) {
  51. $json['error']['confirm'] = $this->language->get('error_confirm');
  52. }
  53. if ($this->config->get('config_account_id')) {
  54. $this->load->model('catalog/information');
  55. $information_info = $this->model_catalog_information->getInformation($this->config->get('config_account_id'));
  56. if ($information_info && !isset($this->request->post['agree'])) {
  57. $json['error']['warning'] = sprintf($this->language->get('error_agree'), $information_info['title']);
  58. }
  59. }
  60. }
  61. if (!$json) {
  62. $this->model_account_customer->addCustomer($this->request->post);
  63. $this->customer->login($this->request->post['email'], $this->request->post['password']);
  64. $this->session->data['payment_address_id'] = $this->customer->getAddressId();
  65. if (isset($this->request->post['shipping_address']) && $this->request->post['shipping_address']) {
  66. $this->session->data['shipping_address_id'] = $this->customer->getAddressId();
  67. }
  68. $this->tax->setZone($this->request->post['country_id'], $this->request->post['zone_id']);
  69. unset($this->session->data['guest']);
  70. unset($this->session->data['shipping_methods']);
  71. unset($this->session->data['shipping_method']);
  72. unset($this->session->data['payment_methods']);
  73. unset($this->session->data['payment_method']);
  74. }
  75. } else {
  76. $this->data['text_select'] = $this->language->get('text_select');
  77. $this->data['text_your_details'] = $this->language->get('text_your_details');
  78. $this->data['text_your_address'] = $this->language->get('text_your_address');
  79. $this->data['text_your_password'] = $this->language->get('text_your_password');
  80. $this->data['entry_firstname'] = $this->language->get('entry_firstname');
  81. $this->data['entry_lastname'] = $this->language->get('entry_lastname');
  82. $this->data['entry_email'] = $this->language->get('entry_email');
  83. $this->data['entry_telephone'] = $this->language->get('entry_telephone');
  84. $this->data['entry_fax'] = $this->language->get('entry_fax');
  85. $this->data['entry_company'] = $this->language->get('entry_company');
  86. $this->data['entry_address_1'] = $this->language->get('entry_address_1');
  87. $this->data['entry_address_2'] = $this->language->get('entry_address_2');
  88. $this->data['entry_postcode'] = $this->language->get('entry_postcode');
  89. $this->data['entry_city'] = $this->language->get('entry_city');
  90. $this->data['entry_country'] = $this->language->get('entry_country');
  91. $this->data['entry_zone'] = $this->language->get('entry_zone');
  92. $this->data['entry_newsletter'] = sprintf($this->language->get('entry_newsletter'), $this->config->get('config_name'));
  93. $this->data['entry_password'] = $this->language->get('entry_password');
  94. $this->data['entry_confirm'] = $this->language->get('entry_confirm');
  95. $this->data['entry_shipping'] = $this->language->get('entry_shipping');
  96. $this->data['button_continue'] = $this->language->get('button_continue');
  97. $this->data['country_id'] = $this->config->get('config_country_id');
  98. $this->load->model('localisation/country');
  99. $this->data['countries'] = $this->model_localisation_country->getCountries();
  100. if ($this->config->get('config_account_id')) {
  101. $this->load->model('catalog/information');
  102. $information_info = $this->model_catalog_information->getInformation($this->config->get('config_account_id'));
  103. if ($information_info) {
  104. $this->data['text_agree'] = sprintf($this->language->get('text_agree'), $this->url->link('information/information/info', 'information_id=' . $this->config->get('config_account_id'), 'SSL'), $information_info['title'], $information_info['title']);
  105. } else {
  106. $this->data['text_agree'] = '';
  107. }
  108. } else {
  109. $this->data['text_agree'] = '';
  110. }
  111. $this->data['shipping_required'] = $this->cart->hasShipping();
  112. if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/checkout/register.tpl')) {
  113. $this->template = $this->config->get('config_template') . '/template/checkout/register.tpl';
  114. } else {
  115. $this->template = 'default/template/checkout/register.tpl';
  116. }
  117. $json['output'] = $this->render();
  118. }
  119. $this->load->library('json');
  120. $this->response->setOutput(Json::encode($json));
  121. }
  122. public function zone() {
  123. $output = '<option value="">' . $this->language->get('text_select') . '</option>';
  124. $this->load->model('localisation/zone');
  125. $results = $this->model_localisation_zone->getZonesByCountryId($this->request->get['country_id']);
  126. foreach ($results as $result) {
  127. $output .= '<option value="' . $result['zone_id'] . '"';
  128. if (isset($this->request->get['zone_id']) && ($this->request->get['zone_id'] == $result['zone_id'])) {
  129. $output .= ' selected="selected"';
  130. }
  131. $output .= '>' . $result['name'] . '</option>';
  132. }
  133. if (!$results) {
  134. $output .= '<option value="0">' . $this->language->get('text_none') . '</option>';
  135. }
  136. $this->response->setOutput($output);
  137. }
  138. }
  139. ?>