public function validate_main_tax_id($value, $fields) { $this->load->helper('vat'); $this->load->model('localisation/country'); $this->language->load('account/register'); $country_id = $fields['main_country_id']['value']; $country = $this->model_localisation_country->getCountry($country_id); if ($country && !empty($country['iso_code_2']) && vat_validation($country['iso_code_2'], $value) == 'invalid') { return $this->language->get('error_vat'); } return ''; }
protected function validateForm() { if (!$this->user->hasPermission('modify', 'sale/order')) { $this->error['warning'] = $this->language->get('error_permission'); } if (utf8_strlen($this->request->post['firstname']) < 1 || utf8_strlen($this->request->post['firstname']) > 32) { $this->error['firstname'] = $this->language->get('error_firstname'); } if (utf8_strlen($this->request->post['lastname']) < 1 || utf8_strlen($this->request->post['lastname']) > 32) { $this->error['lastname'] = $this->language->get('error_lastname'); } if (utf8_strlen($this->request->post['email']) > 96 || !preg_match('/^[^\\@]+@.*\\.[a-z]{2,6}$/i', $this->request->post['email'])) { $this->error['email'] = $this->language->get('error_email'); } if (utf8_strlen($this->request->post['telephone']) < 3 || utf8_strlen($this->request->post['telephone']) > 32) { $this->error['telephone'] = $this->language->get('error_telephone'); } if (utf8_strlen($this->request->post['payment_firstname']) < 1 || utf8_strlen($this->request->post['payment_firstname']) > 32) { $this->error['payment_firstname'] = $this->language->get('error_firstname'); } if (utf8_strlen($this->request->post['payment_lastname']) < 1 || utf8_strlen($this->request->post['payment_lastname']) > 32) { $this->error['payment_lastname'] = $this->language->get('error_lastname'); } if (utf8_strlen($this->request->post['payment_address_1']) < 3 || utf8_strlen($this->request->post['payment_address_1']) > 128) { $this->error['payment_address_1'] = $this->language->get('error_address_1'); } if (utf8_strlen($this->request->post['payment_city']) < 3 || utf8_strlen($this->request->post['payment_city']) > 128) { $this->error['payment_city'] = $this->language->get('error_city'); } $this->load->model('localisation/country'); $country_info = $this->model_localisation_country->getCountry($this->request->post['payment_country_id']); if ($country_info) { if ($country_info['postcode_required'] && utf8_strlen($this->request->post['payment_postcode']) < 2 || utf8_strlen($this->request->post['payment_postcode']) > 10) { $this->error['payment_postcode'] = $this->language->get('error_postcode'); } // VAT Validation $this->load->helper('vat'); if ($this->config->get('config_vat') && $this->request->post['payment_tax_id'] && vat_validation($country_info['iso_code_2'], $this->request->post['payment_tax_id']) == 'invalid') { $this->error['payment_tax_id'] = $this->language->get('error_vat'); } } if ($this->request->post['payment_country_id'] == '') { $this->error['payment_country'] = $this->language->get('error_country'); } if (!isset($this->request->post['payment_zone_id']) || $this->request->post['payment_zone_id'] == '') { $this->error['payment_zone'] = $this->language->get('error_zone'); } if ($this->request->post['payment_method'] == '') { $this->error['payment_zone'] = $this->language->get('error_zone'); } if (!$this->request->post['payment_method']) { $this->error['payment_method'] = $this->language->get('error_payment'); } // Check if any products require shipping $shipping = false; if (isset($this->request->post['order_product'])) { $this->load->model('catalog/product'); foreach ($this->request->post['order_product'] as $order_product) { $product_info = $this->model_catalog_product->getProduct($order_product['product_id']); if ($product_info && $product_info['shipping']) { $shipping = true; } } } if ($shipping) { if (utf8_strlen($this->request->post['shipping_firstname']) < 1 || utf8_strlen($this->request->post['shipping_firstname']) > 32) { $this->error['shipping_firstname'] = $this->language->get('error_firstname'); } if (utf8_strlen($this->request->post['shipping_lastname']) < 1 || utf8_strlen($this->request->post['shipping_lastname']) > 32) { $this->error['shipping_lastname'] = $this->language->get('error_lastname'); } if (utf8_strlen($this->request->post['shipping_address_1']) < 3 || utf8_strlen($this->request->post['shipping_address_1']) > 128) { $this->error['shipping_address_1'] = $this->language->get('error_address_1'); } if (utf8_strlen($this->request->post['shipping_city']) < 3 || utf8_strlen($this->request->post['shipping_city']) > 128) { $this->error['shipping_city'] = $this->language->get('error_city'); } $this->load->model('localisation/country'); $country_info = $this->model_localisation_country->getCountry($this->request->post['shipping_country_id']); if ($country_info && $country_info['postcode_required'] && utf8_strlen($this->request->post['shipping_postcode']) < 2 || utf8_strlen($this->request->post['shipping_postcode']) > 10) { $this->error['shipping_postcode'] = $this->language->get('error_postcode'); } if ($this->request->post['shipping_country_id'] == '') { $this->error['shipping_country'] = $this->language->get('error_country'); } if (!isset($this->request->post['shipping_zone_id']) || $this->request->post['shipping_zone_id'] == '') { $this->error['shipping_zone'] = $this->language->get('error_zone'); } if (!$this->request->post['shipping_method']) { $this->error['shipping_method'] = $this->language->get('error_shipping'); } } if ($this->error && !isset($this->error['warning'])) { $this->error['warning'] = $this->language->get('error_warning'); } if (!$this->error) { return true; } else { return false; } }
public function validate() { $this->language->load('checkout/checkout_express'); $json = array(); // Validate if customer is logged in if (!$this->customer->isLogged()) { $json['redirect'] = $this->url->link('checkout_express/checkout', '', 'SSL'); } // Validate cart has products and has stock if (!$this->cart->hasProducts() && empty($this->session->data['vouchers']) || !$this->cart->hasStock() && !$this->config->get('config_stock_checkout')) { $json['redirect'] = $this->url->link('checkout/cart'); } // Validate minimum quantity requirements $products = $this->cart->getProducts(); foreach ($products as $product) { $product_total = 0; foreach ($products as $product_2) { if ($product_2['product_id'] == $product['product_id']) { $product_total += $product_2['quantity']; } } if ($product['minimum'] > $product_total) { $json['redirect'] = $this->url->link('checkout/cart'); break; } } $this->load->model('checkout/checkout_tools'); if (!$json) { if (!isset($this->request->post['payment_address'])) { $this->request->post['payment_address'] = 'new'; } if ($this->request->post['payment_address'] == 'existing') { $this->load->model('account/address'); if (empty($this->request->post['address_id'])) { $json['error']['warning'] = $this->language->get('error_address'); } elseif (!in_array($this->request->post['address_id'], array_keys($this->model_account_address->getAddresses()))) { $json['error']['warning'] = $this->language->get('error_address'); } else { // Default Payment Address $this->load->model('account/address'); $address_info = $this->model_account_address->getAddress($this->request->post['address_id']); if ($address_info) { $this->load->model('account/customer_group'); $customer_group_info = $this->model_account_customer_group->getCustomerGroup($this->customer->getCustomerGroupId()); // Company ID if ($customer_group_info['company_id_display'] && $customer_group_info['company_id_required'] && !$address_info['company_id']) { $json['error']['warning'] = $this->language->get('error_company_id'); } // Tax ID if ($customer_group_info['tax_id_display'] && $customer_group_info['tax_id_required'] && !$address_info['tax_id']) { $json['error']['warning'] = $this->language->get('error_tax_id'); } } } if (!$json) { $this->session->data['payment_address_id'] = $this->request->post['address_id']; if ($address_info) { $this->session->data['payment_country_id'] = $address_info['country_id']; $this->session->data['payment_zone_id'] = $address_info['zone_id']; } else { unset($this->session->data['payment_country_id']); unset($this->session->data['payment_zone_id']); } unset($this->session->data['payment_method']); unset($this->session->data['payment_methods']); } } $this->request->post['firstname'] = $this->model_checkout_checkout_tools->getFirstName($this->request->post['firstname']); $this->request->post['lastname'] = $this->model_checkout_checkout_tools->getLastName($this->request->post['firstname']); $this->request->post['address_2'] = ''; if (!isset($this->request->post['company_id'])) { $this->request->post['company_id'] = ''; } if (!isset($this->request->post['tax_id'])) { $this->request->post['tax_id'] = ''; } if ($this->request->post['payment_address'] == 'new') { if (utf8_strlen($this->request->post['firstname']) < 1 || utf8_strlen($this->request->post['firstname']) > 32) { $json['error']['firstname'] = $this->language->get('error_firstname'); } // Customer Group $this->load->model('account/customer_group'); $customer_group_info = $this->model_account_customer_group->getCustomerGroup($this->customer->getCustomerGroupId()); if ($customer_group_info) { // Company ID if ($customer_group_info['company_id_display'] && $customer_group_info['company_id_required'] && empty($this->request->post['company_id'])) { $json['error']['company_id'] = $this->language->get('error_company_id'); } // Tax ID if ($customer_group_info['tax_id_display'] && $customer_group_info['tax_id_required'] && empty($this->request->post['tax_id'])) { $json['error']['tax_id'] = $this->language->get('error_tax_id'); } } if (utf8_strlen($this->request->post['address_1']) < 3 || utf8_strlen($this->request->post['address_1']) > 128) { $json['error']['address_1'] = $this->language->get('error_address_1'); } if (utf8_strlen($this->request->post['city']) < 2 || utf8_strlen($this->request->post['city']) > 32) { $json['error']['city'] = $this->language->get('error_city'); } $this->load->model('localisation/country'); $country_info = $this->model_localisation_country->getCountry($this->request->post['country_id']); if ($country_info) { if ($country_info['postcode_required'] && utf8_strlen($this->request->post['postcode']) < 2 || utf8_strlen($this->request->post['postcode']) > 10) { $json['error']['postcode'] = $this->language->get('error_postcode'); } // VAT Validation $this->load->helper('vat'); if ($this->config->get('config_vat') && isset($this->request->post['tax_id']) && $this->request->post['tax_id'] != '' && vat_validation($country_info['iso_code_2'], $this->request->post['tax_id']) == 'invalid') { $json['error']['tax_id'] = $this->language->get('error_vat'); } } if ($this->request->post['country_id'] == '') { $json['error']['country'] = $this->language->get('error_country'); } if (!isset($this->request->post['zone_id']) || $this->request->post['zone_id'] == '') { $json['error']['zone'] = $this->language->get('error_zone'); } if (!$json) { // Default Payment Address $this->load->model('account/address'); $this->session->data['payment_address_id'] = $this->model_account_address->addAddress($this->request->post); $this->session->data['payment_country_id'] = $this->request->post['country_id']; $this->session->data['payment_zone_id'] = $this->request->post['zone_id']; unset($this->session->data['payment_method']); unset($this->session->data['payment_methods']); } } } $this->response->addHeader('Content-Type: application/json'); $this->response->setOutput(json_encode($json)); }
protected function validate() { $this->load->model('account/customer_group'); $this->load->model('catalog/information'); $this->load->model('localisation/country'); if (utf8_strlen($this->request->post['firstname']) < 1 || utf8_strlen($this->request->post['firstname']) > 32) { $this->error['firstname'] = Language::getVar('SUMO_NOUN_FIRSTNAME'); } if (utf8_strlen($this->request->post['lastname']) < 1 || utf8_strlen($this->request->post['lastname']) > 32) { $this->error['lastname'] = Language::getVar('SUMO_NOUN_ERROR_LASTNAME'); } if (empty($this->request->post['gender'])) { $this->error['gender'] = Language::getVar('SUMO_NOUN_ERROR_GENDER'); } if (empty($this->request->post['birthdate']) || utf8_strlen($this->request->post['birthdate']) != 10) { $this->error['birthdate'] = Language::getVar('SUMO_NOUN_ERROR_BIRTHDATE'); } if (!filter_var($this->request->post['email'], \FILTER_VALIDATE_EMAIL)) { $this->error['email'] = Language::getVar('SUMO_NOUN_ERROR_EMAIL'); } if ($this->model_account_customer->getTotalCustomersByEmail($this->request->post['email'])) { $this->error['warning'] = Language::getVar('SUMO_NOUN_ERROR_EMAIL_IN_USE', $this->url->link('account/login', '', 'SSL')); } $this->request->post['telephone'] = preg_replace('/([^\\d]+)/', '', str_replace('+', '00', $this->request->post['telephone'])); $this->request->post['mobile'] = preg_replace('/([^\\d]+)/', '', str_replace('+', '00', $this->request->post['mobile'])); if (utf8_strlen($this->request->post['telephone']) < 8 || utf8_strlen($this->request->post['telephone']) > 15) { $this->error['telephone'] = Language::getVar('SUMO_NOUN_ERROR_TELEPHONE'); } if (!empty($this->request->post['mobile'])) { if (utf8_strlen($this->request->post['mobile']) < 8 || utf8_strlen($this->request->post['mobile']) > 15) { $this->error['mobile'] = Language::getVar('SUMO_NOUN_ERROR_TELEPHONE'); } } // Customer Group if (isset($this->request->post['customer_group_id']) && is_array($this->config->get('customer_group_display')) && in_array($this->request->post['customer_group_id'], $this->config->get('customer_group_display'))) { $customer_group_id = $this->request->post['customer_group_id']; } else { $customer_group_id = $this->config->get('customer_group_id'); } $customer_group = $this->model_account_customer_group->getCustomerGroup($customer_group_id); if ($customer_group) { // Company ID if ($customer_group['company_id_display'] && $customer_group['company_id_required'] && empty($this->request->post['company_id'])) { $this->error['company_id'] = Language::getVar('SUMO_NOUN_ERROR_COMPANY'); } // Tax ID if ($customer_group['tax_id_display'] && $customer_group['tax_id_required'] && empty($this->request->post['tax_id'])) { $this->error['tax_id'] = Language::getVar('SUMO_NOUN_ERROR_TAX'); } } if (utf8_strlen($this->request->post['address_1']) < 3 || utf8_strlen($this->request->post['address_1']) > 128) { $this->error['address_1'] = Language::getVar('SUMO_NOUN_ERROR_ADDRESS'); } if (utf8_strlen($this->request->post['city']) < 2 || utf8_strlen($this->request->post['city']) > 128) { $this->error['city'] = Language::getVar('SUMO_NOUN_ERROR_CITY'); } $country_info = $this->model_localisation_country->getCountry($this->request->post['country_id']); if ($country_info) { if ($country_info['postcode_required'] && utf8_strlen($this->request->post['postcode']) < 2 || utf8_strlen($this->request->post['postcode']) > 6) { $this->error['postcode'] = Language::getVar('SUMO_NOUN_ERROR_POSTAL_CODE'); } // VAT Validation $this->load->helper('vat'); if ($this->request->post['tax_id'] && vat_validation($country_info['iso_code_2'], $this->request->post['tax_id']) == 'invalid') { $this->error['tax_id'] = Language::getVar('SUMO_NOUN_ERROR_VAT'); } } if ($this->request->post['country_id'] == '') { $this->error['country'] = Language::getVar('SUMO_NOUN_ERROR_COUNTRY'); } if (!isset($this->request->post['zone_id']) || $this->request->post['zone_id'] == '') { $this->error['zone'] = Language::getVar('SUMO_NOUN_ERROR_ZONE'); } $password = $this->request->post['password']; if (empty($password) || utf8_strlen($this->request->post['password']) < 4) { $this->error['password'] = Language::getVar('SUMO_NOUN_ERROR_PASSWORD_UNSAFE'); } if ($this->request->post['confirm'] != $this->request->post['password']) { $this->error['confirm'] = Language::getVar('SUMO_NOUN_ERROR_PASSWORD_CONFIRM'); } if ($this->config->get('customer_policy_id')) { $information_info = $this->model_catalog_information->getInformation($this->config->get('customer_policy_id')); if ($information_info && !isset($this->request->post['agree'])) { $this->error['warning'] = Language::getVar('SUMO_NOUN_ACCOUNT_AGREE_PAGE', array($this->url->link('information/information/info', 'information_id=' . $information_info['information_id']), $information_info['title'])); } } if (!$this->error) { return true; } return false; }
protected function validateForm() { if (!$this->user->hasPermission('modify', 'sale/customer')) { $this->error['warning'] = $this->language->get('error_permission'); } if (utf8_strlen($this->request->post['firstname']) < 1 || utf8_strlen($this->request->post['firstname']) > 32) { $this->error['firstname'] = $this->language->get('error_firstname'); } if (utf8_strlen($this->request->post['lastname']) < 1 || utf8_strlen($this->request->post['lastname']) > 32) { $this->error['lastname'] = $this->language->get('error_lastname'); } if (utf8_strlen($this->request->post['email']) > 96 || !preg_match('/^[^\\@]+@.*.[a-z]{2,15}$/i', $this->request->post['email'])) { $this->error['email'] = $this->language->get('error_email'); } $customer_info = $this->model_sale_customer->getCustomerByEmail($this->request->post['email']); if (!isset($this->request->get['customer_id'])) { if ($customer_info) { $this->error['warning'] = $this->language->get('error_exists'); } } else { if ($customer_info && $this->request->get['customer_id'] != $customer_info['customer_id']) { $this->error['warning'] = $this->language->get('error_exists'); } } if (utf8_strlen($this->request->post['telephone']) < 3 || utf8_strlen($this->request->post['telephone']) > 32) { $this->error['telephone'] = $this->language->get('error_telephone'); } if (isset($this->request->post['date_of_birth']) && utf8_strlen($this->request->post['date_of_birth']) == 10) { if ($this->request->post['date_of_birth'] != date('Y-m-d', strtotime($this->request->post['date_of_birth']))) { $this->error['date_of_birth'] = $this->language->get('error_date_of_birth'); } } else { $this->error['date_of_birth'] = $this->language->get('error_date_of_birth'); } if ($this->request->post['password'] || !isset($this->request->get['customer_id'])) { if (utf8_strlen($this->request->post['password']) < 4 || utf8_strlen($this->request->post['password']) > 20) { $this->error['password'] = $this->language->get('error_password'); } if ($this->request->post['password'] != $this->request->post['confirm']) { $this->error['confirm'] = $this->language->get('error_confirm'); } } if (isset($this->request->post['address'])) { foreach ($this->request->post['address'] as $key => $value) { if (utf8_strlen($value['firstname']) < 1 || utf8_strlen($value['firstname']) > 32) { $this->error['address_firstname'][$key] = $this->language->get('error_firstname'); } if (utf8_strlen($value['lastname']) < 1 || utf8_strlen($value['lastname']) > 32) { $this->error['address_lastname'][$key] = $this->language->get('error_lastname'); } if (utf8_strlen($value['address_1']) < 3 || utf8_strlen($value['address_1']) > 128) { $this->error['address_address_1'][$key] = $this->language->get('error_address_1'); } if (utf8_strlen($value['city']) < 2 || utf8_strlen($value['city']) > 128) { $this->error['address_city'][$key] = $this->language->get('error_city'); } $this->load->model('localisation/country'); $country_info = $this->model_localisation_country->getCountry($value['country_id']); if ($country_info) { if ($country_info['postcode_required'] && utf8_strlen($value['postcode']) < 2 || utf8_strlen($value['postcode']) > 10) { $this->error['address_postcode'][$key] = $this->language->get('error_postcode'); } // VAT Validation $this->load->model('sale/customer_group'); 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'))) { $customer_group_id = $this->request->post['customer_group_id']; } else { $customer_group_id = $this->config->get('config_customer_group_id'); } $customer_group = $this->model_sale_customer_group->getCustomerGroup($customer_group_id); if ($customer_group && $customer_group['tax_id_display']) { $this->load->helper('vat'); if ($this->config->get('config_vat') && $value['tax_id'] != '' && vat_validation($country_info['iso_code_2'], $value['tax_id']) == 'invalid') { $this->error['address_tax_id'][$key] = $this->language->get('error_vat'); } } } if ($value['country_id'] == '') { $this->error['address_country'][$key] = $this->language->get('error_country'); } if (!isset($value['zone_id']) || $value['zone_id'] == '') { $this->error['address_zone'][$key] = $this->language->get('error_zone'); } } } if ($this->error && !isset($this->error['warning'])) { $this->error['warning'] = $this->language->get('error_warning'); } if (!$this->error) { return true; } else { return false; } }
private function validateForm() { if (utf8_strlen($this->request->post['firstname']) < 1 || utf8_strlen($this->request->post['firstname']) > 32) { $this->error['firstname'] = $this->language->get('error_firstname'); } if (utf8_strlen($this->request->post['lastname']) < 1 || utf8_strlen($this->request->post['lastname']) > 32) { $this->error['lastname'] = $this->language->get('error_lastname'); } if (utf8_strlen($this->request->post['address_1']) < 3 || utf8_strlen($this->request->post['address_1']) > 128) { $this->error['address_1'] = $this->language->get('error_address_1'); } if (utf8_strlen($this->request->post['city']) < 2 || utf8_strlen($this->request->post['city']) > 128) { $this->error['city'] = $this->language->get('error_city'); } $this->load->model('localisation/country'); $country_info = $this->model_localisation_country->getCountry($this->request->post['country_id']); if ($country_info) { if ($country_info['postcode_required'] && utf8_strlen($this->request->post['postcode']) < 2 || utf8_strlen($this->request->post['postcode']) > 10) { $this->error['postcode'] = $this->language->get('error_postcode'); } // VAT Validation $this->load->helper('vat'); if ($this->config->get('config_vat') && !empty($this->request->post['tax_id']) && vat_validation($country_info['iso_code_2'], $this->request->post['tax_id']) == 'invalid') { $this->error['tax_id'] = $this->language->get('error_vat'); } } if ($this->request->post['country_id'] == '') { $this->error['country'] = $this->language->get('error_country'); } if ($this->request->post['zone_id'] == '') { $this->error['zone'] = $this->language->get('error_zone'); } /*Verify Postal*/ $this->load->model('ocean/urlredirect'); $verifyPostal = $this->model_ocean_urlredirect->verifyPostal($this->request->post['postcode'], $this->request->post['city'], $this->request->post['zone_id'], $this->request->post['country_id']); if (empty($verifyPostal)) { $this->error['postcode'] = ERROR_POSTAL_VERIFICATION; } /*End Verify Postal*/ /*Verify City*/ $verifyCity = $this->model_ocean_urlredirect->verifyCity($this->request->post['city'], $this->request->post['zone_id'], $this->request->post['country_id']); if (empty($verifyCity)) { $this->error['city'] = ERROR_CITY_VERIFICATION; } /*End Verify City*/ if (!$this->error) { return true; } else { return false; } }
protected function validate() { if (utf8_strlen($this->request->post['firstname']) < 1 || utf8_strlen($this->request->post['firstname']) > 32) { $this->error['firstname'] = $this->language->get('error_firstname'); } if (utf8_strlen($this->request->post['lastname']) < 1 || utf8_strlen($this->request->post['lastname']) > 32) { $this->error['lastname'] = $this->language->get('error_lastname'); } if (utf8_strlen($this->request->post['email']) > 96 || !preg_match('/^[^\\@]+@.*\\.[a-z]{2,6}$/i', $this->request->post['email'])) { $this->error['email'] = $this->language->get('error_email'); } if ($this->model_account_customer->getTotalCustomersByEmail($this->request->post['email'])) { $this->error['warning'] = $this->language->get('error_exists'); } if (utf8_strlen($this->request->post['telephone']) < 3 || utf8_strlen($this->request->post['telephone']) > 32 || !is_numeric($this->request->post['telephone'])) { $this->error['telephone'] = $this->language->get('error_telephone'); } // Customer Group $this->load->model('account/customer_group'); 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'))) { $customer_group_id = $this->request->post['customer_group_id']; } else { $customer_group_id = $this->config->get('config_customer_group_id'); } $customer_group = $this->model_account_customer_group->getCustomerGroup($customer_group_id); if ($customer_group) { // Company ID if ($customer_group['company_id_display'] && $customer_group['company_id_required'] && empty($this->request->post['company_id'])) { $this->error['company_id'] = $this->language->get('error_company_id'); } // Tax ID // if ($customer_group['tax_id_display'] && $customer_group['tax_id_required'] && empty($this->request->post['tax_id'])) { // $this->error['tax_id'] = $this->language->get('error_tax_id'); // } } if (utf8_strlen($this->request->post['address_1']) < 3 || utf8_strlen($this->request->post['address_1']) > 128) { $this->error['address_1'] = $this->language->get('error_address_1'); } if (utf8_strlen($this->request->post['city']) < 2 || utf8_strlen($this->request->post['city']) > 128) { $this->error['city'] = $this->language->get('error_city'); } $this->load->model('localisation/country'); $country_info = $this->model_localisation_country->getCountry($this->request->post['country_id']); if ($country_info) { if ($country_info['postcode_required'] && utf8_strlen($this->request->post['postcode']) < 6 || utf8_strlen($this->request->post['postcode']) > 6 || !is_numeric($this->request->post['postcode'])) { $this->error['postcode'] = $this->language->get('error_postcode'); } // VAT Validation $this->load->helper('vat'); if ($this->config->get('config_vat') && $this->request->post['tax_id'] && vat_validation($country_info['iso_code_2'], $this->request->post['tax_id']) == 'invalid') { $this->error['tax_id'] = $this->language->get('error_vat'); } } if ($this->request->post['country_id'] == '') { $this->error['country'] = $this->language->get('error_country'); } if (!isset($this->request->post['zone_id']) || $this->request->post['zone_id'] == '') { $this->error['zone'] = $this->language->get('error_zone'); } if (utf8_strlen($this->request->post['password']) < 4 || utf8_strlen($this->request->post['password']) > 20) { $this->error['password'] = $this->language->get('error_password'); } if ($this->request->post['confirm'] != $this->request->post['password']) { $this->error['confirm'] = $this->language->get('error_confirm'); } if ($this->config->get('config_account_id')) { $this->load->model('catalog/information'); $information_info = $this->model_catalog_information->getInformation($this->config->get('config_account_id')); if ($information_info && !isset($this->request->post['agree'])) { $this->error['warning'] = sprintf($this->language->get('error_agree'), $information_info['title']); } } if (!$this->error) { return true; } else { return false; } }
protected function validateForm() { if (!$this->user->hasPermission('modify', 'sale/customer')) { $this->error['warning'] = $this->language->get('error_permission'); } if (utf8_strlen($this->request->post['firstname']) < 1 || utf8_strlen($this->request->post['firstname']) > 32) { $this->error['firstname'] = $this->language->get('error_firstname'); } if (utf8_strlen($this->request->post['lastname']) < 1 || utf8_strlen($this->request->post['lastname']) > 32) { $this->error['lastname'] = $this->language->get('error_lastname'); } if (utf8_strlen($this->request->post['email']) > 96 || !$this->ocstore->validate($this->request->post['email'])) { $this->error['email'] = $this->language->get('error_email'); } $customer_info = $this->model_sale_customer->getCustomerByEmail($this->request->post['email']); if (!isset($this->request->get['customer_id'])) { if ($customer_info) { $this->error['warning'] = $this->language->get('error_exists'); } } else { if ($customer_info && $this->request->get['customer_id'] != $customer_info['customer_id']) { $this->error['warning'] = $this->language->get('error_exists'); } } if (utf8_strlen($this->request->post['telephone']) < 3 || utf8_strlen($this->request->post['telephone']) > 32) { $this->error['telephone'] = $this->language->get('error_telephone'); } if ($this->request->post['password'] || !isset($this->request->get['customer_id'])) { if (utf8_strlen($this->request->post['password']) < 4 || utf8_strlen($this->request->post['password']) > 20) { $this->error['password'] = $this->language->get('error_password'); } if ($this->request->post['password'] != $this->request->post['confirm']) { $this->error['confirm'] = $this->language->get('error_confirm'); } } if (isset($this->request->post['address'])) { foreach ($this->request->post['address'] as $key => $value) { if (utf8_strlen($value['firstname']) < 1 || utf8_strlen($value['firstname']) > 32) { $this->error['address_firstname'][$key] = $this->language->get('error_firstname'); } if (utf8_strlen($value['lastname']) < 1 || utf8_strlen($value['lastname']) > 32) { $this->error['address_lastname'][$key] = $this->language->get('error_lastname'); } if (utf8_strlen($value['address_1']) < 3 || utf8_strlen($value['address_1']) > 128) { $this->error['address_address_1'][$key] = $this->language->get('error_address_1'); } if (utf8_strlen($value['city']) < 2 || utf8_strlen($value['city']) > 128) { $this->error['address_city'][$key] = $this->language->get('error_city'); } $this->load->model('localisation/country'); $country_info = $this->model_localisation_country->getCountry($value['country_id']); if ($country_info) { if ($country_info['postcode_required'] && utf8_strlen($value['postcode']) < 2 || utf8_strlen($value['postcode']) > 10) { $this->error['address_postcode'][$key] = $this->language->get('error_postcode'); } // VAT Validation $this->load->helper('vat'); if ($this->config->get('config_vat') && $value['tax_id'] && vat_validation($country_info['iso_code_2'], $value['tax_id']) == 'invalid') { $this->error['address_tax_id'][$key] = $this->language->get('error_vat'); } } if ($value['country_id'] == '') { $this->error['address_country'][$key] = $this->language->get('error_country'); } if (!isset($value['zone_id']) || $value['zone_id'] == '') { $this->error['address_zone'][$key] = $this->language->get('error_zone'); } } } if ($this->error && !isset($this->error['warning'])) { $this->error['warning'] = $this->language->get('error_warning'); } if (!$this->error) { return true; } else { return false; } }
public function invalid($value, $data = array()) { $result = false; if (isset($data['not_empty'])) { $result = empty($value) ? true : false; } if (isset($data['min_length']) && !$result) { $result = utf8_strlen($value) < $data['min_length'] ? true : false; } if (isset($data['max_length']) && !$result) { $result = utf8_strlen($value) > $data['max_length'] ? true : false; } if (isset($data['vat_address']) && !$result) { $result = vat_validation($this->checkout[$data['vat_address']]['iso_code_2'], $value) == 'invalid' ? true : false; } if (isset($data['compare_to']) && !$result) { $field = explode("[", $data['compare_to']); $field[1] = str_replace("]", "", $field[1]); $data['compare_to'] = isset($this->checkout[$field[0]][$field[1]]) ? $this->checkout[$field[0]][$field[1]] : ''; $result = $value != $data['compare_to'] ? true : false; } if (isset($data['regex']) && !$result) { $result = !preg_match($data['regex'], $value) ? true : false; } if (isset($data['email_exists']) && !$result) { $result = $this->model_account_customer->getTotalCustomersByEmail($value) ? true : false; } if (isset($data['checked']) && !$result) { $result = !$value; } return $result; }
public function payment_address_validate(&$data = array()) { $opencart2 = $data['opencart2'] = (int) substr(VERSION, 0, 1) == 2; if ($data['opencart2']) { $this->load->language('checkout/checkout'); } else { $this->language->load('checkout/checkout'); } $json = array(); // Validate if customer is logged in. if (!$this->customer->isLogged()) { //$json['redirect'] = $this->url->link('checkout/checkout', '', 'SSL'); } // Validate cart has products and has stock. if (!$this->cart->hasProducts() && empty($this->session->data['vouchers']) || !$this->cart->hasStock() && !$this->config->get('config_stock_checkout')) { // $json['redirect'] = $this->url->link('checkout/cart'); } // Validate minimum quantity requirments. $products = $this->cart->getProducts(); foreach ($products as $product) { $product_total = 0; foreach ($products as $product_2) { if ($product_2['product_id'] == $product['product_id']) { $product_total += $product_2['quantity']; } } if ($product['minimum'] > $product_total) { $json['redirect'] = $this->url->link('checkout/cart'); break; } } if ($data['opencart2']) { if (!$json) { if (isset($this->request->post['payment_address']) && $this->request->post['payment_address'] == 'existing') { $this->load->model('account/address'); if (empty($this->request->post['payment_address_id'])) { $json['error']['warning'] = $this->language->get('error_address'); } elseif (!in_array($this->request->post['payment_address_id'], array_keys($this->model_account_address->getAddresses()))) { $json['error']['warning'] = $this->language->get('error_address'); } if (!$json) { // Default Payment Address $this->load->model('account/address'); $this->session->data['payment_address'] = $this->model_account_address->getAddress($this->request->post['payment_address_id']); //unset($this->session->data['payment_method']); //unset($this->session->data['payment_methods']); } } else { if (!isset($this->request->post['firstname']) || (utf8_strlen(trim($this->request->post['firstname'])) < 1 || utf8_strlen(trim($this->request->post['firstname'])) > 32)) { $json['error']['firstname'] = $this->language->get('error_firstname'); } if (!isset($this->request->post['lastname']) || (utf8_strlen(trim($this->request->post['lastname'])) < 1 || utf8_strlen(trim($this->request->post['lastname'])) > 32)) { $json['error']['lastname'] = $this->language->get('error_lastname'); } if (!isset($this->request->post['address_1']) || (utf8_strlen(trim($this->request->post['address_1'])) < 3 || utf8_strlen(trim($this->request->post['address_1'])) > 128)) { $json['error']['address_1'] = $this->language->get('error_address_1'); } if (!isset($this->request->post['city']) || (utf8_strlen($this->request->post['city']) < 2 || utf8_strlen($this->request->post['city']) > 32)) { $json['error']['city'] = $this->language->get('error_city'); } $this->load->model('localisation/country'); if (isset($this->request->post['country_id'])) { $country_info = $this->model_localisation_country->getCountry($this->request->post['country_id']); } if (isset($country_info) && $country_info['postcode_required'] && (utf8_strlen(trim($this->request->post['postcode'])) < 2 || utf8_strlen(trim($this->request->post['postcode'])) > 10)) { $json['error']['postcode'] = $this->language->get('error_postcode'); } if (!isset($this->request->post['country_id']) || $this->request->post['country_id'] == '') { $json['error']['country_id'] = $this->language->get('error_country'); } if (!isset($this->request->post['zone_id']) || $this->request->post['zone_id'] == '') { $json['error']['zone_id'] = $this->language->get('error_zone'); } // Custom field validation $this->load->model('account/custom_field'); $custom_fields = $this->model_account_custom_field->getCustomFields(array('filter_customer_group_id' => $this->config->get('config_customer_group_id'))); foreach ($custom_fields as $custom_field) { if ($custom_field['location'] == 'address' && $custom_field['required'] && empty($this->request->post['custom_field'][$custom_field['custom_field_id']])) { $json['error']['custom_field'][$custom_field['custom_field_id']] = sprintf($this->language->get('error_custom_field'), $custom_field['name']); } } if (!$json) { // Default Payment Address $this->load->model('account/address'); $address_id = $this->model_account_address->addAddress($this->request->post); $this->session->data['payment_address'] = $this->model_account_address->getAddress($address_id); //unset($this->session->data['payment_method']); //unset($this->session->data['payment_methods']); /* $activity_data = array( 'customer_id' => $this->customer->getId(), 'name' => $this->customer->getFirstName() . ' ' . $this->customer->getLastName() ); $this->model_account_activity->addActivity('address_add', $activity_data); */ } } } } else { if (!$json) { if (isset($this->request->post['payment_address']) && $this->request->post['payment_address'] == 'existing') { $this->load->model('account/address'); if (empty($this->request->post['payment_address_id'])) { $json['error']['warning'] = $this->language->get('error_address'); } elseif (!in_array($this->request->post['payment_address_id'], array_keys($this->model_account_address->getAddresses()))) { $json['error']['warning'] = $this->language->get('error_address'); } else { // Default Payment Address $this->load->model('account/address'); $address_info = $this->model_account_address->getAddress($this->request->post['payment_address_id']); if ($address_info) { $this->load->model('account/customer_group'); $customer_group_info = $this->model_account_customer_group->getCustomerGroup($this->customer->getCustomerGroupId()); // Company ID if ($customer_group_info['company_id_display'] && $customer_group_info['company_id_required'] && !$address_info['company_id']) { $json['error']['warning'] = $this->language->get('error_company_id'); } // Tax ID if ($customer_group_info['tax_id_display'] && $customer_group_info['tax_id_required'] && !$address_info['tax_id']) { $json['error']['warning'] = $this->language->get('error_tax_id'); } } } if (!$json) { $this->session->data['payment_address_id'] = $this->request->post['payment_address_id']; if ($address_info) { $this->session->data['payment_country_id'] = $address_info['country_id']; $this->session->data['payment_zone_id'] = $address_info['zone_id']; } else { unset($this->session->data['payment_country_id']); unset($this->session->data['payment_zone_id']); } //unset($this->session->data['payment_method']); //unset($this->session->data['payment_methods']); } } else { if (!isset($this->request->post['firstname']) || (utf8_strlen(trim($this->request->post['firstname'])) < 1 || utf8_strlen(trim($this->request->post['firstname'])) > 32)) { $json['error']['firstname'] = $this->language->get('error_firstname'); } if (!isset($this->request->post['lastname']) || (utf8_strlen(trim($this->request->post['lastname'])) < 1 || utf8_strlen(trim($this->request->post['lastname'])) > 32)) { $json['error']['lastname'] = $this->language->get('error_lastname'); } if (!isset($this->request->post['address_1']) || (utf8_strlen(trim($this->request->post['address_1'])) < 3 || utf8_strlen(trim($this->request->post['address_1'])) > 128)) { $json['error']['address_1'] = $this->language->get('error_address_1'); } if (!isset($this->request->post['city']) || (utf8_strlen($this->request->post['city']) < 2 || utf8_strlen($this->request->post['city']) > 32)) { $json['error']['city'] = $this->language->get('error_city'); } // Customer Group $this->load->model('account/customer_group'); $customer_group_info = $this->model_account_customer_group->getCustomerGroup($this->customer->getCustomerGroupId()); if ($customer_group_info) { // Company ID if ($customer_group_info['company_id_display'] && $customer_group_info['company_id_required'] && empty($this->request->post['company_id'])) { $json['error']['company_id'] = $this->language->get('error_company_id'); } // Tax ID if ($customer_group_info['tax_id_display'] && $customer_group_info['tax_id_required'] && empty($this->request->post['tax_id'])) { $json['error']['tax_id'] = $this->language->get('error_tax_id'); } } $this->load->model('localisation/country'); if (isset($this->request->post['country_id'])) { $country_info = $this->model_localisation_country->getCountry($this->request->post['country_id']); } if (isset($country_info)) { if ($country_info['postcode_required'] && utf8_strlen($this->request->post['postcode']) < 2 || utf8_strlen($this->request->post['postcode']) > 10) { $json['error']['postcode'] = $this->language->get('error_postcode'); } // VAT Validation $this->load->helper('vat'); if ($this->config->get('config_vat') && !empty($this->request->post['tax_id']) && vat_validation($country_info['iso_code_2'], $this->request->post['tax_id']) == 'invalid') { $json['error']['tax_id'] = $this->language->get('error_vat'); } } if (!isset($this->request->post['country_id']) || $this->request->post['country_id'] == '') { $json['error']['country_id'] = $this->language->get('error_country'); } if (!isset($this->request->post['zone_id']) || $this->request->post['zone_id'] == '') { $json['error']['zone_id'] = $this->language->get('error_zone'); } if (!$json) { // Default Payment Address $this->load->model('account/address'); $this->session->data['payment_address_id'] = $this->model_account_address->addAddress($this->request->post); $this->session->data['payment_country_id'] = $this->request->post['country_id']; $this->session->data['payment_zone_id'] = $this->request->post['zone_id']; //unset($this->session->data['payment_method']); //unset($this->session->data['payment_methods']); } } } } return $json; }
public function validate() { $this->language->load('onepage/checkout'); $json = array(); // Validate if customer is logged in. if (!$this->customer->isLogged()) { $json['redirect'] = $this->url->link('onepage/checkout', '', 'SSL'); } // Validate cart has products and has stock. if (!$this->cart->hasProducts() && empty($this->session->data['vouchers']) || !$this->cart->hasStock() && !$this->config->get('config_stock_checkout')) { $json['redirect'] = $this->url->link('onepage/cart'); } // Validate minimum quantity requirments. $products = $this->cart->getProducts(); foreach ($products as $product) { $product_total = 0; foreach ($products as $product_2) { if ($product_2['product_id'] == $product['product_id']) { $product_total += $product_2['quantity']; } } if ($product['minimum'] > $product_total) { $json['redirect'] = $this->url->link('onepage/cart'); break; } } if (!$json) { if (isset($this->request->post['payment_address']) && $this->request->post['payment_address'] == 'existing') { $this->load->model('account/address'); if (empty($this->request->post['address_id'])) { $json['error']['warning'] = $this->language->get('error_address'); } elseif (!in_array($this->request->post['address_id'], array_keys($this->model_account_address->getAddresses()))) { $json['error']['warning'] = $this->language->get('error_address'); } else { // Default Payment Address $this->load->model('account/address'); $address_info = $this->model_account_address->getAddress($this->request->post['address_id']); if ($address_info) { $this->load->model('account/customer_group'); $customer_group_info = $this->model_account_customer_group->getCustomerGroup($this->customer->getCustomerGroupId()); // Company ID if ($customer_group_info['company_id_display'] && $customer_group_info['company_id_required'] && !$address_info['company_id']) { $json['error']['warning'] = $this->language->get('error_company_id'); } // Tax ID if ($customer_group_info['tax_id_display'] && $customer_group_info['tax_id_required'] && !$address_info['tax_id']) { $json['error']['warning'] = $this->language->get('error_tax_id'); } } } if (!$json) { $this->session->data['payment_address_id'] = $this->request->post['address_id']; if ($address_info) { $this->session->data['payment_country_id'] = $address_info['country_id']; $this->session->data['payment_zone_id'] = $address_info['zone_id']; } else { unset($this->session->data['payment_country_id']); unset($this->session->data['payment_zone_id']); } unset($this->session->data['payment_method']); unset($this->session->data['payment_methods']); } } else { if (utf8_strlen($this->request->post['firstname']) < 1 || utf8_strlen($this->request->post['firstname']) > 32) { $json['error']['firstname'] = $this->language->get('error_firstname'); } if (utf8_strlen($this->request->post['lastname']) < 1 || utf8_strlen($this->request->post['lastname']) > 32) { $json['error']['lastname'] = $this->language->get('error_lastname'); } // Customer Group $this->load->model('account/customer_group'); $customer_group_info = $this->model_account_customer_group->getCustomerGroup($this->customer->getCustomerGroupId()); if ($customer_group_info) { // Company ID if ($customer_group_info['company_id_display'] && $customer_group_info['company_id_required'] && empty($this->request->post['company_id'])) { $json['error']['company_id'] = $this->language->get('error_company_id'); } // Tax ID if ($customer_group_info['tax_id_display'] && $customer_group_info['tax_id_required'] && empty($this->request->post['tax_id'])) { $json['error']['tax_id'] = $this->language->get('error_tax_id'); } } if (utf8_strlen($this->request->post['address_1']) < 3 || utf8_strlen($this->request->post['address_1']) > 128) { $json['error']['address_1'] = $this->language->get('error_address_1'); } if (utf8_strlen($this->request->post['city']) < 2 || utf8_strlen($this->request->post['city']) > 32) { $json['error']['city'] = $this->language->get('error_city'); } $this->load->model('localisation/country'); $country_info = $this->model_localisation_country->getCountry($this->request->post['country_id']); if ($country_info) { if ($country_info['postcode_required'] && utf8_strlen($this->request->post['postcode']) < 2 || utf8_strlen($this->request->post['postcode']) > 10) { $json['error']['postcode'] = $this->language->get('error_postcode'); } // VAT Validation $this->load->helper('vat'); if ($this->config->get('config_vat') && !empty($this->request->post['tax_id']) && vat_validation($country_info['iso_code_2'], $this->request->post['tax_id']) == 'invalid') { $json['error']['tax_id'] = $this->language->get('error_vat'); } } if ($this->request->post['country_id'] == '') { $json['error']['country'] = $this->language->get('error_country'); } if (!isset($this->request->post['zone_id']) || $this->request->post['zone_id'] == '') { $json['error']['zone'] = $this->language->get('error_zone'); } //jalen $this->load->helper('validation_form'); $phoneSection = $this->request->post['phoneSection']; $phoneCode = $this->request->post['phoneCode']; $phoneExt = $this->request->post['phoneExt']; $phone = connection_phone($phoneSection, $phoneCode, $phoneExt); $this->request->post['phone'] = $phone; if (!validation_mobile($this->request->post['mobile']) && !$phoneSection && !$phoneCode && !$phoneExt) { $json['error']['mobile'] = $this->language->get('error_mobile'); } elseif (!$this->request->post['mobile'] && !validation_phone($phone)) { $json['error']['phoneExt'] = $this->language->get('error_phoneExt'); } elseif (!validation_mobile($this->request->post['mobile']) && !validation_phone($phone)) { $json['error']['mobile'] = $this->language->get('error_mobile'); $json['error']['phoneExt'] = $this->language->get('error_phoneExt'); } $postcode = $this->request->post['postcode']; if ($postcode && !check_postcode($postcode)) { $json['error']['postcode'] = $this->language->get('error_postcode'); } if (!$json) { // Default Payment Address $this->load->model('account/address'); $this->session->data['payment_address_id'] = $this->session->data['shipping_address_id'] = $this->model_account_address->addAddress($this->request->post); $this->session->data['payment_country_id'] = $this->request->post['country_id']; $this->session->data['payment_zone_id'] = $this->request->post['zone_id']; //返回数据 $json_address = $this->model_account_address->getAddress($this->session->data['payment_address_id']); $json['address'] = '<dl class="item selected"> <dt>' . $json_address['firstname'] . ' ' . $json_address['lastname'] . '</dt> <dd> <p class="tel">' . $json_address['mobile'] . '</p> <p>' . $json_address['country'] . ' ' . $json_address['zone'] . ' ' . $json_address['city'] . ' ' . $json_address['address_1'] . ' </p> <p>' . $json_address['address_1'] . '</p> </dd> <dd style="display:none"> <input type="radio" name="address_id" class="addressId" value="' . $this->session->data['payment_address_id'] . '"> </dd> </dl>'; //unset($this->session->data['payment_method']); //unset($this->session->data['payment_methods']); } } } $this->response->setOutput(json_encode($json)); }
public function index() { $this->language->load('onecheckout/checkout'); $this->load->model('onecheckout/checkout'); $version_int = $this->model_onecheckout_checkout->versiontoint(); $json = array(); if ($this->customer->isLogged()) { $json['redirect'] = $this->url->link('onecheckout/checkout', '', 'SSL'); } if (!$this->cart->hasProducts() && (!isset($this->session->data['vouchers']) || !$this->session->data['vouchers']) || !$this->cart->hasStock() && !$this->config->get('config_stock_checkout')) { $json['redirect'] = $this->url->link('checkout/cart'); } if (!$this->config->get('config_guest_checkout') || $this->cart->hasDownload()) { $json['redirect'] = $this->url->link('onecheckout/checkout', '', 'SSL'); } if ($this->request->server['REQUEST_METHOD'] == 'POST') { if (!$json) { if (strlen(utf8_decode($this->request->post['firstname'])) < 1 || strlen(utf8_decode($this->request->post['firstname'])) > 32) { $json['error']['firstname'] = $this->language->get('error_firstname'); } if (strlen(utf8_decode($this->request->post['lastname'])) < 1 || strlen(utf8_decode($this->request->post['lastname'])) > 32) { $json['error']['lastname'] = $this->language->get('error_lastname'); } if ($this->request->post['birthday_day'] == '' || $this->request->post['birthday_month'] == '' || $this->request->post['birthday_year'] == '') { $json['error']['birthday'] = $this->language->get('error_birthday'); } if (strlen(utf8_decode($this->request->post['email'])) > 96 || !preg_match('/^[^\\@]+@.*\\.[a-z]{2,6}$/i', $this->request->post['email'])) { $json['error']['email'] = $this->language->get('error_email'); } if (strlen(utf8_decode($this->request->post['telephone'])) < 3 || strlen(utf8_decode($this->request->post['telephone'])) > 32) { $json['error']['telephone'] = $this->language->get('error_telephone'); } //version if ($version_int >= 1530) { // Customer Group $this->load->model('account/customer_group'); 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'))) { $customer_group_id = $this->request->post['customer_group_id']; } else { $customer_group_id = $this->config->get('config_customer_group_id'); } $customer_group = $this->model_account_customer_group->getCustomerGroup($customer_group_id); if ($customer_group) { // Company ID if ($customer_group['company_id_display'] && $customer_group['company_id_required'] && empty($this->request->post['company_id'])) { $json['error']['company_id'] = $this->language->get('error_company_id'); } // Tax ID if ($customer_group['tax_id_display'] && $customer_group['tax_id_required'] && empty($this->request->post['tax_id'])) { $json['error']['tax_id'] = $this->language->get('error_tax_id'); } } } if (strlen(utf8_decode($this->request->post['address_1'])) < 3 || strlen(utf8_decode($this->request->post['address_1'])) > 128) { $json['error']['address_1'] = $this->language->get('error_address_1'); } $country_info = $this->model_onecheckout_checkout->getCountry($this->request->post['country_id']); if ($country_info) { if ($country_info['postcode_required'] && strlen(utf8_decode($this->request->post['postcode'])) < 2 || strlen(utf8_decode($this->request->post['postcode'])) > 10) { $json['error']['postcode'] = $this->language->get('error_postcode'); } if ($version_int >= 1530) { // VAT Validation $this->load->helper('vat'); if ($this->config->get('config_vat') && $this->request->post['tax_id'] && vat_validation($country_info['iso_code_2'], $this->request->post['tax_id']) == 'invalid') { $json['error']['tax_id'] = $this->language->get('error_vat'); } } } if ($this->request->post['country_id'] == '') { $json['error']['country'] = $this->language->get('error_country'); } if ($this->request->post['zone_id'] == '') { $json['error']['zone'] = $this->language->get('error_zone'); } } if (!$json) { $this->session->data['guest']['customer_group_id'] = isset($customer_group_id) ? $customer_group_id : $this->config->get('config_customer_group_id'); $this->session->data['guest']['firstname'] = $this->request->post['firstname']; $this->session->data['guest']['lastname'] = $this->request->post['lastname']; $this->session->data['guest']['email'] = $this->request->post['email']; $this->session->data['guest']['telephone'] = $this->request->post['telephone']; $this->session->data['guest']['fax'] = $this->request->post['fax']; $this->session->data['guest']['payment']['firstname'] = $this->request->post['firstname']; $this->session->data['guest']['payment']['lastname'] = $this->request->post['lastname']; $this->session->data['guest']['payment']['company'] = $this->request->post['company']; $this->session->data['guest']['payment']['company_id'] = isset($this->request->post['company_id']) ? $this->request->post['company_id'] : ''; $this->session->data['guest']['payment']['tax_id'] = isset($this->request->post['tax_id']) ? $this->request->post['tax_id'] : ''; $this->session->data['guest']['payment']['address_1'] = $this->request->post['address_1']; $this->session->data['guest']['payment']['address_2'] = $this->request->post['address_2']; $this->session->data['guest']['payment']['postcode'] = $this->request->post['postcode']; $this->session->data['guest']['payment']['city'] = $this->request->post['city']; $this->session->data['guest']['payment']['country_id'] = $this->request->post['country_id']; $this->session->data['guest']['payment']['zone_id'] = $this->request->post['zone_id']; $country_info = $this->model_onecheckout_checkout->getCountry($this->request->post['country_id']); if ($country_info) { $this->session->data['guest']['payment']['country'] = $country_info['name']; $this->session->data['guest']['payment']['iso_code_2'] = $country_info['iso_code_2']; $this->session->data['guest']['payment']['iso_code_3'] = $country_info['iso_code_3']; $this->session->data['guest']['payment']['address_format'] = $country_info['address_format']; } else { $this->session->data['guest']['payment']['country'] = ''; $this->session->data['guest']['payment']['iso_code_2'] = ''; $this->session->data['guest']['payment']['iso_code_3'] = ''; $this->session->data['guest']['payment']['address_format'] = ''; } $zone_info = $this->model_onecheckout_checkout->getZone($this->request->post['zone_id']); if ($zone_info) { $this->session->data['guest']['payment']['zone'] = $zone_info['name']; $this->session->data['guest']['payment']['zone_code'] = $zone_info['code']; } else { $this->session->data['guest']['payment']['zone'] = ''; $this->session->data['guest']['payment']['zone_code'] = ''; } if (isset($this->request->post['shipping_address']) && $this->request->post['shipping_address']) { $this->session->data['guest']['shipping_address'] = true; } else { $this->session->data['guest']['shipping_address'] = false; } // Default Payment Address if ($this->config->get('config_tax_customer') == 'payment') { $this->session->data['payment_country_id'] = $this->request->post['country_id']; $this->session->data['payment_zone_id'] = $this->request->post['zone_id']; } if ($this->session->data['guest']['shipping_address']) { $this->session->data['guest']['shipping']['firstname'] = $this->request->post['firstname']; $this->session->data['guest']['shipping']['lastname'] = $this->request->post['lastname']; $this->session->data['guest']['shipping']['company'] = $this->request->post['company']; $this->session->data['guest']['shipping']['address_1'] = $this->request->post['address_1']; $this->session->data['guest']['shipping']['address_2'] = $this->request->post['address_2']; $this->session->data['guest']['shipping']['postcode'] = $this->request->post['postcode']; $this->session->data['guest']['shipping']['city'] = $this->request->post['city']; $this->session->data['guest']['shipping']['country_id'] = $this->request->post['country_id']; $this->session->data['guest']['shipping']['zone_id'] = $this->request->post['zone_id']; if ($country_info) { $this->session->data['guest']['shipping']['country'] = $country_info['name']; $this->session->data['guest']['shipping']['iso_code_2'] = $country_info['iso_code_2']; $this->session->data['guest']['shipping']['iso_code_3'] = $country_info['iso_code_3']; $this->session->data['guest']['shipping']['address_format'] = $country_info['address_format']; } else { $this->session->data['guest']['shipping']['country'] = ''; $this->session->data['guest']['shipping']['iso_code_2'] = ''; $this->session->data['guest']['shipping']['iso_code_3'] = ''; $this->session->data['guest']['shipping']['address_format'] = ''; } if ($zone_info) { $this->session->data['guest']['shipping']['zone'] = $zone_info['name']; $this->session->data['guest']['shipping']['zone_code'] = $zone_info['code']; } else { $this->session->data['guest']['shipping']['zone'] = ''; $this->session->data['guest']['shipping']['zone_code'] = ''; } $version_int = $this->model_onecheckout_checkout->versiontoint(); //version if ($version_int < 1513 && $version_int >= 1500) { $this->tax->setZone($this->request->post['country_id'], $this->request->post['zone_id']); } // Default Shipping Address if ($this->config->get('config_tax_customer') == 'shipping') { $this->session->data['shipping_country_id'] = $this->request->post['country_id']; $this->session->data['shipping_zone_id'] = $this->request->post['zone_id']; $this->session->data['shipping_postcode'] = $this->request->post['postcode']; } } unset($this->session->data['shipping_methods']); unset($this->session->data['shipping_method']); unset($this->session->data['payment_methods']); unset($this->session->data['payment_method']); } } else { $this->data['entry_shipping'] = $this->language->get('entry_shipping'); $this->data['button_continue'] = $this->language->get('button_continue'); $this->data['shipping_required'] = $this->cart->hasShipping(); if (isset($this->session->data['guest']['shipping_address'])) { $this->data['shipping_address'] = $this->session->data['guest']['shipping_address']; } else { $this->data['shipping_address'] = true; } if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/onecheckout/guest.tpl')) { $this->template = $this->config->get('config_template') . '/template/onecheckout/guest.tpl'; } else { $this->template = 'default/template/onecheckout/guest.tpl'; } $json['output'] = $this->render(); } $this->response->setOutput($this->model_onecheckout_checkout->jsonencode($json)); }
public function payment() { $this->language->load('onecheckout/checkout'); $this->load->model('onecheckout/checkout'); $this->load->model('account/customer'); $version_int = $this->model_onecheckout_checkout->versiontoint(); $this->data['version_int'] = $version_int; $json = array(); if (!$this->customer->isLogged()) { $json['redirect'] = $this->url->link('onecheckout/checkout', '', 'SSL'); } if (!$this->model_onecheckout_checkout->getAddresses()) { $json['alert'] = $this->language->get('text_noaddress'); $json['redirect'] = $this->url->link('account/address/insert', '', 'SSL'); } if (!$this->cart->hasProducts() && (!isset($this->session->data['vouchers']) || !$this->session->data['vouchers']) || !$this->cart->hasStock() && !$this->config->get('config_stock_checkout')) { $json['redirect'] = $this->url->link('checkout/cart'); } if ($this->request->server['REQUEST_METHOD'] == 'POST') { if (!$json) { if ($this->request->post['payment_address'] == 'existing') { if (!isset($this->request->post['address_id'])) { $json['error']['warning'] = $this->language->get('error_address'); } if (!$json && $version_int >= 1530) { $this->load->model('account/address'); $existaddress = $this->model_account_address->getAddress($this->request->post['address_id']); if ($existaddress) { $this->load->model('account/customer_group'); $customer_group_info = $this->model_account_customer_group->getCustomerGroup($this->customer->getCustomerGroupId()); // Company ID if ($customer_group_info['company_id_display'] && $customer_group_info['company_id_required'] && !$existaddress['company_id']) { $json['error']['warning'] = $this->language->get('error_company_id'); } // Tax ID if ($customer_group_info['tax_id_display'] && $customer_group_info['tax_id_required'] && !$existaddress['tax_id']) { $json['error']['warning'] = $this->language->get('error_tax_id'); } } } if (!$json) { $this->session->data['payment_address_id'] = $this->request->post['address_id']; // Default Payment Address $address_info = $this->model_onecheckout_checkout->getAddress($this->request->post['address_id']); if ($address_info && $this->config->get('config_tax_customer') == 'payment') { $this->session->data['payment_country_id'] = $address_info['country_id']; $this->session->data['payment_zone_id'] = $address_info['zone_id']; } else { unset($this->session->data['payment_country_id']); unset($this->session->data['payment_zone_id']); } unset($this->session->data['payment_methods']); unset($this->session->data['payment_method']); } } if ($this->request->post['payment_address'] == 'new') { if (strlen(utf8_decode($this->request->post['firstname'])) < 1 || strlen(utf8_decode($this->request->post['firstname'])) > 32) { $json['error']['firstname'] = $this->language->get('error_firstname'); } if (strlen(utf8_decode($this->request->post['lastname'])) < 1 || strlen(utf8_decode($this->request->post['lastname'])) > 32) { $json['error']['lastname'] = $this->language->get('error_lastname'); } //version if ($version_int >= 1530) { // Customer Group $this->load->model('account/customer_group'); /*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'))) { $customer_group_id = $this->request->post['customer_group_id']; } else*/ if ($this->customer->isLogged()) { $customer_group_id = $this->customer->getCustomerGroupId(); } else { $customer_group_id = $this->config->get('config_customer_group_id'); } $customer_group = $this->model_account_customer_group->getCustomerGroup($customer_group_id); if ($customer_group) { // Company ID if ($customer_group['company_id_display'] && $customer_group['company_id_required'] && empty($this->request->post['company_id'])) { $json['error']['company_id'] = $this->language->get('error_company_id'); } // Tax ID if ($customer_group['tax_id_display'] && $customer_group['tax_id_required'] && empty($this->request->post['tax_id'])) { $json['error']['tax_id'] = $this->language->get('error_tax_id'); } } } if (strlen(utf8_decode($this->request->post['address_1'])) < 3 || strlen(utf8_decode($this->request->post['address_1'])) > 64) { $json['error']['address_1'] = $this->language->get('error_address_1'); } $country_info = $this->model_onecheckout_checkout->getCountry($this->request->post['country_id']); if ($country_info) { if ($country_info['postcode_required'] && strlen(utf8_decode($this->request->post['postcode'])) < 2 || strlen(utf8_decode($this->request->post['postcode'])) > 10) { $json['error']['postcode'] = $this->language->get('error_postcode'); } if ($version_int >= 1530) { // VAT Validation $this->load->helper('vat'); if ($this->config->get('config_vat') && $this->request->post['tax_id'] && vat_validation($country_info['iso_code_2'], $this->request->post['tax_id']) == 'invalid') { $json['error']['tax_id'] = $this->language->get('error_vat'); } } } if ($this->request->post['country_id'] == '') { $json['error']['country'] = $this->language->get('error_country'); } if ($this->request->post['zone_id'] == '') { $json['error']['zone'] = $this->language->get('error_zone'); } if (!$json) { $this->session->data['payment_address_id'] = $this->model_onecheckout_checkout->addAddress($this->request->post); unset($this->session->data['payment_methods']); unset($this->session->data['payment_method']); } } } } else { $this->data['text_address_existing'] = $this->language->get('text_address_existing'); $this->data['text_address_new'] = $this->language->get('text_address_new'); $this->data['text_select'] = $this->language->get('text_select'); $this->data['text_none'] = $this->language->get('text_none'); $this->data['entry_firstname'] = $this->language->get('entry_firstname'); $this->data['entry_lastname'] = $this->language->get('entry_lastname'); $this->data['entry_company'] = $this->language->get('entry_company'); $this->data['entry_company_id'] = $this->language->get('entry_company_id'); $this->data['entry_tax_id'] = $this->language->get('entry_tax_id'); $this->data['entry_address_1'] = $this->language->get('entry_address_1'); $this->data['entry_address_2'] = $this->language->get('entry_address_2'); $this->data['entry_postcode'] = $this->language->get('entry_postcode'); $this->data['entry_city'] = $this->language->get('entry_city'); $this->data['entry_country'] = $this->language->get('entry_country'); $this->data['entry_zone'] = $this->language->get('entry_zone'); $this->data['type'] = 'payment'; if (isset($this->session->data['payment_address_id'])) { $this->data['address_id'] = $this->session->data['payment_address_id']; } else { $this->data['address_id'] = $this->customer->getAddressId(); if (!$this->customer->getAddressId()) { $g_addresses = $this->model_onecheckout_checkout->getAddresses(); foreach ($g_addresses as $g_address) { $this->session->data['payment_address_id'] = $g_address['address_id']; $this->data['address_id'] = $g_address['address_id']; } } } // $this->data['entry_fullname'] = $this->language->get('entry_fullname'); $this->data['entry_birthday'] = $this->language->get('entry_birthday'); $this->data['entry_email'] = $this->language->get('entry_email'); $this->data['entry_telephone'] = $this->language->get('entry_telephone'); $this->data['entry_address_1'] = $this->language->get('entry_address_1'); $this->data['text_logged'] = sprintf($this->language->get('text_logged'), $this->url->link('account/account', '', 'SSL'), $this->customer->getLastName() . ' ' . $this->customer->getFirstName(), $this->url->link('account/logout', '', 'SSL')); $this->data['user'] = $this->model_account_customer->getCustomer($this->session->data['customer_id']); //var_dump($this->data['user']); $this->data['payment_address'] = $this->model_onecheckout_checkout->getAddress($this->data['user']['address_id']); $this->data['addresses'] = array(); $this->data['addresses'] = $this->model_onecheckout_checkout->getAddresses(); //version if ($version_int >= 1530) { $this->load->model('account/customer_group'); $customer_group_info = $this->model_account_customer_group->getCustomerGroup($this->customer->getCustomerGroupId()); if ($customer_group_info) { $this->data['company_id_display'] = $customer_group_info['company_id_display']; } else { $this->data['company_id_display'] = ''; } if ($customer_group_info) { $this->data['company_id_required'] = $customer_group_info['company_id_required']; } else { $this->data['company_id_required'] = ''; } if ($customer_group_info) { $this->data['tax_id_display'] = $customer_group_info['tax_id_display']; } else { $this->data['tax_id_display'] = ''; } if ($customer_group_info) { $this->data['tax_id_required'] = $customer_group_info['tax_id_required']; } else { $this->data['tax_id_required'] = ''; } } if (isset($this->session->data['payment_country_id'])) { $this->data['country_id'] = $this->session->data['payment_country_id']; } else { $this->data['country_id'] = $this->config->get('config_country_id'); } if (isset($this->session->data['payment_zone_id'])) { $this->data['zone_id'] = $this->session->data['payment_zone_id']; } else { $this->data['zone_id'] = '3780'; } $this->data['countries'] = $this->model_onecheckout_checkout->getCountries(); if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/onecheckout/address.tpl')) { $this->template = $this->config->get('config_template') . '/template/onecheckout/address.tpl'; } else { $this->template = 'default/template/onecheckout/address.tpl'; } $json['hasshipping'] = $this->cart->hasShipping(); $json['output'] = $this->render(); } $this->response->setOutput($this->model_onecheckout_checkout->jsonencode($json)); }
protected function validateForm() { if (!$this->user->hasPermission('modify', 'sale/customer')) { $this->error[] = Language::getVar('SUMO_ERROR_NO_PERMISSION'); return; } if (utf8_strlen($this->request->post['firstname']) < 1 || utf8_strlen($this->request->post['firstname']) > 32) { $this->error[] = Language::getVar('SUMO_ERROR_FIRSTNAME'); } if (utf8_strlen($this->request->post['lastname']) < 1 || utf8_strlen($this->request->post['lastname']) > 32) { $this->error[] = Language::getVar('SUMO_ERROR_LASTNAME'); } if (utf8_strlen($this->request->post['email']) > 96 || !preg_match('/^[^\\@]+@.*\\.[a-z]{2,6}$/i', $this->request->post['email'])) { $this->error[] = Language::getVar('SUMO_ERROR_EMAIL'); } $customer_info = $this->model_sale_customer->getCustomerByEmail($this->request->post['email']); if (!isset($this->request->get['customer_id'])) { if ($customer_info) { $this->error[] = Language::getVar('SUMO_ERROR_EMAIL_EXISTS'); } } else { if ($customer_info && $this->request->get['customer_id'] != $customer_info['customer_id']) { $this->error[] = Language::getVar('SUMO_ERROR_EMAIL_EXISTS'); } } if (empty($this->request->post['gender'])) { $this->error[] = Language::getVar('SUMO_ERROR_GENDER'); } if (utf8_strlen($this->request->post['telephone']) < 3 || utf8_strlen($this->request->post['telephone']) > 32) { $this->error[] = Language::getVar('SUMO_ERROR_PHONE'); } if (!empty($this->request->post['mobile'])) { if (utf8_strlen($this->request->post['mobile']) < 3 || utf8_strlen($this->request->post['mobile']) > 32) { $this->error[] = Language::getVar('SUMO_ERROR_MOBILE'); } } if ($this->request->post['password'] || !isset($this->request->get['customer_id'])) { if (utf8_strlen($this->request->post['password']) < 4 || utf8_strlen($this->request->post['password']) > 20) { $this->error[] = Language::getVar('SUMO_ERROR_PASSWORD'); } if ($this->request->post['password'] != $this->request->post['confirm']) { $this->error[] = Language::getVar('SUMO_ERROR_PASSWORD_CONFIRM'); } } if (isset($this->request->post['address'])) { foreach ($this->request->post['address'] as $key => $value) { // All fields empty? Continue with next item, we're not using this address if (implode('', $value) == '') { unset($this->request->post['address'][$key]); continue; } if (utf8_strlen($value['firstname']) < 1 || utf8_strlen($value['firstname']) > 32) { $this->error['address_firstname'] = Language::getVar('SUMO_ERROR_FIRSTNAME'); } if (utf8_strlen($value['lastname']) < 1 || utf8_strlen($value['lastname']) > 32) { $this->error['address_lastname'] = Language::getVar('SUMO_ERROR_LASTNAME'); } if (utf8_strlen($value['address_1']) < 3 || utf8_strlen($value['address_1']) > 128) { $this->error['address_address_1'] = Language::getVar('SUMO_ERROR_ADDRESS_1'); } if (strlen($value['number']) < 1 || strlen($value['number']) > 9) { $this->error['address_number'] = Language::getVar('SUMO_ERROR_ADDRESS_NUMBER'); } if (utf8_strlen($value['city']) < 2 || utf8_strlen($value['city']) > 128) { $this->error['address_city'] = Language::getVar('SUMO_ERROR_CITY'); } $this->load->model('localisation/country'); $country_info = $this->model_localisation_country->getCountry($value['country_id']); if ($country_info) { if ($country_info['postcode_required'] && utf8_strlen($value['postcode']) < 2 || utf8_strlen($value['postcode']) > 10) { $this->error['address_postcode'] = Language::getVar('SUMO_ERROR_POSTCODE'); } // VAT Validation $this->load->helper('vat'); if ($this->config->get('vat') && $value['tax_id'] && vat_validation($country_info['iso_code_2'], $value['tax_id']) == 'invalid') { $this->error['address_tax_id'] = Language::getVar('SUMO_ERROR_TAX'); } } if ($value['country_id'] < 1) { $this->error['address_country'] = Language::getVar('SUMO_ERROR_COUNTRY'); } if (!isset($value['zone_id']) || $value['zone_id'] == '') { $this->error['address_zone'] = Language::getVar('SUMO_ERROR_ZONE'); } } } // Do we at least have on address? if (!sizeof($this->request->post['address'])) { $this->error['address'] = Language::getVar('SUMO_ERROR_NO_ADDRESS'); } if (!$this->error) { return true; } return false; }
protected function validateForm() { if (utf8_strlen($this->request->post['firstname']) < 1 || utf8_strlen($this->request->post['firstname']) > 32) { $this->error['firstname'] = $this->language->get('error_firstname'); } if (utf8_strlen($this->request->post['lastname']) < 1 || utf8_strlen($this->request->post['lastname']) > 32) { $this->error['lastname'] = $this->language->get('error_lastname'); } if (utf8_strlen($this->request->post['address_1']) < 3 || utf8_strlen($this->request->post['address_1']) > 128) { $this->error['address_1'] = $this->language->get('error_address_1'); } if (utf8_strlen($this->request->post['city']) < 2 || utf8_strlen($this->request->post['city']) > 128) { $this->error['city'] = $this->language->get('error_city'); } $this->load->model('localisation/country'); $country_info = $this->model_localisation_country->getCountry($this->request->post['country_id']); if ($country_info) { if ($country_info['postcode_required'] && utf8_strlen($this->request->post['postcode']) < 2 || utf8_strlen($this->request->post['postcode']) > 10) { $this->error['postcode'] = $this->language->get('error_postcode'); } // VAT Validation $this->load->helper('vat'); if ($this->config->get('config_vat') && !empty($this->request->post['tax_id']) && vat_validation($country_info['iso_code_2'], $this->request->post['tax_id']) == 'invalid') { $this->error['tax_id'] = $this->language->get('error_vat'); } } if ($this->request->post['country_id'] == '') { $this->error['country'] = $this->language->get('error_country'); } if (!isset($this->request->post['zone_id']) || $this->request->post['zone_id'] == '') { $this->error['zone'] = $this->language->get('error_zone'); } if (!$this->error) { return true; } else { return false; } }
protected function validate() { // ***** Buyer account part ***** if (utf8_strlen($this->request->post['firstname']) < 1 || utf8_strlen($this->request->post['firstname']) > 32) { $this->error['firstname'] = $this->language->get('error_firstname'); } if (utf8_strlen($this->request->post['lastname']) < 1 || utf8_strlen($this->request->post['lastname']) > 32) { $this->error['lastname'] = $this->language->get('error_lastname'); } if (utf8_strlen($this->request->post['email']) > 96 || !preg_match('/^[^\\@]+@.*\\.[a-z]{2,6}$/i', $this->request->post['email'])) { $this->error['email'] = $this->language->get('error_email'); } if ($this->model_account_customer->getTotalCustomersByEmail($this->request->post['email'])) { $this->error['warning'] = $this->language->get('error_exists'); } if (utf8_strlen($this->request->post['telephone']) < 3 || utf8_strlen($this->request->post['telephone']) > 32) { $this->error['telephone'] = $this->language->get('error_telephone'); } // Customer Group $this->load->model('account/customer_group'); 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'))) { $customer_group_id = $this->request->post['customer_group_id']; } else { $customer_group_id = $this->config->get('config_customer_group_id'); } $customer_group = $this->model_account_customer_group->getCustomerGroup($customer_group_id); if ($customer_group) { // Company ID if ($customer_group['company_id_display'] && $customer_group['company_id_required'] && empty($this->request->post['company_id'])) { $this->error['company_id'] = $this->language->get('error_company_id'); } // Tax ID if ($customer_group['tax_id_display'] && $customer_group['tax_id_required'] && empty($this->request->post['tax_id'])) { $this->error['tax_id'] = $this->language->get('error_tax_id'); } } if (utf8_strlen($this->request->post['address_1']) < 3 || utf8_strlen($this->request->post['address_1']) > 128) { $this->error['address_1'] = $this->language->get('error_address_1'); } if (utf8_strlen($this->request->post['city']) < 2 || utf8_strlen($this->request->post['city']) > 128) { $this->error['city'] = $this->language->get('error_city'); } $this->load->model('localisation/country'); $country_info = $this->model_localisation_country->getCountry($this->request->post['country_id']); if ($country_info) { if ($country_info['postcode_required'] && utf8_strlen($this->request->post['postcode']) < 2 || utf8_strlen($this->request->post['postcode']) > 10) { $this->error['postcode'] = $this->language->get('error_postcode'); } // VAT Validation $this->load->helper('vat'); if ($this->config->get('config_vat') && $this->request->post['tax_id'] && vat_validation($country_info['iso_code_2'], $this->request->post['tax_id']) == 'invalid') { $this->error['tax_id'] = $this->language->get('error_vat'); } } if ($this->request->post['country_id'] == '') { $this->error['country'] = $this->language->get('error_country'); } if (!isset($this->request->post['zone_id']) || $this->request->post['zone_id'] == '') { $this->error['zone'] = $this->language->get('error_zone'); } if (utf8_strlen($this->request->post['password']) < 4 || utf8_strlen($this->request->post['password']) > 20) { $this->error['password'] = $this->language->get('error_password'); } if ($this->request->post['confirm'] != $this->request->post['password']) { $this->error['confirm'] = $this->language->get('error_confirm'); } if ($this->config->get('config_account_id')) { $this->load->model('catalog/information'); $information_info = $this->model_catalog_information->getInformation($this->config->get('config_account_id')); if ($information_info && !isset($this->request->post['agree'])) { $this->error['warning'] = sprintf($this->language->get('error_agree'), $information_info['title']); } } // ***** Seller account part ***** $data = $this->request->post; if (empty($data['seller_nickname'])) { //$json['errors']['seller[nickname]'] = $this->language->get('ms_error_sellerinfo_nickname_empty'); $this->error['seller_nickname'] = $this->language->get('ms_error_sellerinfo_nickname_empty'); } else { if (mb_strlen($data['seller_nickname']) < 4 || mb_strlen($data['seller_nickname']) > 128) { //$json['errors']['seller[nickname]'] = $this->language->get('ms_error_sellerinfo_nickname_length'); $this->error['seller_nickname'] = $this->language->get('ms_error_sellerinfo_nickname_length'); } else { if ($this->MsLoader->MsSeller->nicknameTaken($data['seller_nickname'])) { //$json['errors']['seller[nickname]'] = $this->language->get('ms_error_sellerinfo_nickname_taken'); $this->error['seller_nickname'] = $this->language->get('ms_error_sellerinfo_nickname_taken'); } else { switch ($this->config->get('msconf_nickname_rules')) { case 1: // extended latin if (!preg_match("/^[a-zA-Z0-9_\\-\\s\\x{00C0}-\\x{017F}]+\$/u", $data['seller_nickname'])) { //$json['errors']['seller[nickname]'] = $this->language->get('ms_error_sellerinfo_nickname_latin'); $this->error['seller_nickname'] = $this->language->get('ms_error_sellerinfo_nickname_latin'); } break; case 2: // utf8 if (!preg_match("/((?:[-]|[À-ß][€-¿]|[à-ï][€-¿]{2}|[ð-÷][€-¿]{3}){1,100})./x", $data['seller_nickname'])) { //$json['errors']['seller[nickname]'] = $this->language->get('ms_error_sellerinfo_nickname_utf8'); $this->error['seller_nickname'] = $this->language->get('ms_error_sellerinfo_nickname_utf8'); } break; case 0: default: // alnum if (!preg_match("/^[a-zA-Z0-9_\\-\\s]+\$/", $data['seller_nickname'])) { //$json['errors']['seller[nickname]'] = $this->language->get('ms_error_sellerinfo_nickname_alphanumeric'); $this->error['seller_nickname'] = $this->language->get('ms_error_sellerinfo_nickname_alphanumeric'); } break; } } } } if ($this->config->get('msconf_seller_terms_page')) { $this->load->model('catalog/information'); $information_info = $this->model_catalog_information->getInformation($this->config->get('msconf_seller_terms_page')); if ($information_info && !isset($data['seller_terms'])) { //$json['errors']['seller[terms]'] = htmlspecialchars_decode(sprintf($this->language->get('ms_error_sellerinfo_terms'), $information_info['title'])); $this->error['seller_terms'] = htmlspecialchars_decode(sprintf($this->language->get('ms_error_sellerinfo_terms'), $information_info['title'])); } } if (mb_strlen($data['seller_company']) > 50) { //$json['errors']['seller[company]'] = $this->language->get('ms_error_sellerinfo_company_length'); $this->error['seller_company'] = $this->language->get('ms_error_sellerinfo_company_length'); } if (mb_strlen($data['seller_description']) > 1000) { //$json['errors']['seller[description]'] = $this->language->get('ms_error_sellerinfo_description_length'); $this->error['seller_description'] = $this->language->get('ms_error_sellerinfo_description_length'); } if (mb_strlen($data['seller_paypal']) > 256) { //$json['errors']['seller[paypal]'] = $this->language->get('ms_error_sellerinfo_paypal'); $this->error['seller_paypal'] = $this->language->get('ms_error_sellerinfo_paypal'); } if (isset($data['seller_avatar_name']) && !empty($data['seller_avatar_name'])) { if ($this->config->get('msconf_avatars_for_sellers') == 2 && !$this->MsLoader->MsFile->checkPredefinedAvatar($data['seller_avatar_name'])) { $this->error['seller_avatar'] = $this->language->get('ms_error_file_upload_error'); } elseif ($this->config->get('msconf_avatars_for_sellers') == 1 && !$this->MsLoader->MsFile->checkPredefinedAvatar($data['seller_avatar_name']) && !$this->MsLoader->MsFile->checkFileAgainstSession($data['seller_avatar_name'])) { $this->error['seller_avatar'] = $this->language->get('ms_error_file_upload_error'); } elseif ($this->config->get('msconf_avatars_for_sellers') == 0 && !$this->MsLoader->MsFile->checkFileAgainstSession($data['seller_avatar_name'])) { $this->error['seller_avatar'] = $this->language->get('ms_error_file_upload_error'); } } // strip disallowed tags in description if ($this->config->get('msconf_enable_rte')) { if ($this->config->get('msconf_rte_whitelist') != '') { $allowed_tags = explode(",", $this->config->get('msconf_rte_whitelist')); $allowed_tags_ready = ""; foreach ($allowed_tags as $tag) { $allowed_tags_ready .= "<" . trim($tag) . ">"; } $data['seller_description'] = htmlspecialchars(strip_tags(htmlspecialchars_decode($data['seller_description'], ENT_COMPAT), $allowed_tags_ready), ENT_COMPAT, 'UTF-8'); } } else { $data['seller_description'] = htmlspecialchars(nl2br($data['seller_description']), ENT_COMPAT, 'UTF-8'); } if (!$this->error) { return true; } else { return false; } }
public function validate() { $this->language->load('checkout/checkout'); $this->load->model('account/customer'); $json = array(); // Validate if customer is already logged out. if ($this->customer->isLogged()) { $json['redirect'] = $this->url->link('checkout/checkout', '', 'SSL'); } // Validate cart has products and has stock. if (!$this->cart->hasProducts() && empty($this->session->data['vouchers']) || !$this->cart->hasStock() && !$this->config->get('config_stock_checkout')) { $json['redirect'] = $this->url->link('checkout/cart'); } // Validate minimum quantity requirments. $products = $this->cart->getProducts(); foreach ($products as $product) { $product_total = 0; foreach ($products as $product_2) { if ($product_2['product_id'] == $product['product_id']) { $product_total += $product_2['quantity']; } } if ($product['minimum'] > $product_total) { $json['redirect'] = $this->url->link('checkout/cart'); break; } } if (!$json) { if (utf8_strlen($this->request->post['firstname']) < 1 || utf8_strlen($this->request->post['firstname']) > 32) { $json['error']['firstname'] = $this->language->get('error_firstname'); } if (utf8_strlen($this->request->post['lastname']) < 1 || utf8_strlen($this->request->post['lastname']) > 32) { $json['error']['lastname'] = $this->language->get('error_lastname'); } if (utf8_strlen($this->request->post['email']) > 96 || !preg_match('/^[^\\@]+@.*\\.[a-z]{2,6}$/i', $this->request->post['email'])) { $json['error']['email'] = $this->language->get('error_email'); } if ($this->model_account_customer->getTotalCustomersByEmail($this->request->post['email'])) { $json['error']['warning'] = $this->language->get('error_exists'); } if (utf8_strlen($this->request->post['telephone']) < 3 || utf8_strlen($this->request->post['telephone']) > 32) { $json['error']['telephone'] = $this->language->get('error_telephone'); } // Customer Group $this->load->model('account/customer_group'); 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'))) { $customer_group_id = $this->request->post['customer_group_id']; } else { $customer_group_id = $this->config->get('config_customer_group_id'); } $customer_group = $this->model_account_customer_group->getCustomerGroup($customer_group_id); if ($customer_group) { // Company ID if ($customer_group['company_id_display'] && $customer_group['company_id_required'] && empty($this->request->post['company_id'])) { $json['error']['company_id'] = $this->language->get('error_company_id'); } // Tax ID if ($customer_group['tax_id_display'] && $customer_group['tax_id_required'] && empty($this->request->post['tax_id'])) { $json['error']['tax_id'] = $this->language->get('error_tax_id'); } } if (utf8_strlen($this->request->post['address_1']) < 3 || utf8_strlen($this->request->post['address_1']) > 128) { $json['error']['address_1'] = $this->language->get('error_address_1'); } if (utf8_strlen($this->request->post['city']) < 2 || utf8_strlen($this->request->post['city']) > 128) { $json['error']['city'] = $this->language->get('error_city'); } $this->load->model('localisation/country'); $country_info = $this->model_localisation_country->getCountry($this->request->post['country_id']); if ($country_info) { if ($country_info['postcode_required'] && utf8_strlen($this->request->post['postcode']) < 2 || utf8_strlen($this->request->post['postcode']) > 10) { $json['error']['postcode'] = $this->language->get('error_postcode'); } // VAT Validation $this->load->helper('vat'); if ($this->config->get('config_vat') && $this->request->post['tax_id'] && vat_validation($country_info['iso_code_2'], $this->request->post['tax_id']) == 'invalid') { $json['error']['tax_id'] = $this->language->get('error_vat'); } } if ($this->request->post['country_id'] == '') { $json['error']['country'] = $this->language->get('error_country'); } if (!isset($this->request->post['zone_id']) || $this->request->post['zone_id'] == '') { $json['error']['zone'] = $this->language->get('error_zone'); } if (utf8_strlen($this->request->post['password']) < 4 || utf8_strlen($this->request->post['password']) > 20) { $json['error']['password'] = $this->language->get('error_password'); } if ($this->request->post['confirm'] != $this->request->post['password']) { $json['error']['confirm'] = $this->language->get('error_confirm'); } if ($this->config->get('config_account_id')) { $this->load->model('catalog/information'); $information_info = $this->model_catalog_information->getInformation($this->config->get('config_account_id')); if ($information_info && !isset($this->request->post['agree'])) { $json['error']['warning'] = sprintf($this->language->get('error_agree'), $information_info['title']); } } } if (!$json) { $this->model_account_customer->addCustomer($this->request->post); $this->session->data['account'] = 'register'; if ($customer_group && !$customer_group['approval']) { $this->customer->login($this->request->post['email'], $this->request->post['password']); $this->session->data['payment_address_id'] = $this->customer->getAddressId(); $this->session->data['payment_country_id'] = $this->request->post['country_id']; $this->session->data['payment_zone_id'] = $this->request->post['zone_id']; if (!empty($this->request->post['shipping_address'])) { $this->session->data['shipping_address_id'] = $this->customer->getAddressId(); $this->session->data['shipping_country_id'] = $this->request->post['country_id']; $this->session->data['shipping_zone_id'] = $this->request->post['zone_id']; $this->session->data['shipping_postcode'] = $this->request->post['postcode']; } } else { $json['redirect'] = $this->url->link('account/success'); } unset($this->session->data['guest']); unset($this->session->data['shipping_method']); unset($this->session->data['shipping_methods']); unset($this->session->data['payment_method']); unset($this->session->data['payment_methods']); } $this->response->setOutput(json_encode($json)); }
public function index() { $this->language->load('onecheckout/checkout'); $this->load->model('onecheckout/checkout'); $version_int = $this->model_onecheckout_checkout->versiontoint(); $json = array(); if ($this->customer->isLogged()) { $json['redirect'] = $this->url->link('onecheckout/checkout', '', 'SSL'); } if (!$this->cart->hasProducts() && (!isset($this->session->data['vouchers']) || !$this->session->data['vouchers']) || !$this->cart->hasStock() && !$this->config->get('config_stock_checkout')) { $json['redirect'] = $this->url->link('checkout/cart'); } $this->data['text_placeholder_password'] = $this->language->get('text_placeholder_password'); $this->data['text_placeholder_confirm'] = $this->language->get('text_placeholder_confirm'); if ($this->request->server['REQUEST_METHOD'] == 'POST') { if (!$json) { if (strlen(utf8_decode($this->request->post['firstname'])) < 1 || strlen(utf8_decode($this->request->post['firstname'])) > 32) { $json['error']['firstname'] = $this->language->get('error_firstname'); } if (strlen(utf8_decode($this->request->post['lastname'])) < 1 || strlen(utf8_decode($this->request->post['lastname'])) > 32) { $json['error']['lastname'] = $this->language->get('error_lastname'); } if (strlen(utf8_decode($this->request->post['email'])) > 96 || !preg_match('/^[^\\@]+@.*\\.[a-z]{2,6}$/i', $this->request->post['email'])) { $json['error']['email'] = $this->language->get('error_email'); } if ($this->model_onecheckout_checkout->getTotalCustomersByEmail($this->request->post['email'])) { $json['error']['warning'] = $this->language->get('error_exists'); } if (strlen(utf8_decode($this->request->post['telephone'])) < 3 || strlen(utf8_decode($this->request->post['telephone'])) > 32) { $json['error']['telephone'] = $this->language->get('error_telephone'); } //version if ($version_int >= 1530) { // Customer Group $this->load->model('account/customer_group'); 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'))) { $customer_group_id = $this->request->post['customer_group_id']; } else { $customer_group_id = $this->config->get('config_customer_group_id'); } $customer_group = $this->model_account_customer_group->getCustomerGroup($customer_group_id); if ($customer_group) { // Company ID if ($customer_group['company_id_display'] && $customer_group['company_id_required'] && empty($this->request->post['company_id'])) { $json['error']['company_id'] = $this->language->get('error_company_id'); } // Tax ID if ($customer_group['tax_id_display'] && $customer_group['tax_id_required'] && empty($this->request->post['tax_id'])) { $json['error']['tax_id'] = $this->language->get('error_tax_id'); } } } if (strlen(utf8_decode($this->request->post['address_1'])) < 3 || strlen(utf8_decode($this->request->post['address_1'])) > 128) { $json['error']['address_1'] = $this->language->get('error_address_1'); } $country_info = $this->model_onecheckout_checkout->getCountry($this->request->post['country_id']); if ($country_info) { if ($country_info['postcode_required'] && strlen(utf8_decode($this->request->post['postcode'])) < 2 || strlen(utf8_decode($this->request->post['postcode'])) > 10) { $json['error']['postcode'] = $this->language->get('error_postcode'); } if ($version_int >= 1530) { // VAT Validation $this->load->helper('vat'); if ($this->config->get('config_vat') && $this->request->post['tax_id'] && vat_validation($country_info['iso_code_2'], $this->request->post['tax_id']) == 'invalid') { $json['error']['tax_id'] = $this->language->get('error_vat'); } } } if ($this->request->post['country_id'] == '') { $json['error']['country'] = $this->language->get('error_country'); } if ($this->request->post['zone_id'] == '') { $json['error']['zone'] = $this->language->get('error_zone'); } if (strlen(utf8_decode($this->request->post['password'])) < 4 || strlen(utf8_decode($this->request->post['password'])) > 20) { $json['error']['password'] = $this->language->get('error_password'); } if ($this->request->post['confirm'] != $this->request->post['password']) { $json['error']['confirm'] = $this->language->get('error_confirm'); } if ($this->config->get('config_account_id')) { $information_info = $this->model_onecheckout_checkout->getInformation($this->config->get('config_account_id')); if ($information_info && !isset($this->request->post['agree'])) { $json['error']['warning'] = sprintf($this->language->get('error_agree'), $information_info['title']); } } } if (!$json) { if ($version_int >= 1530) { $this->load->model('account/customer'); $this->model_account_customer->addCustomer($this->request->post); $customer_app = $customer_group && !$customer_group['approval']; } else { $this->model_onecheckout_checkout->addCustomer($this->request->post); $customer_app = !$this->config->get('config_customer_approval'); } if (!$this->config->get('config_customer_approval')) { $this->customer->login($this->request->post['email'], $this->request->post['password']); $this->session->data['payment_address_id'] = $this->customer->getAddressId(); if ($this->config->get('config_tax_customer') == 'payment') { $this->session->data['payment_country_id'] = $this->request->post['country_id']; $this->session->data['payment_zone_id'] = $this->request->post['zone_id']; } if (isset($this->request->post['shipping_address']) && $this->request->post['shipping_address']) { $this->session->data['shipping_address_id'] = $this->customer->getAddressId(); if ($this->config->get('config_tax_customer') == 'shipping') { $this->session->data['shipping_country_id'] = $this->request->post['country_id']; $this->session->data['shipping_zone_id'] = $this->request->post['zone_id']; $this->session->data['shipping_postcode'] = $this->request->post['postcode']; } } } else { $json['redirect'] = $this->url->link('account/success'); } $version_int = $this->model_onecheckout_checkout->versiontoint(); //version if ($version_int < 1513 && $version_int >= 1500) { $this->tax->setZone($this->request->post['country_id'], $this->request->post['zone_id']); } unset($this->session->data['guest']); unset($this->session->data['shipping_methods']); unset($this->session->data['shipping_method']); unset($this->session->data['payment_methods']); unset($this->session->data['payment_method']); } } else { $this->data['entry_newsletter'] = sprintf($this->language->get('entry_newsletter'), $this->config->get('config_name')); $this->data['entry_password'] = $this->language->get('entry_password'); $this->data['entry_confirm'] = $this->language->get('entry_confirm'); $this->data['entry_shipping'] = $this->language->get('entry_shipping'); if ($this->config->get('config_account_id')) { $information_info = $this->model_onecheckout_checkout->getInformation($this->config->get('config_account_id')); if ($information_info) { $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']); } else { $this->data['text_agree'] = ''; } } else { $this->data['text_agree'] = ''; } $this->data['shipping_required'] = $this->cart->hasShipping(); if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/onecheckout/register.tpl')) { $this->template = $this->config->get('config_template') . '/template/onecheckout/register.tpl'; } else { $this->template = 'default/template/onecheckout/register.tpl'; } $json['output'] = $this->render(); } $this->response->setOutput($this->model_onecheckout_checkout->jsonencode($json)); }
public function validate() { $this->language->load('checkout/checkout'); $json = array(); // Validate if customer is logged in. if ($this->customer->isLogged()) { $json['redirect'] = $this->url->link('checkout/checkout', '', 'SSL'); } // Validate cart has products and has stock. if (!$this->cart->hasProducts() && empty($this->session->data['vouchers']) || !$this->cart->hasStock() && !$this->config->get('config_stock_checkout')) { $json['redirect'] = $this->url->link('checkout/cart'); } // Check if guest checkout is avaliable. if (!$this->config->get('config_guest_checkout') || $this->config->get('config_customer_price') || $this->cart->hasDownload()) { $json['redirect'] = $this->url->link('checkout/checkout', '', 'SSL'); } if (!$json) { if (utf8_strlen($this->request->post['firstname']) < 1 || utf8_strlen($this->request->post['firstname']) > 32) { $json['error']['firstname'] = $this->language->get('error_firstname'); } if (utf8_strlen($this->request->post['lastname']) < 1 || utf8_strlen($this->request->post['lastname']) > 32) { $json['error']['lastname'] = $this->language->get('error_lastname'); } if (utf8_strlen($this->request->post['email']) > 96 || !$this->ocstore->validate($this->request->post['email'])) { $json['error']['email'] = $this->language->get('error_email'); } if (utf8_strlen($this->request->post['telephone']) < 3 || utf8_strlen($this->request->post['telephone']) > 32) { $json['error']['telephone'] = $this->language->get('error_telephone'); } // Customer Group $this->load->model('account/customer_group'); 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'))) { $customer_group_id = $this->request->post['customer_group_id']; } else { $customer_group_id = $this->config->get('config_customer_group_id'); } $customer_group = $this->model_account_customer_group->getCustomerGroup($customer_group_id); if ($customer_group) { // Company ID if ($customer_group['company_id_display'] && $customer_group['company_id_required'] && empty($this->request->post['company_id'])) { $json['error']['company_id'] = $this->language->get('error_company_id'); } // Tax ID if ($customer_group['tax_id_display'] && $customer_group['tax_id_required'] && empty($this->request->post['tax_id'])) { $json['error']['tax_id'] = $this->language->get('error_tax_id'); } } if (utf8_strlen($this->request->post['address_1']) < 3 || utf8_strlen($this->request->post['address_1']) > 128) { $json['error']['address_1'] = $this->language->get('error_address_1'); } if (utf8_strlen($this->request->post['city']) < 2 || utf8_strlen($this->request->post['city']) > 128) { $json['error']['city'] = $this->language->get('error_city'); } $this->load->model('localisation/country'); $country_info = $this->model_localisation_country->getCountry($this->request->post['country_id']); if ($country_info) { /* if ($country_info['postcode_required'] && (utf8_strlen($this->request->post['postcode']) < 2) || (utf8_strlen($this->request->post['postcode']) > 10)) { $json['error']['postcode'] = $this->language->get('error_postcode'); } */ // VAT Validation $this->load->helper('vat'); if ($this->config->get('config_vat') && $this->request->post['tax_id'] && vat_validation($country_info['iso_code_2'], $this->request->post['tax_id']) == 'invalid') { $json['error']['tax_id'] = $this->language->get('error_vat'); } } if ($this->request->post['country_id'] == '') { $json['error']['country'] = $this->language->get('error_country'); } if (!isset($this->request->post['zone_id']) || $this->request->post['zone_id'] == '') { $json['error']['zone'] = $this->language->get('error_zone'); } } if (!$json) { $this->session->data['guest']['customer_group_id'] = $customer_group_id; $this->session->data['guest']['firstname'] = $this->request->post['firstname']; $this->session->data['guest']['lastname'] = $this->request->post['lastname']; $this->session->data['guest']['email'] = $this->request->post['email']; $this->session->data['guest']['telephone'] = $this->request->post['telephone']; //$this->session->data['guest']['fax'] = $this->request->post['fax']; $this->session->data['guest']['payment']['firstname'] = $this->request->post['firstname']; $this->session->data['guest']['payment']['lastname'] = $this->request->post['lastname']; $this->session->data['guest']['payment']['company'] = $this->request->post['company']; $this->session->data['guest']['payment']['company_id'] = $this->request->post['company_id']; $this->session->data['guest']['payment']['tax_id'] = $this->request->post['tax_id']; $this->session->data['guest']['payment']['address_1'] = $this->request->post['address_1']; $this->session->data['guest']['payment']['address_2'] = $this->request->post['address_2']; //$this->session->data['guest']['payment']['postcode'] = $this->request->post['postcode']; $this->session->data['guest']['payment']['city'] = $this->request->post['city']; $this->session->data['guest']['payment']['country_id'] = $this->request->post['country_id']; $this->session->data['guest']['payment']['zone_id'] = $this->request->post['zone_id']; $this->load->model('localisation/country'); $country_info = $this->model_localisation_country->getCountry($this->request->post['country_id']); if ($country_info) { $this->session->data['guest']['payment']['country'] = $country_info['name']; $this->session->data['guest']['payment']['iso_code_2'] = $country_info['iso_code_2']; $this->session->data['guest']['payment']['iso_code_3'] = $country_info['iso_code_3']; $this->session->data['guest']['payment']['address_format'] = $country_info['address_format']; } else { $this->session->data['guest']['payment']['country'] = ''; $this->session->data['guest']['payment']['iso_code_2'] = ''; $this->session->data['guest']['payment']['iso_code_3'] = ''; $this->session->data['guest']['payment']['address_format'] = ''; } $this->load->model('localisation/zone'); $zone_info = $this->model_localisation_zone->getZone($this->request->post['zone_id']); if ($zone_info) { $this->session->data['guest']['payment']['zone'] = $zone_info['name']; $this->session->data['guest']['payment']['zone_code'] = $zone_info['code']; } else { $this->session->data['guest']['payment']['zone'] = ''; $this->session->data['guest']['payment']['zone_code'] = ''; } if (!empty($this->request->post['shipping_address'])) { $this->session->data['guest']['shipping_address'] = true; } else { $this->session->data['guest']['shipping_address'] = false; } // Default Payment Address $this->session->data['payment_country_id'] = $this->request->post['country_id']; $this->session->data['payment_zone_id'] = $this->request->post['zone_id']; if ($this->session->data['guest']['shipping_address']) { $this->session->data['guest']['shipping']['firstname'] = $this->request->post['firstname']; $this->session->data['guest']['shipping']['lastname'] = $this->request->post['lastname']; $this->session->data['guest']['shipping']['company'] = $this->request->post['company']; $this->session->data['guest']['shipping']['address_1'] = $this->request->post['address_1']; $this->session->data['guest']['shipping']['address_2'] = $this->request->post['address_2']; //$this->session->data['guest']['shipping']['postcode'] = $this->request->post['postcode']; $this->session->data['guest']['shipping']['city'] = $this->request->post['city']; $this->session->data['guest']['shipping']['country_id'] = $this->request->post['country_id']; $this->session->data['guest']['shipping']['zone_id'] = $this->request->post['zone_id']; if ($country_info) { $this->session->data['guest']['shipping']['country'] = $country_info['name']; $this->session->data['guest']['shipping']['iso_code_2'] = $country_info['iso_code_2']; $this->session->data['guest']['shipping']['iso_code_3'] = $country_info['iso_code_3']; $this->session->data['guest']['shipping']['address_format'] = $country_info['address_format']; } else { $this->session->data['guest']['shipping']['country'] = ''; $this->session->data['guest']['shipping']['iso_code_2'] = ''; $this->session->data['guest']['shipping']['iso_code_3'] = ''; $this->session->data['guest']['shipping']['address_format'] = ''; } if ($zone_info) { $this->session->data['guest']['shipping']['zone'] = $zone_info['name']; $this->session->data['guest']['shipping']['zone_code'] = $zone_info['code']; } else { $this->session->data['guest']['shipping']['zone'] = ''; $this->session->data['guest']['shipping']['zone_code'] = ''; } // Default Shipping Address $this->session->data['shipping_country_id'] = $this->request->post['country_id']; $this->session->data['shipping_zone_id'] = $this->request->post['zone_id']; //$this->session->data['shipping_postcode'] = $this->request->post['postcode']; } $this->session->data['account'] = 'guest'; unset($this->session->data['shipping_method']); unset($this->session->data['shipping_methods']); unset($this->session->data['payment_method']); unset($this->session->data['payment_methods']); } $this->response->setOutput(json_encode($json)); }
private function validateAddressData($data, $key, $name = true) { $errors = array(); if ($name) { // firstname if (utf8_strlen(trim($data[$key . 'firstname'])) < 1 || utf8_strlen(trim($data[$key . 'firstname'])) > 32) { $errors[$key . 'firstname'] = $this->language->get('error_firstname'); } // lastname if (utf8_strlen(trim($data[$key . 'lastname'])) < 1 || utf8_strlen(trim($data[$key . 'lastname'])) > 32) { $errors[$key . 'lastname'] = $this->language->get('error_lastname'); } } if (utf8_strlen(trim($data[$key . 'address_1'])) < 3 || utf8_strlen(trim($data[$key . 'address_1'])) > 128) { $errors[$key . 'address_1'] = $this->language->get('error_address_1'); } if (utf8_strlen($data[$key . 'city']) < 2 || utf8_strlen($data[$key . 'city']) > 32) { $errors[$key . 'city'] = $this->language->get('error_city'); } $country_info = $this->model_localisation_country->getCountry($data[$key . 'country_id']); if ($country_info && $country_info['postcode_required'] && (utf8_strlen(trim($data[$key . 'postcode'])) < 2 || utf8_strlen(trim($data[$key . 'postcode'])) > 10)) { $errors[$key . 'postcode'] = $this->language->get('error_postcode'); } if ($data[$key . 'country_id'] == '') { $errors[$key . 'country'] = $this->language->get('error_country'); } if (!isset($data[$key . 'zone_id']) || $data[$key . 'zone_id'] == '') { $errors[$key . 'zone'] = $this->language->get('error_zone'); } // Custom field validation if (Front::$IS_OC2) { $custom_fields = $this->model_journal2_checkout->getCustomFields(); foreach ($custom_fields as $custom_field) { if ($custom_field['location'] == 'address' && $custom_field['required'] && empty($data[$key . 'custom_field'][$custom_field['custom_field_id']])) { $errors[$key . 'custom_field' . $custom_field['custom_field_id']] = sprintf($this->language->get('error_custom_field'), $custom_field['name']); } } } else { $customer_group = $this->model_account_customer_group->getCustomerGroup(Journal2Utils::getProperty($this->request->post, 'customer_group_id', $this->model_journal2_checkout->getCustomerGroupId())); if ($customer_group) { // Company ID if ($customer_group['company_id_display'] && $customer_group['company_id_required'] && empty($data[$key . 'company_id'])) { $errors[$key . 'company_id'] = $this->language->get('error_company_id'); } // Tax ID if ($customer_group['tax_id_display'] && $customer_group['tax_id_required'] && empty($data[$key . 'tax_id'])) { $errors[$key . 'tax_id'] = $this->language->get('error_tax_id'); } } // VAT Validation $this->load->helper('vat'); if ($country_info && $this->config->get('config_vat') && $data[$key . 'tax_id'] && vat_validation($country_info['iso_code_2'], $data[$key . 'tax_id']) == 'invalid') { $errors[$key . 'tax_id'] = $this->language->get('error_vat'); } } return $errors; }
protected function validateForm() { if (!$this->user->hasPermission('modify', 'sale/customer')) { $this->error['warning'] = $this->language->get('error_permission'); } if (utf8_strlen($this->request->post['firstname']) < 1 || utf8_strlen($this->request->post['firstname']) > 32) { $this->error['firstname'] = $this->language->get('error_firstname'); } // if( (utf8_strlen( $this->request->post['lastname'] ) < 1) || (utf8_strlen( $this->request->post['lastname'] ) > 32) ) // { if (utf8_strlen($this->request->post['middlename']) > 32) { $this->error['middlename'] = $this->language->get('error_middlename'); } if (utf8_strlen($this->request->post['identity_card_number']) > 15 || !preg_match('/^[a-zA-Z0-9]+$/', $this->request->post['identity_card_number'])) { $this->error['identity_card_number'] = $this->language->get('error_identity_card_number'); } if (utf8_strlen($this->request->post['mobile_phone']) > 15 || !is_numeric($this->request->post['mobile_phone'])) { $this->error['mobile_phone'] = $this->language->get('error_mobile_phone'); } if (utf8_strlen($this->request->post['lastname']) < 1 || utf8_strlen($this->request->post['lastname']) > 32) { $this->error['lastname'] = $this->language->get('error_lastname'); } if (utf8_strlen($this->request->post['email']) > 96 || !preg_match('/^[^\\@]+@.*\\.[a-z]{2,6}$/i', $this->request->post['email'])) { $this->error['email'] = $this->language->get('error_email'); } $customer_info = $this->model_sale_customer->getCustomerByEmail($this->request->post['email']); if (!isset($this->request->get['customer_id'])) { if ($customer_info) { $this->error['warning'] = $this->language->get('error_exists'); } } else { if ($customer_info && $this->request->get['customer_id'] != $customer_info['customer_id']) { $this->error['warning'] = $this->language->get('error_exists'); } } if (utf8_strlen($this->request->post['telephone']) < 3 || utf8_strlen($this->request->post['telephone']) > 32) { $this->error['telephone'] = $this->language->get('error_telephone'); } if ($this->request->post['password'] || !isset($this->request->get['customer_id'])) { if (utf8_strlen($this->request->post['password']) < 4 || utf8_strlen($this->request->post['password']) > 20) { $this->error['password'] = $this->language->get('error_password'); } if ($this->request->post['password'] != $this->request->post['confirm']) { $this->error['confirm'] = $this->language->get('error_confirm'); } } if (isset($this->request->post['address'])) { foreach ($this->request->post['address'] as $key => $value) { if ($this->request->post['customer_group_id'] != 3 && $this->request->post['customer_group_id'] != 4) { if (utf8_strlen($value['firstname']) < 1 || utf8_strlen($value['firstname']) > 32) { $this->error['address_firstname'][$key] = $this->language->get('error_firstname'); } if (utf8_strlen($value['lastname']) < 1 || utf8_strlen($value['lastname']) > 32) { $this->error['address_lastname'][$key] = $this->language->get('error_lastname'); } } // b2b user if end if (utf8_strlen($value['address_1']) < 3 || utf8_strlen($value['address_1']) > 128) { $this->error['address_address_1'][$key] = $this->language->get('error_address_1'); } if (utf8_strlen($value['city']) < 2 || utf8_strlen($value['city']) > 128) { $this->error['address_city'][$key] = $this->language->get('error_city'); } $this->load->model('localisation/country'); $country_info = $this->model_localisation_country->getCountry($value['country_id']); if ($country_info) { if ($country_info['postcode_required'] && utf8_strlen($value['postcode']) < 2 || utf8_strlen($value['postcode']) > 10) { $this->error['address_postcode'][$key] = $this->language->get('error_postcode'); } // VAT Validation $this->load->helper('vat'); if ($this->config->get('config_vat') && $value['tax_id'] && vat_validation($country_info['iso_code_2'], $value['tax_id']) == 'invalid') { $this->error['address_tax_id'][$key] = $this->language->get('error_vat'); } } if ($value['country_id'] == '') { $this->error['address_country'][$key] = $this->language->get('error_country'); } if (!isset($value['zone_id']) || $value['zone_id'] == '') { $this->error['address_zone'][$key] = $this->language->get('error_zone'); } } } if ($this->error && !isset($this->error['warning'])) { $this->error['warning'] = $this->language->get('error_warning'); } if (!$this->error) { return true; } else { return false; } }
public function validate() { $json['error'] = array(); $this->language->load('onecheckout/checkout'); $this->load->model('onecheckout/checkout'); $version_int = $this->model_onecheckout_checkout->versiontoint(); if ($this->request->server['REQUEST_METHOD'] == 'POST') { //var_dump($this->request->post); if (isset($this->request->post['firstname'])) { if (strlen(utf8_decode($this->request->post['firstname'])) < 1 || strlen(utf8_decode($this->request->post['firstname'])) > 32) { $json['error']['firstname'] = $this->language->get('error_firstname'); } else { $this->session->data['shipping']['firstname'] = $this->request->post['firstname']; } } if (isset($this->request->post['lastname'])) { if (strlen(utf8_decode($this->request->post['lastname'])) < 1 || strlen(utf8_decode($this->request->post['lastname'])) > 32) { $json['error']['lastname'] = $this->language->get('error_lastname'); } else { $this->session->data['shipping']['lastname'] = $this->request->post['lastname']; } } if (isset($this->request->post['email'])) { if (strlen(utf8_decode($this->request->post['email'])) > 96 || !preg_match('/^[^\\@]+@.*\\.[a-z]{2,6}$/i', $this->request->post['email'])) { $json['error']['email'] = $this->language->get('error_email'); } elseif ($this->model_onecheckout_checkout->getTotalCustomersByEmail($this->request->post['email'])) { $json['error']['email'] = $this->language->get('error_exists'); } } if (isset($this->request->post['telephone'])) { if (strlen(utf8_decode($this->request->post['telephone'])) < 3 || strlen(utf8_decode($this->request->post['telephone'])) > 32) { $json['error']['telephone'] = $this->language->get('error_telephone'); } } //version if ($version_int >= 1530) { // Customer Group $this->load->model('account/customer_group'); 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'))) { $customer_group_id = $this->request->post['customer_group_id']; } elseif ($this->customer->isLogged()) { $customer_group_id = $this->customer->getCustomerGroupId(); } else { $customer_group_id = $this->config->get('config_customer_group_id'); } $customer_group = $this->model_account_customer_group->getCustomerGroup($customer_group_id); if ($customer_group) { // Company ID if ($customer_group['company_id_display'] && $customer_group['company_id_required'] && isset($this->request->post['company_id']) && empty($this->request->post['company_id'])) { $json['error']['company_id'] = $this->language->get('error_company_id'); } // Tax ID if ($customer_group['tax_id_display'] && $customer_group['tax_id_required'] && isset($this->request->post['tax_id']) && empty($this->request->post['tax_id'])) { $json['error']['tax_id'] = $this->language->get('error_tax_id'); } } } if (isset($this->request->post['company'])) { $this->session->data['shipping']['company'] = $this->request->post['company']; } if (isset($this->request->post['address_1'])) { if (strlen(utf8_decode($this->request->post['address_1'])) < 3 || strlen(utf8_decode($this->request->post['address_1'])) > 128) { $json['error']['address_1'] = $this->language->get('error_address_1'); } else { $this->session->data['shipping']['address_1'] = $this->request->post['address_1']; } } if (isset($this->request->post['country_id'])) { $country_info = $this->model_onecheckout_checkout->getCountry($this->request->post['country_id']); if ($country_info) { if (isset($this->request->post['postcode'])) { if ($country_info['postcode_required'] && strlen(utf8_decode($this->request->post['postcode'])) < 2 || strlen(utf8_decode($this->request->post['postcode'])) > 10) { $json['error']['postcode'] = $this->language->get('error_postcode'); } } if ($version_int >= 1530 && isset($this->request->post['tax_id'])) { // VAT Validation $this->load->helper('vat'); if ($this->config->get('config_vat') && $this->request->post['tax_id'] && vat_validation($country_info['iso_code_2'], $this->request->post['tax_id']) == 'invalid') { $json['error']['tax_id'] = $this->language->get('error_vat'); } } } } if (isset($this->request->post['password'])) { if (strlen(utf8_decode($this->request->post['password'])) < 4 || strlen(utf8_decode($this->request->post['password'])) > 20) { $json['error']['password'] = $this->language->get('error_password'); } } if (isset($this->request->post['password']) && isset($this->request->post['confirm'])) { if ($this->request->post['confirm'] != $this->request->post['password']) { $json['error']['confirm'] = $this->language->get('error_confirm'); } } } $this->response->setOutput($this->model_onecheckout_checkout->jsonencode($json)); }