Pachis Posted August 18, 2011 Share Posted August 18, 2011 Buenas a todos. Estoy terminando mi tienda con prestashop para vender productos de ferretería, material eléctrico, iluminación y pequeño electrodoméstico (espero abrir el 1 de Septiembre, os mantendré informados) y me encuentro con el siguiente problema. Tengo la versión 1.4.4 y a la hora de registrarse sale como obligatorio el DNI (siempre que así lo configures en el BO, sección de transporte) y al menos un número de teléfono. Mi idea es simplemente dejar esos campos como opcionales, indicando textualmente que el DNI/NIF hay que rellenarlo en caso de ser empresa/autónomo. Si desactivo la opción de pedir DNI para España en la solapa de "Transporte", directamente no sale la sección de DNI en la página de registro por lo que no es una solución viable (para empresas sería un problema). He editado el authentication.tpl del theme cambiando la clase de "required text" a simplemente "text" pero no he solucionado nada. ¿Algún alma caritativa que me diga como solucionar este problema?. Gracias! Link to comment Share on other sites More sharing options...
Eolia Posted August 18, 2011 Share Posted August 18, 2011 in controllers/AdressController.php comment this lines: if (!Tools::getValue('phone') AND !Tools::getValue('phone_mobile')) $this->errors[] = Tools::displayError('You must register at least one phone number'); if (!$country = new Country((int)$address->id_country) OR !Validate::isLoadedObject($country)) die(Tools::displayError()); enjoy ! Link to comment Share on other sites More sharing options...
Pachis Posted August 18, 2011 Author Share Posted August 18, 2011 in controllers/AdressController.php comment this lines: if (!Tools::getValue('phone') AND !Tools::getValue('phone_mobile')) $this->errors[] = Tools::displayError('You must register at least one phone number'); if (!$country = new Country((int)$address->id_country) OR !Validate::isLoadedObject($country)) die(Tools::displayError()); enjoy ! Thank you mate! You have to edit authcontroller.php too and comment the same lines. Modifying only adresscontroller.php doesn't let you register a new user whithout phone. I tried commenting only the first 2 lines and it worked for me, you don't need to comment the last 2. It's too late for me but tomorrow I will try to mod the DNI box, I will let you know. Gracias al compañero Eolia me he orientado para solucionar el asunto. Además del adresscontroller.php hay que editar también el authcontroller.php si no, no permite registrar usuarios nuevos sin indicar ningún teléfono. Basta con editar las dos primeras líneas, las 2 últimas hace referencia a otro campo. Mañana me pondré con el asunto del DNI para dejarlo opcional pero no obligatorio también, en cuanto sepa algo os comento. Link to comment Share on other sites More sharing options...
Pachis Posted August 19, 2011 Author Share Posted August 19, 2011 Solución definitiva: ----Para que los números de teléfono sean opcionales y no obligatorios: Comentar o eliminar en AddressController.php y AuthController.php (carpeta controllers) las siguientes líneas: if (!Tools::getValue('phone') AND !Tools::getValue('phone_mobile')) $this->errors[] = Tools::displayError('You must register at least one phone number'); ----Para que el campo DNI sea opcional y no obligatorio: Sustituír en AddressController.php y AuthController.php (carpeta controllers) la siguiente línea: if ($country->isNeedDni() AND (!Tools::getValue('dni') OR !Validate::isDniLite(Tools::getValue('dni')))) Por if (!Validate::isDniLite(Tools::getValue('dni'))) Saludos a todos. Link to comment Share on other sites More sharing options...
Eolia Posted August 19, 2011 Share Posted August 19, 2011 Good job Link to comment Share on other sites More sharing options...
Zenhon Posted November 27, 2011 Share Posted November 27, 2011 Hola, Aunque este post ya lleve mucho tiempo abierto sólo quiero agradecer la apertura, contestación y explicación que habéis facilitado. Muchas gracias. Link to comment Share on other sites More sharing options...
alejandrocobo Posted December 20, 2011 Share Posted December 20, 2011 Solución definitiva: ----Para que los números de teléfono sean opcionales y no obligatorios: Comentar o eliminar en AddressController.php y AuthController.php (carpeta controllers) las siguientes líneas: if (!Tools::getValue('phone') AND !Tools::getValue('phone_mobile')) $this->errors[] = Tools::displayError('You must register at least one phone number'); ----Para que el campo DNI sea opcional y no obligatorio: Sustituír en AddressController.php y AuthController.php (carpeta controllers) la siguiente línea: if ($country->isNeedDni() AND (!Tools::getValue('dni') OR !Validate::isDniLite(Tools::getValue('dni')))) Por if (!Validate::isDniLite(Tools::getValue('dni'))) Saludos a todos. Hola Pachis, Gracias por este post está interesante, el de telefono me funcionó, pero el de DNI no, hay que hacer algo mas? Gracias 1 Link to comment Share on other sites More sharing options...
Pachis Posted January 15, 2012 Author Share Posted January 15, 2012 Hola Pachis, Gracias por este post está interesante, el de telefono me funcionó, pero el de DNI no, hay que hacer algo mas? Gracias Os pego mis AddressController.php y AuthController.php tal y como lo tengo en la tienda. La solución que aporté al principio es cierto que no funcionaba correctamente pero esta es totalmente funcional. La versión de mi tienda es la 1.4.5.1. Espero que os sirva de ayuda Aquí el AddressController.php <?php /* * 2007-2011 PrestaShop * * NOTICE OF LICENSE * * This source file is subject to the Open Software License (OSL 3.0) * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://opensource.org/licenses/osl-3.0.php * If you did not receive a copy of the license and are unable to * obtain it through the world-wide-web, please send an email * to [email protected] so we can send you a copy immediately. * * DISCLAIMER * * Do not edit or add to this file if you wish to upgrade PrestaShop to newer * versions in the future. If you wish to customize PrestaShop for your * needs please refer to http://www.prestashop.com for more information. * * @author PrestaShop SA <[email protected]> * @copyright 2007-2011 PrestaShop SA * @version Release: $Revision: 7809 $ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) * International Registered Trademark & Property of PrestaShop SA */ if (Configuration::get('VATNUMBER_MANAGEMENT') AND file_exists(_PS_MODULE_DIR_.'vatnumber/vatnumber.php')) include_once(_PS_MODULE_DIR_.'vatnumber/vatnumber.php'); class AddressControllerCore extends FrontController { public $auth = true; public $guestAllowed = true; public $php_self = 'address.php'; public $authRedirection = 'addresses.php'; public $ssl = true; protected $_address; public function preProcess() { parent::preProcess(); if ($back = Tools::getValue('back')) self::$smarty->assign('back', Tools::safeOutput($back)); if ($mod = Tools::getValue('mod')) self::$smarty->assign('mod', Tools::safeOutput($mod)); if (Tools::isSubmit('ajax') AND Tools::isSubmit('type')) { if (Tools::getValue('type') == 'delivery') $id_address = isset(self::$cart->id_address_delivery) ? (int)self::$cart->id_address_delivery : 0; elseif (Tools::getValue('type') == 'invoice') $id_address = (isset(self::$cart->id_address_invoice) AND self::$cart->id_address_invoice != self::$cart->id_address_delivery) ? (int)self::$cart->id_address_invoice : 0; else exit; } else $id_address = (int)Tools::getValue('id_address', 0); if ($id_address) { $this->_address = new Address((int)$id_address); if (Validate::isLoadedObject($this->_address) AND Customer::customerHasAddress((int)(self::$cookie->id_customer), (int)($id_address))) { if (Tools::isSubmit('delete')) { if (self::$cart->id_address_invoice == $this->_address->id) unset(self::$cart->id_address_invoice); if (self::$cart->id_address_delivery == $this->_address->id) unset(self::$cart->id_address_delivery); if ($this->_address->delete()) Tools::redirect('addresses.php'); $this->errors[] = Tools::displayError('This address cannot be deleted.'); } self::$smarty->assign(array('address' => $this->_address, 'id_address' => (int)$id_address)); } elseif (Tools::isSubmit('ajax')) exit; else Tools::redirect('addresses.php'); } if (Tools::isSubmit('submitAddress')) { $address = new Address(); $this->errors = $address->validateControler(); $address->id_customer = (int)(self::$cookie->id_customer); if (!$country = new Country((int)$address->id_country) OR !Validate::isLoadedObject($country)) die(Tools::displayError()); /* US customer: normalize the address */ if ($address->id_country == Country::getByIso('US')) { include_once(_PS_TAASC_PATH_.'AddressStandardizationSolution.php'); $normalize = new AddressStandardizationSolution; $address->address1 = $normalize->AddressLineStandardization($address->address1); $address->address2 = $normalize->AddressLineStandardization($address->address2); } $zip_code_format = $country->zip_code_format; if ($country->need_zip_code) { if (($postcode = Tools::getValue('postcode')) AND $zip_code_format) { $zip_regexp = '/^'.$zip_code_format.'$/ui'; $zip_regexp = str_replace(' ', '( |)', $zip_regexp); $zip_regexp = str_replace('-', '(-|)', $zip_regexp); $zip_regexp = str_replace('N', '[0-9]', $zip_regexp); $zip_regexp = str_replace('L', '[a-zA-Z]', $zip_regexp); $zip_regexp = str_replace('C', $country->iso_code, $zip_regexp); if (!preg_match($zip_regexp, $postcode)) $this->errors[] = '<strong>'.Tools::displayError('Zip/ Postal code').'</strong> '.Tools::displayError('is invalid.').'<br />'.Tools::displayError('Must be typed as follows:').' '.str_replace('C', $country->iso_code, str_replace('N', '0', str_replace('L', 'A', $zip_code_format))); } elseif ($zip_code_format) $this->errors[] = '<strong>'.Tools::displayError('Zip/ Postal code').'</strong> '.Tools::displayError('is required.'); elseif ($postcode AND !preg_match('/^[0-9a-zA-Z -]{4,9}$/ui', $postcode)) $this->errors[] = '<strong>'.Tools::displayError('Zip/ Postal code').'</strong> '.Tools::displayError('is invalid.').'<br />'.Tools::displayError('Must be typed as follows:').' '.str_replace('C', $country->iso_code, str_replace('N', '0', str_replace('L', 'A', $zip_code_format))); } if ($country->isNeedDni() AND !Validate::isDniLite(Tools::getValue('dni'))) $this->errors[] = Tools::displayError('Identification number is incorrect or has already been used.'); elseif (!$country->isNeedDni()) $address->dni = NULL; if (Configuration::get('PS_TOKEN_ENABLE') == 1 AND strcmp(Tools::getToken(false), Tools::getValue('token')) AND self::$cookie->isLogged(true) === true) $this->errors[] = Tools::displayError('Invalid token'); if ((int)($country->contains_states) AND !(int)($address->id_state)) $this->errors[] = Tools::displayError('This country requires a state selection.'); if (!sizeof($this->errors)) { if (isset($id_address)) { $country = new Country((int)($address->id_country)); if (Validate::isLoadedObject($country) AND !$country->contains_states) $address->id_state = 0; $address_old = new Address((int)$id_address); if (Validate::isLoadedObject($address_old) AND Customer::customerHasAddress((int)self::$cookie->id_customer, (int)$address_old->id)) { if ($address_old->isUsed()) { $address_old->delete(); if (!Tools::isSubmit('ajax')) { $to_update = false; if (self::$cart->id_address_invoice == $address_old->id) { $to_update = true; self::$cart->id_address_invoice = 0; } if (self::$cart->id_address_delivery == $address_old->id) { $to_update = true; self::$cart->id_address_delivery = 0; } if ($to_update) self::$cart->update(); } } else { $address->id = (int)($address_old->id); $address->date_add = $address_old->date_add; } } } elseif (self::$cookie->is_guest) Tools::redirect('addresses.php'); if ($result = $address->save()) { /* In order to select this new address : order-address.tpl */ if ((bool)(Tools::getValue('select_address', false)) == true OR (Tools::isSubmit('ajax') AND Tools::getValue('type') == 'invoice')) { /* This new adress is for invoice_adress, select it */ self::$cart->id_address_invoice = (int)($address->id); self::$cart->update(); } if (Tools::isSubmit('ajax')) { $return = array( 'hasError' => !empty($this->errors), 'errors' => $this->errors, 'id_address_delivery' => self::$cart->id_address_delivery, 'id_address_invoice' => self::$cart->id_address_invoice ); die(Tools::jsonEncode($return)); } Tools::redirect($back ? ($mod ? $back.'&back='.$mod : $back) : 'addresses.php'); } $this->errors[] = Tools::displayError('An error occurred while updating your address.'); } } elseif (!$id_address) { $customer = new Customer((int)(self::$cookie->id_customer)); if (Validate::isLoadedObject($customer)) { $_POST['firstname'] = $customer->firstname; $_POST['lastname'] = $customer->lastname; } } if (Tools::isSubmit('ajax') AND sizeof($this->errors)) { $return = array( 'hasError' => !empty($this->errors), 'errors' => $this->errors ); die(Tools::jsonEncode($return)); } } public function setMedia() { parent::setMedia(); Tools::addJS(_THEME_JS_DIR_.'tools/statesManagement.js'); } public function process() { parent::process(); /* Secure restriction for guest */ if (self::$cookie->is_guest) Tools::redirect('addresses.php'); if (Tools::isSubmit('id_country') AND Tools::getValue('id_country') != NULL AND is_numeric(Tools::getValue('id_country'))) $selectedCountry = (int)Tools::getValue('id_country'); elseif (isset($this->_address) AND isset($this->_address->id_country) AND !empty($this->_address->id_country) AND is_numeric($this->_address->id_country)) $selectedCountry = (int)$this->_address->id_country; elseif (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { $array = preg_split('/,|-/', $_SERVER['HTTP_ACCEPT_LANGUAGE']); if (!Validate::isLanguageIsoCode($array[0]) OR !($selectedCountry = Country::getByIso($array[0]))) $selectedCountry = (int)Configuration::get('PS_COUNTRY_DEFAULT'); } else $selectedCountry = (int)Configuration::get('PS_COUNTRY_DEFAULT'); if (Configuration::get('PS_RESTRICT_DELIVERED_COUNTRIES')) $countries = Carrier::getDeliveredCountries((int)self::$cookie->id_lang, true, true); else $countries = Country::getCountries((int)self::$cookie->id_lang, true); $countriesList = ''; foreach ($countries AS $country) $countriesList .= '<option value="'.(int)($country['id_country']).'" '.($country['id_country'] == $selectedCountry ? 'selected="selected"' : '').'>'.htmlentities($country['name'], ENT_COMPAT, 'UTF-8').'</option>'; if ((Configuration::get('VATNUMBER_MANAGEMENT') AND file_exists(_PS_MODULE_DIR_.'vatnumber/vatnumber.php')) && VatNumber::isApplicable(Configuration::get('PS_COUNTRY_DEFAULT'))) self::$smarty->assign('vat_display', 2); elseif (Configuration::get('VATNUMBER_MANAGEMENT')) self::$smarty->assign('vat_display', 1); else self::$smarty->assign('vat_display', 0); self::$smarty->assign('ajaxurl', _MODULE_DIR_); self::$smarty->assign('vatnumber_ajax_call', (int)file_exists(_PS_MODULE_DIR_.'vatnumber/ajax.php')); self::$smarty->assign(array( 'countries_list' => $countriesList, 'countries' => $countries, 'errors' => $this->errors, 'token' => Tools::getToken(false), 'select_address' => (int)(Tools::getValue('select_address')) )); } protected function _processAddressFormat() { $id_country = is_null($this->_address)? 0 : (int)$this->_address->id_country; $dlv_adr_fields = AddressFormat::getOrderedAddressFields($id_country, true, true); self::$smarty->assign('ordered_adr_fields', $dlv_adr_fields); } public function displayHeader() { if (Tools::getValue('ajax') != 'true') parent::displayHeader(); } public function displayContent() { parent::displayContent(); $this->_processAddressFormat(); self::$smarty->display(_PS_THEME_DIR_.'address.tpl'); } public function displayFooter() { if (Tools::getValue('ajax') != 'true') parent::displayFooter(); } } Aquí el AuthController.php <?php /* * 2007-2011 PrestaShop * * NOTICE OF LICENSE * * This source file is subject to the Open Software License (OSL 3.0) * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://opensource.org/licenses/osl-3.0.php * If you did not receive a copy of the license and are unable to * obtain it through the world-wide-web, please send an email * to [email protected] so we can send you a copy immediately. * * DISCLAIMER * * Do not edit or add to this file if you wish to upgrade PrestaShop to newer * versions in the future. If you wish to customize PrestaShop for your * needs please refer to http://www.prestashop.com for more information. * * @author PrestaShop SA <[email protected]> * @copyright 2007-2011 PrestaShop SA * @version Release: $Revision: 8859 $ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) * International Registered Trademark & Property of PrestaShop SA */ class AuthControllerCore extends FrontController { public $ssl = true; public $php_self = 'authentication.php'; public function preProcess() { parent::preProcess(); if (self::$cookie->isLogged() AND !Tools::isSubmit('ajax')) Tools::redirect('my-account.php'); if (Tools::getValue('create_account')) { $create_account = 1; self::$smarty->assign('email_create', 1); } if (Tools::isSubmit('SubmitCreate')) { if (!Validate::isEmail($email = Tools::getValue('email_create')) OR empty($email)) $this->errors[] = Tools::displayError('Invalid e-mail address'); elseif (Customer::customerExists($email)) { $this->errors[] = Tools::displayError('An account is already registered with this e-mail, please fill in the password or request a new one.'); $_POST['email'] = $_POST['email_create']; unset($_POST['email_create']); } else { $create_account = 1; self::$smarty->assign('email_create', Tools::safeOutput($email)); $_POST['email'] = $email; } } if (Tools::isSubmit('submitAccount') OR Tools::isSubmit('submitGuestAccount')) { $create_account = 1; if (Tools::isSubmit('submitAccount')) self::$smarty->assign('email_create', 1); /* New Guest customer */ if (!Tools::getValue('is_new_customer', 1) AND !Configuration::get('PS_GUEST_CHECKOUT_ENABLED')) $this->errors[] = Tools::displayError('You cannot create a guest account.'); if (!Tools::getValue('is_new_customer', 1)) $_POST['passwd'] = md5(time()._COOKIE_KEY_); if (isset($_POST['guest_email']) AND $_POST['guest_email']) $_POST['email'] = $_POST['guest_email']; /* Preparing customer */ $customer = new Customer(); $lastnameAddress = $_POST['lastname']; $firstnameAddress = $_POST['firstname']; $_POST['lastname'] = $_POST['customer_lastname']; $_POST['firstname'] = $_POST['customer_firstname']; if (!@checkdate(Tools::getValue('months'), Tools::getValue('days'), Tools::getValue('years')) AND !(Tools::getValue('months') == '' AND Tools::getValue('days') == '' AND Tools::getValue('years') == '')) $this->errors[] = Tools::displayError('Invalid date of birth'); $customer->birthday = (empty($_POST['years']) ? '' : (int)($_POST['years']).'-'.(int)($_POST['months']).'-'.(int)($_POST['days'])); $this->errors = array_unique(array_merge($this->errors, $customer->validateControler())); /* Preparing address */ $address = new Address(); $_POST['lastname'] = $lastnameAddress; $_POST['firstname'] = $firstnameAddress; $address->id_customer = 1; $this->errors = array_unique(array_merge($this->errors, $address->validateControler())); /* US customer: normalize the address */ if ($address->id_country == Country::getByIso('US')) { include_once(_PS_TAASC_PATH_.'AddressStandardizationSolution.php'); $normalize = new AddressStandardizationSolution; $address->address1 = $normalize->AddressLineStandardization($address->address1); $address->address2 = $normalize->AddressLineStandardization($address->address2); } $zip_code_format = Country::getZipCodeFormat((int)(Tools::getValue('id_country'))); if (Country::getNeedZipCode((int)(Tools::getValue('id_country')))) { if (($postcode = Tools::getValue('postcode')) AND $zip_code_format) { $zip_regexp = '/^'.$zip_code_format.'$/ui'; $zip_regexp = str_replace(' ', '( |)', $zip_regexp); $zip_regexp = str_replace('-', '(-|)', $zip_regexp); $zip_regexp = str_replace('N', '[0-9]', $zip_regexp); $zip_regexp = str_replace('L', '[a-zA-Z]', $zip_regexp); $zip_regexp = str_replace('C', Country::getIsoById((int)(Tools::getValue('id_country'))), $zip_regexp); if (!preg_match($zip_regexp, $postcode)) $this->errors[] = '<strong>'.Tools::displayError('Zip/ Postal code').'</strong> '.Tools::displayError('is invalid.').'<br />'.Tools::displayError('Must be typed as follows:').' '.str_replace('C', Country::getIsoById((int)(Tools::getValue('id_country'))), str_replace('N', '0', str_replace('L', 'A', $zip_code_format))); } elseif ($zip_code_format) $this->errors[] = '<strong>'.Tools::displayError('Zip/ Postal code').'</strong> '.Tools::displayError('is required.'); elseif ($postcode AND !preg_match('/^[0-9a-zA-Z -]{4,9}$/ui', $postcode)) $this->errors[] = '<strong>'.Tools::displayError('Zip/ Postal code').'</strong> '.Tools::displayError('is invalid.'); } if (Country::isNeedDniByCountryId($address->id_country) AND !Validate::isDniLite(Tools::getValue('dni'))) $this->errors[] = Tools::displayError('Identification number is incorrect or has already been used.'); elseif (!Country::isNeedDniByCountryId($address->id_country)) $address->dni = NULL; if (!sizeof($this->errors)) { if (Customer::customerExists(Tools::getValue('email'))) $this->errors[] = Tools::displayError('An account is already registered with this e-mail, please fill in the password or request a new one.'); if (Tools::isSubmit('newsletter')) { $customer->ip_registration_newsletter = pSQL(Tools::getRemoteAddr()); $customer->newsletter_date_add = pSQL(date('Y-m-d H:i:s')); } if (!sizeof($this->errors)) { if (!$country = new Country($address->id_country, Configuration::get('PS_LANG_DEFAULT')) OR !Validate::isLoadedObject($country)) die(Tools::displayError()); if ((int)($country->contains_states) AND !(int)($address->id_state)) $this->errors[] = Tools::displayError('This country requires a state selection.'); else { $customer->active = 1; /* New Guest customer */ if (Tools::isSubmit('is_new_customer')) $customer->is_guest = !Tools::getValue('is_new_customer', 1); else $customer->is_guest = 0; if (!$customer->add()) $this->errors[] = Tools::displayError('An error occurred while creating your account.'); else { $address->id_customer = (int)($customer->id); if (!$address->add()) $this->errors[] = Tools::displayError('An error occurred while creating your address.'); else { if (!$customer->is_guest) { if (!Mail::Send((int)(self::$cookie->id_lang), 'account', Mail::l('Welcome!'), array('{firstname}' => $customer->firstname, '{lastname}' => $customer->lastname, '{email}' => $customer->email, '{passwd}' => Tools::getValue('passwd')), $customer->email, $customer->firstname.' '.$customer->lastname)) $this->errors[] = Tools::displayError('Cannot send email'); } self::$smarty->assign('confirmation', 1); self::$cookie->id_customer = (int)($customer->id); self::$cookie->customer_lastname = $customer->lastname; self::$cookie->customer_firstname = $customer->firstname; self::$cookie->passwd = $customer->passwd; self::$cookie->logged = 1; self::$cookie->email = $customer->email; self::$cookie->is_guest = !Tools::getValue('is_new_customer', 1); /* Update cart address */ self::$cart->secure_key = $customer->secure_key; self::$cart->id_address_delivery = Address::getFirstCustomerAddressId((int)($customer->id)); self::$cart->id_address_invoice = Address::getFirstCustomerAddressId((int)($customer->id)); self::$cart->update(); Module::hookExec('createAccount', array( '_POST' => $_POST, 'newCustomer' => $customer )); if (Tools::isSubmit('ajax')) { $return = array( 'hasError' => !empty($this->errors), 'errors' => $this->errors, 'isSaved' => true, 'id_customer' => (int)self::$cookie->id_customer, 'id_address_delivery' => self::$cart->id_address_delivery, 'id_address_invoice' => self::$cart->id_address_invoice, 'token' => Tools::getToken(false) ); die(Tools::jsonEncode($return)); } if ($back = Tools::getValue('back')) Tools::redirect($back); Tools::redirect('my-account.php'); } } } } } if (sizeof($this->errors)) { if (!Tools::getValue('is_new_customer')) unset($_POST['passwd']); if (Tools::isSubmit('ajax')) { $return = array( 'hasError' => !empty($this->errors), 'errors' => $this->errors, 'isSaved' => false, 'id_customer' => 0 ); die(Tools::jsonEncode($return)); } } } if (Tools::isSubmit('SubmitLogin')) { Module::hookExec('beforeAuthentication'); $passwd = trim(Tools::getValue('passwd')); $email = trim(Tools::getValue('email')); if (empty($email)) $this->errors[] = Tools::displayError('E-mail address required'); elseif (!Validate::isEmail($email)) $this->errors[] = Tools::displayError('Invalid e-mail address'); elseif (empty($passwd)) $this->errors[] = Tools::displayError('Password is required'); elseif (Tools::strlen($passwd) > 32) $this->errors[] = Tools::displayError('Password is too long'); elseif (!Validate::isPasswd($passwd)) $this->errors[] = Tools::displayError('Invalid password'); else { $customer = new Customer(); $authentication = $customer->getByEmail(trim($email), trim($passwd)); if (!$authentication OR !$customer->id) { /* Handle brute force attacks */ sleep(1); $this->errors[] = Tools::displayError('Authentication failed'); } else { self::$cookie->id_customer = (int)($customer->id); self::$cookie->customer_lastname = $customer->lastname; self::$cookie->customer_firstname = $customer->firstname; self::$cookie->logged = 1; self::$cookie->is_guest = $customer->isGuest(); self::$cookie->passwd = $customer->passwd; self::$cookie->email = $customer->email; if (Configuration::get('PS_CART_FOLLOWING') AND (empty(self::$cookie->id_cart) OR Cart::getNbProducts(self::$cookie->id_cart) == 0)) self::$cookie->id_cart = (int)(Cart::lastNoneOrderedCart((int)($customer->id))); /* Update cart address */ self::$cart->id_carrier = 0; self::$cart->id_address_delivery = Address::getFirstCustomerAddressId((int)($customer->id)); self::$cart->id_address_invoice = Address::getFirstCustomerAddressId((int)($customer->id)); // If a logged guest logs in as a customer, the cart secure key was already set and needs to be updated self::$cart->secure_key = $customer->secure_key; self::$cart->update(); Module::hookExec('authentication'); if (!Tools::isSubmit('ajax')) { if ($back = Tools::getValue('back')) Tools::redirect($back); Tools::redirect('my-account.php'); } } } if (Tools::isSubmit('ajax')) { $return = array( 'hasError' => !empty($this->errors), 'errors' => $this->errors, 'token' => Tools::getToken(false) ); die(Tools::jsonEncode($return)); } } if (isset($create_account)) { /* Select the most appropriate country */ if (isset($_POST['id_country']) AND is_numeric($_POST['id_country'])) $selectedCountry = (int)($_POST['id_country']); /* FIXME : language iso and country iso are not similar, * maybe an associative table with country an language can resolve it, * But for now it's a bug ! * @see : bug #6968 * @link:http://www.prestashop.com/bug_tracker/view/6968/ elseif (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { $array = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']); if (Validate::isLanguageIsoCode($array[0])) { $selectedCountry = Country::getByIso($array[0]); if (!$selectedCountry) $selectedCountry = (int)(Configuration::get('PS_COUNTRY_DEFAULT')); } }*/ if (!isset($selectedCountry)) $selectedCountry = (int)(Configuration::get('PS_COUNTRY_DEFAULT')); if (Configuration::get('PS_RESTRICT_DELIVERED_COUNTRIES')) $countries = Carrier::getDeliveredCountries((int)self::$cookie->id_lang, true, true); else $countries = Country::getCountries((int)self::$cookie->id_lang, true); self::$smarty->assign(array( 'countries' => $countries, 'sl_country' => (isset($selectedCountry) ? $selectedCountry : 0), 'vat_management' => Configuration::get('VATNUMBER_MANAGEMENT') )); /* Call a hook to display more information on form */ self::$smarty->assign(array( 'HOOK_CREATE_ACCOUNT_FORM' => Module::hookExec('createAccountForm'), 'HOOK_CREATE_ACCOUNT_TOP' => Module::hookExec('createAccountTop') )); } /* Generate years, months and days */ if (isset($_POST['years']) AND is_numeric($_POST['years'])) $selectedYears = (int)($_POST['years']); $years = Tools::dateYears(); if (isset($_POST['months']) AND is_numeric($_POST['months'])) $selectedMonths = (int)($_POST['months']); $months = Tools::dateMonths(); if (isset($_POST['days']) AND is_numeric($_POST['days'])) $selectedDays = (int)($_POST['days']); $days = Tools::dateDays(); self::$smarty->assign(array( 'years' => $years, 'sl_year' => (isset($selectedYears) ? $selectedYears : 0), 'months' => $months, 'sl_month' => (isset($selectedMonths) ? $selectedMonths : 0), 'days' => $days, 'sl_day' => (isset($selectedDays) ? $selectedDays : 0) )); self::$smarty->assign('newsletter', (int)Module::getInstanceByName('blocknewsletter')->active); } public function setMedia() { parent::setMedia(); Tools::addCSS(_THEME_CSS_DIR_.'authentication.css'); Tools::addJS(array(_THEME_JS_DIR_.'tools/statesManagement.js', _PS_JS_DIR_.'jquery/jquery-typewatch.pack.js')); } public function process() { parent::process(); $back = Tools::getValue('back'); $key = Tools::safeOutput(Tools::getValue('key')); if (!empty($key)) $back .= (strpos($back, '?') !== false ? '&' : '?').'key='.$key; if (!empty($back)) { self::$smarty->assign('back', Tools::safeOutput($back)); if (strpos($back, 'order.php') !== false) { if (Configuration::get('PS_RESTRICT_DELIVERED_COUNTRIES')) $countries = Carrier::getDeliveredCountries((int)self::$cookie->id_lang, true, true); else $countries = Country::getCountries((int)self::$cookie->id_lang, true); self::$smarty->assign(array( 'inOrderProcess' => true, 'PS_GUEST_CHECKOUT_ENABLED' => Configuration::get('PS_GUEST_CHECKOUT_ENABLED'), 'sl_country' => (int)Tools::getValue('id_country', Configuration::get('PS_COUNTRY_DEFAULT')), 'countries' => $countries )); } } } public function displayContent() { $this->processAddressFormat(); parent::displayContent(); self::$smarty->display(_PS_THEME_DIR_.'authentication.tpl'); } protected function processAddressFormat() { $addressItems = array(); $addressFormat = AddressFormat::getOrderedAddressFields(Configuration::get('PS_COUNTRY_DEFAULT'), false, true); $requireFormFieldsList = AddressFormat::$requireFormFieldsList; foreach ($addressFormat as $addressline) foreach (explode(' ', $addressline) as $addressItem) $addressItems[] = trim($addressItem); // Add missing require fields for a new user susbscription form foreach($requireFormFieldsList as $fieldName) if (!in_array($fieldName, $addressItems)) $addressItems[] = trim($fieldName); foreach (array('inv', 'dlv') as $addressType) self::$smarty->assign(array($addressType.'_adr_fields' => $addressFormat, $addressType.'_all_fields' => $addressItems)); } } Link to comment Share on other sites More sharing options...
nadie Posted January 15, 2012 Share Posted January 15, 2012 Os pego mis AddressController.php y AuthController.php tal y como lo tengo en la tienda. La solución que aporté al principio es cierto que no funcionaba correctamente pero esta es totalmente funcional. La versión de mi tienda es la 1.4.5.1. Espero que os sirva de ayuda Aquí el AddressController.php <?php /* * 2007-2011 PrestaShop * * NOTICE OF LICENSE * * This source file is subject to the Open Software License (OSL 3.0) * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://opensource.org/licenses/osl-3.0.php * If you did not receive a copy of the license and are unable to * obtain it through the world-wide-web, please send an email * to [email protected] so we can send you a copy immediately. * * DISCLAIMER * * Do not edit or add to this file if you wish to upgrade PrestaShop to newer * versions in the future. If you wish to customize PrestaShop for your * needs please refer to http://www.prestashop.com for more information. * * @author PrestaShop SA <[email protected]> * @copyright 2007-2011 PrestaShop SA * @version Release: $Revision: 7809 $ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) * International Registered Trademark & Property of PrestaShop SA */ if (Configuration::get('VATNUMBER_MANAGEMENT') AND file_exists(_PS_MODULE_DIR_.'vatnumber/vatnumber.php')) include_once(_PS_MODULE_DIR_.'vatnumber/vatnumber.php'); class AddressControllerCore extends FrontController { public $auth = true; public $guestAllowed = true; public $php_self = 'address.php'; public $authRedirection = 'addresses.php'; public $ssl = true; protected $_address; public function preProcess() { parent::preProcess(); if ($back = Tools::getValue('back')) self::$smarty->assign('back', Tools::safeOutput($back)); if ($mod = Tools::getValue('mod')) self::$smarty->assign('mod', Tools::safeOutput($mod)); if (Tools::isSubmit('ajax') AND Tools::isSubmit('type')) { if (Tools::getValue('type') == 'delivery') $id_address = isset(self::$cart->id_address_delivery) ? (int)self::$cart->id_address_delivery : 0; elseif (Tools::getValue('type') == 'invoice') $id_address = (isset(self::$cart->id_address_invoice) AND self::$cart->id_address_invoice != self::$cart->id_address_delivery) ? (int)self::$cart->id_address_invoice : 0; else exit; } else $id_address = (int)Tools::getValue('id_address', 0); if ($id_address) { $this->_address = new Address((int)$id_address); if (Validate::isLoadedObject($this->_address) AND Customer::customerHasAddress((int)(self::$cookie->id_customer), (int)($id_address))) { if (Tools::isSubmit('delete')) { if (self::$cart->id_address_invoice == $this->_address->id) unset(self::$cart->id_address_invoice); if (self::$cart->id_address_delivery == $this->_address->id) unset(self::$cart->id_address_delivery); if ($this->_address->delete()) Tools::redirect('addresses.php'); $this->errors[] = Tools::displayError('This address cannot be deleted.'); } self::$smarty->assign(array('address' => $this->_address, 'id_address' => (int)$id_address)); } elseif (Tools::isSubmit('ajax')) exit; else Tools::redirect('addresses.php'); } if (Tools::isSubmit('submitAddress')) { $address = new Address(); $this->errors = $address->validateControler(); $address->id_customer = (int)(self::$cookie->id_customer); if (!$country = new Country((int)$address->id_country) OR !Validate::isLoadedObject($country)) die(Tools::displayError()); /* US customer: normalize the address */ if ($address->id_country == Country::getByIso('US')) { include_once(_PS_TAASC_PATH_.'AddressStandardizationSolution.php'); $normalize = new AddressStandardizationSolution; $address->address1 = $normalize->AddressLineStandardization($address->address1); $address->address2 = $normalize->AddressLineStandardization($address->address2); } $zip_code_format = $country->zip_code_format; if ($country->need_zip_code) { if (($postcode = Tools::getValue('postcode')) AND $zip_code_format) { $zip_regexp = '/^'.$zip_code_format.'$/ui'; $zip_regexp = str_replace(' ', '( |)', $zip_regexp); $zip_regexp = str_replace('-', '(-|)', $zip_regexp); $zip_regexp = str_replace('N', '[0-9]', $zip_regexp); $zip_regexp = str_replace('L', '[a-zA-Z]', $zip_regexp); $zip_regexp = str_replace('C', $country->iso_code, $zip_regexp); if (!preg_match($zip_regexp, $postcode)) $this->errors[] = '<strong>'.Tools::displayError('Zip/ Postal code').'</strong> '.Tools::displayError('is invalid.').'<br />'.Tools::displayError('Must be typed as follows:').' '.str_replace('C', $country->iso_code, str_replace('N', '0', str_replace('L', 'A', $zip_code_format))); } elseif ($zip_code_format) $this->errors[] = '<strong>'.Tools::displayError('Zip/ Postal code').'</strong> '.Tools::displayError('is required.'); elseif ($postcode AND !preg_match('/^[0-9a-zA-Z -]{4,9}$/ui', $postcode)) $this->errors[] = '<strong>'.Tools::displayError('Zip/ Postal code').'</strong> '.Tools::displayError('is invalid.').'<br />'.Tools::displayError('Must be typed as follows:').' '.str_replace('C', $country->iso_code, str_replace('N', '0', str_replace('L', 'A', $zip_code_format))); } if ($country->isNeedDni() AND !Validate::isDniLite(Tools::getValue('dni'))) $this->errors[] = Tools::displayError('Identification number is incorrect or has already been used.'); elseif (!$country->isNeedDni()) $address->dni = NULL; if (Configuration::get('PS_TOKEN_ENABLE') == 1 AND strcmp(Tools::getToken(false), Tools::getValue('token')) AND self::$cookie->isLogged(true) === true) $this->errors[] = Tools::displayError('Invalid token'); if ((int)($country->contains_states) AND !(int)($address->id_state)) $this->errors[] = Tools::displayError('This country requires a state selection.'); if (!sizeof($this->errors)) { if (isset($id_address)) { $country = new Country((int)($address->id_country)); if (Validate::isLoadedObject($country) AND !$country->contains_states) $address->id_state = 0; $address_old = new Address((int)$id_address); if (Validate::isLoadedObject($address_old) AND Customer::customerHasAddress((int)self::$cookie->id_customer, (int)$address_old->id)) { if ($address_old->isUsed()) { $address_old->delete(); if (!Tools::isSubmit('ajax')) { $to_update = false; if (self::$cart->id_address_invoice == $address_old->id) { $to_update = true; self::$cart->id_address_invoice = 0; } if (self::$cart->id_address_delivery == $address_old->id) { $to_update = true; self::$cart->id_address_delivery = 0; } if ($to_update) self::$cart->update(); } } else { $address->id = (int)($address_old->id); $address->date_add = $address_old->date_add; } } } elseif (self::$cookie->is_guest) Tools::redirect('addresses.php'); if ($result = $address->save()) { /* In order to select this new address : order-address.tpl */ if ((bool)(Tools::getValue('select_address', false)) == true OR (Tools::isSubmit('ajax') AND Tools::getValue('type') == 'invoice')) { /* This new adress is for invoice_adress, select it */ self::$cart->id_address_invoice = (int)($address->id); self::$cart->update(); } if (Tools::isSubmit('ajax')) { $return = array( 'hasError' => !empty($this->errors), 'errors' => $this->errors, 'id_address_delivery' => self::$cart->id_address_delivery, 'id_address_invoice' => self::$cart->id_address_invoice ); die(Tools::jsonEncode($return)); } Tools::redirect($back ? ($mod ? $back.'&back='.$mod : $back) : 'addresses.php'); } $this->errors[] = Tools::displayError('An error occurred while updating your address.'); } } elseif (!$id_address) { $customer = new Customer((int)(self::$cookie->id_customer)); if (Validate::isLoadedObject($customer)) { $_POST['firstname'] = $customer->firstname; $_POST['lastname'] = $customer->lastname; } } if (Tools::isSubmit('ajax') AND sizeof($this->errors)) { $return = array( 'hasError' => !empty($this->errors), 'errors' => $this->errors ); die(Tools::jsonEncode($return)); } } public function setMedia() { parent::setMedia(); Tools::addJS(_THEME_JS_DIR_.'tools/statesManagement.js'); } public function process() { parent::process(); /* Secure restriction for guest */ if (self::$cookie->is_guest) Tools::redirect('addresses.php'); if (Tools::isSubmit('id_country') AND Tools::getValue('id_country') != NULL AND is_numeric(Tools::getValue('id_country'))) $selectedCountry = (int)Tools::getValue('id_country'); elseif (isset($this->_address) AND isset($this->_address->id_country) AND !empty($this->_address->id_country) AND is_numeric($this->_address->id_country)) $selectedCountry = (int)$this->_address->id_country; elseif (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { $array = preg_split('/,|-/', $_SERVER['HTTP_ACCEPT_LANGUAGE']); if (!Validate::isLanguageIsoCode($array[0]) OR !($selectedCountry = Country::getByIso($array[0]))) $selectedCountry = (int)Configuration::get('PS_COUNTRY_DEFAULT'); } else $selectedCountry = (int)Configuration::get('PS_COUNTRY_DEFAULT'); if (Configuration::get('PS_RESTRICT_DELIVERED_COUNTRIES')) $countries = Carrier::getDeliveredCountries((int)self::$cookie->id_lang, true, true); else $countries = Country::getCountries((int)self::$cookie->id_lang, true); $countriesList = ''; foreach ($countries AS $country) $countriesList .= '<option value="'.(int)($country['id_country']).'" '.($country['id_country'] == $selectedCountry ? 'selected="selected"' : '').'>'.htmlentities($country['name'], ENT_COMPAT, 'UTF-8').'</option>'; if ((Configuration::get('VATNUMBER_MANAGEMENT') AND file_exists(_PS_MODULE_DIR_.'vatnumber/vatnumber.php')) && VatNumber::isApplicable(Configuration::get('PS_COUNTRY_DEFAULT'))) self::$smarty->assign('vat_display', 2); elseif (Configuration::get('VATNUMBER_MANAGEMENT')) self::$smarty->assign('vat_display', 1); else self::$smarty->assign('vat_display', 0); self::$smarty->assign('ajaxurl', _MODULE_DIR_); self::$smarty->assign('vatnumber_ajax_call', (int)file_exists(_PS_MODULE_DIR_.'vatnumber/ajax.php')); self::$smarty->assign(array( 'countries_list' => $countriesList, 'countries' => $countries, 'errors' => $this->errors, 'token' => Tools::getToken(false), 'select_address' => (int)(Tools::getValue('select_address')) )); } protected function _processAddressFormat() { $id_country = is_null($this->_address)? 0 : (int)$this->_address->id_country; $dlv_adr_fields = AddressFormat::getOrderedAddressFields($id_country, true, true); self::$smarty->assign('ordered_adr_fields', $dlv_adr_fields); } public function displayHeader() { if (Tools::getValue('ajax') != 'true') parent::displayHeader(); } public function displayContent() { parent::displayContent(); $this->_processAddressFormat(); self::$smarty->display(_PS_THEME_DIR_.'address.tpl'); } public function displayFooter() { if (Tools::getValue('ajax') != 'true') parent::displayFooter(); } } Aquí el AuthController.php <?php /* * 2007-2011 PrestaShop * * NOTICE OF LICENSE * * This source file is subject to the Open Software License (OSL 3.0) * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://opensource.org/licenses/osl-3.0.php * If you did not receive a copy of the license and are unable to * obtain it through the world-wide-web, please send an email * to [email protected] so we can send you a copy immediately. * * DISCLAIMER * * Do not edit or add to this file if you wish to upgrade PrestaShop to newer * versions in the future. If you wish to customize PrestaShop for your * needs please refer to http://www.prestashop.com for more information. * * @author PrestaShop SA <[email protected]> * @copyright 2007-2011 PrestaShop SA * @version Release: $Revision: 8859 $ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) * International Registered Trademark & Property of PrestaShop SA */ class AuthControllerCore extends FrontController { public $ssl = true; public $php_self = 'authentication.php'; public function preProcess() { parent::preProcess(); if (self::$cookie->isLogged() AND !Tools::isSubmit('ajax')) Tools::redirect('my-account.php'); if (Tools::getValue('create_account')) { $create_account = 1; self::$smarty->assign('email_create', 1); } if (Tools::isSubmit('SubmitCreate')) { if (!Validate::isEmail($email = Tools::getValue('email_create')) OR empty($email)) $this->errors[] = Tools::displayError('Invalid e-mail address'); elseif (Customer::customerExists($email)) { $this->errors[] = Tools::displayError('An account is already registered with this e-mail, please fill in the password or request a new one.'); $_POST['email'] = $_POST['email_create']; unset($_POST['email_create']); } else { $create_account = 1; self::$smarty->assign('email_create', Tools::safeOutput($email)); $_POST['email'] = $email; } } if (Tools::isSubmit('submitAccount') OR Tools::isSubmit('submitGuestAccount')) { $create_account = 1; if (Tools::isSubmit('submitAccount')) self::$smarty->assign('email_create', 1); /* New Guest customer */ if (!Tools::getValue('is_new_customer', 1) AND !Configuration::get('PS_GUEST_CHECKOUT_ENABLED')) $this->errors[] = Tools::displayError('You cannot create a guest account.'); if (!Tools::getValue('is_new_customer', 1)) $_POST['passwd'] = md5(time()._COOKIE_KEY_); if (isset($_POST['guest_email']) AND $_POST['guest_email']) $_POST['email'] = $_POST['guest_email']; /* Preparing customer */ $customer = new Customer(); $lastnameAddress = $_POST['lastname']; $firstnameAddress = $_POST['firstname']; $_POST['lastname'] = $_POST['customer_lastname']; $_POST['firstname'] = $_POST['customer_firstname']; if (!@checkdate(Tools::getValue('months'), Tools::getValue('days'), Tools::getValue('years')) AND !(Tools::getValue('months') == '' AND Tools::getValue('days') == '' AND Tools::getValue('years') == '')) $this->errors[] = Tools::displayError('Invalid date of birth'); $customer->birthday = (empty($_POST['years']) ? '' : (int)($_POST['years']).'-'.(int)($_POST['months']).'-'.(int)($_POST['days'])); $this->errors = array_unique(array_merge($this->errors, $customer->validateControler())); /* Preparing address */ $address = new Address(); $_POST['lastname'] = $lastnameAddress; $_POST['firstname'] = $firstnameAddress; $address->id_customer = 1; $this->errors = array_unique(array_merge($this->errors, $address->validateControler())); /* US customer: normalize the address */ if ($address->id_country == Country::getByIso('US')) { include_once(_PS_TAASC_PATH_.'AddressStandardizationSolution.php'); $normalize = new AddressStandardizationSolution; $address->address1 = $normalize->AddressLineStandardization($address->address1); $address->address2 = $normalize->AddressLineStandardization($address->address2); } $zip_code_format = Country::getZipCodeFormat((int)(Tools::getValue('id_country'))); if (Country::getNeedZipCode((int)(Tools::getValue('id_country')))) { if (($postcode = Tools::getValue('postcode')) AND $zip_code_format) { $zip_regexp = '/^'.$zip_code_format.'$/ui'; $zip_regexp = str_replace(' ', '( |)', $zip_regexp); $zip_regexp = str_replace('-', '(-|)', $zip_regexp); $zip_regexp = str_replace('N', '[0-9]', $zip_regexp); $zip_regexp = str_replace('L', '[a-zA-Z]', $zip_regexp); $zip_regexp = str_replace('C', Country::getIsoById((int)(Tools::getValue('id_country'))), $zip_regexp); if (!preg_match($zip_regexp, $postcode)) $this->errors[] = '<strong>'.Tools::displayError('Zip/ Postal code').'</strong> '.Tools::displayError('is invalid.').'<br />'.Tools::displayError('Must be typed as follows:').' '.str_replace('C', Country::getIsoById((int)(Tools::getValue('id_country'))), str_replace('N', '0', str_replace('L', 'A', $zip_code_format))); } elseif ($zip_code_format) $this->errors[] = '<strong>'.Tools::displayError('Zip/ Postal code').'</strong> '.Tools::displayError('is required.'); elseif ($postcode AND !preg_match('/^[0-9a-zA-Z -]{4,9}$/ui', $postcode)) $this->errors[] = '<strong>'.Tools::displayError('Zip/ Postal code').'</strong> '.Tools::displayError('is invalid.'); } if (Country::isNeedDniByCountryId($address->id_country) AND !Validate::isDniLite(Tools::getValue('dni'))) $this->errors[] = Tools::displayError('Identification number is incorrect or has already been used.'); elseif (!Country::isNeedDniByCountryId($address->id_country)) $address->dni = NULL; if (!sizeof($this->errors)) { if (Customer::customerExists(Tools::getValue('email'))) $this->errors[] = Tools::displayError('An account is already registered with this e-mail, please fill in the password or request a new one.'); if (Tools::isSubmit('newsletter')) { $customer->ip_registration_newsletter = pSQL(Tools::getRemoteAddr()); $customer->newsletter_date_add = pSQL(date('Y-m-d H:i:s')); } if (!sizeof($this->errors)) { if (!$country = new Country($address->id_country, Configuration::get('PS_LANG_DEFAULT')) OR !Validate::isLoadedObject($country)) die(Tools::displayError()); if ((int)($country->contains_states) AND !(int)($address->id_state)) $this->errors[] = Tools::displayError('This country requires a state selection.'); else { $customer->active = 1; /* New Guest customer */ if (Tools::isSubmit('is_new_customer')) $customer->is_guest = !Tools::getValue('is_new_customer', 1); else $customer->is_guest = 0; if (!$customer->add()) $this->errors[] = Tools::displayError('An error occurred while creating your account.'); else { $address->id_customer = (int)($customer->id); if (!$address->add()) $this->errors[] = Tools::displayError('An error occurred while creating your address.'); else { if (!$customer->is_guest) { if (!Mail::Send((int)(self::$cookie->id_lang), 'account', Mail::l('Welcome!'), array('{firstname}' => $customer->firstname, '{lastname}' => $customer->lastname, '{email}' => $customer->email, '{passwd}' => Tools::getValue('passwd')), $customer->email, $customer->firstname.' '.$customer->lastname)) $this->errors[] = Tools::displayError('Cannot send email'); } self::$smarty->assign('confirmation', 1); self::$cookie->id_customer = (int)($customer->id); self::$cookie->customer_lastname = $customer->lastname; self::$cookie->customer_firstname = $customer->firstname; self::$cookie->passwd = $customer->passwd; self::$cookie->logged = 1; self::$cookie->email = $customer->email; self::$cookie->is_guest = !Tools::getValue('is_new_customer', 1); /* Update cart address */ self::$cart->secure_key = $customer->secure_key; self::$cart->id_address_delivery = Address::getFirstCustomerAddressId((int)($customer->id)); self::$cart->id_address_invoice = Address::getFirstCustomerAddressId((int)($customer->id)); self::$cart->update(); Module::hookExec('createAccount', array( '_POST' => $_POST, 'newCustomer' => $customer )); if (Tools::isSubmit('ajax')) { $return = array( 'hasError' => !empty($this->errors), 'errors' => $this->errors, 'isSaved' => true, 'id_customer' => (int)self::$cookie->id_customer, 'id_address_delivery' => self::$cart->id_address_delivery, 'id_address_invoice' => self::$cart->id_address_invoice, 'token' => Tools::getToken(false) ); die(Tools::jsonEncode($return)); } if ($back = Tools::getValue('back')) Tools::redirect($back); Tools::redirect('my-account.php'); } } } } } if (sizeof($this->errors)) { if (!Tools::getValue('is_new_customer')) unset($_POST['passwd']); if (Tools::isSubmit('ajax')) { $return = array( 'hasError' => !empty($this->errors), 'errors' => $this->errors, 'isSaved' => false, 'id_customer' => 0 ); die(Tools::jsonEncode($return)); } } } if (Tools::isSubmit('SubmitLogin')) { Module::hookExec('beforeAuthentication'); $passwd = trim(Tools::getValue('passwd')); $email = trim(Tools::getValue('email')); if (empty($email)) $this->errors[] = Tools::displayError('E-mail address required'); elseif (!Validate::isEmail($email)) $this->errors[] = Tools::displayError('Invalid e-mail address'); elseif (empty($passwd)) $this->errors[] = Tools::displayError('Password is required'); elseif (Tools::strlen($passwd) > 32) $this->errors[] = Tools::displayError('Password is too long'); elseif (!Validate::isPasswd($passwd)) $this->errors[] = Tools::displayError('Invalid password'); else { $customer = new Customer(); $authentication = $customer->getByEmail(trim($email), trim($passwd)); if (!$authentication OR !$customer->id) { /* Handle brute force attacks */ sleep(1); $this->errors[] = Tools::displayError('Authentication failed'); } else { self::$cookie->id_customer = (int)($customer->id); self::$cookie->customer_lastname = $customer->lastname; self::$cookie->customer_firstname = $customer->firstname; self::$cookie->logged = 1; self::$cookie->is_guest = $customer->isGuest(); self::$cookie->passwd = $customer->passwd; self::$cookie->email = $customer->email; if (Configuration::get('PS_CART_FOLLOWING') AND (empty(self::$cookie->id_cart) OR Cart::getNbProducts(self::$cookie->id_cart) == 0)) self::$cookie->id_cart = (int)(Cart::lastNoneOrderedCart((int)($customer->id))); /* Update cart address */ self::$cart->id_carrier = 0; self::$cart->id_address_delivery = Address::getFirstCustomerAddressId((int)($customer->id)); self::$cart->id_address_invoice = Address::getFirstCustomerAddressId((int)($customer->id)); // If a logged guest logs in as a customer, the cart secure key was already set and needs to be updated self::$cart->secure_key = $customer->secure_key; self::$cart->update(); Module::hookExec('authentication'); if (!Tools::isSubmit('ajax')) { if ($back = Tools::getValue('back')) Tools::redirect($back); Tools::redirect('my-account.php'); } } } if (Tools::isSubmit('ajax')) { $return = array( 'hasError' => !empty($this->errors), 'errors' => $this->errors, 'token' => Tools::getToken(false) ); die(Tools::jsonEncode($return)); } } if (isset($create_account)) { /* Select the most appropriate country */ if (isset($_POST['id_country']) AND is_numeric($_POST['id_country'])) $selectedCountry = (int)($_POST['id_country']); /* FIXME : language iso and country iso are not similar, * maybe an associative table with country an language can resolve it, * But for now it's a bug ! * @see : bug #6968 * @link:http://www.prestashop.com/bug_tracker/view/6968/ elseif (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { $array = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']); if (Validate::isLanguageIsoCode($array[0])) { $selectedCountry = Country::getByIso($array[0]); if (!$selectedCountry) $selectedCountry = (int)(Configuration::get('PS_COUNTRY_DEFAULT')); } }*/ if (!isset($selectedCountry)) $selectedCountry = (int)(Configuration::get('PS_COUNTRY_DEFAULT')); if (Configuration::get('PS_RESTRICT_DELIVERED_COUNTRIES')) $countries = Carrier::getDeliveredCountries((int)self::$cookie->id_lang, true, true); else $countries = Country::getCountries((int)self::$cookie->id_lang, true); self::$smarty->assign(array( 'countries' => $countries, 'sl_country' => (isset($selectedCountry) ? $selectedCountry : 0), 'vat_management' => Configuration::get('VATNUMBER_MANAGEMENT') )); /* Call a hook to display more information on form */ self::$smarty->assign(array( 'HOOK_CREATE_ACCOUNT_FORM' => Module::hookExec('createAccountForm'), 'HOOK_CREATE_ACCOUNT_TOP' => Module::hookExec('createAccountTop') )); } /* Generate years, months and days */ if (isset($_POST['years']) AND is_numeric($_POST['years'])) $selectedYears = (int)($_POST['years']); $years = Tools::dateYears(); if (isset($_POST['months']) AND is_numeric($_POST['months'])) $selectedMonths = (int)($_POST['months']); $months = Tools::dateMonths(); if (isset($_POST['days']) AND is_numeric($_POST['days'])) $selectedDays = (int)($_POST['days']); $days = Tools::dateDays(); self::$smarty->assign(array( 'years' => $years, 'sl_year' => (isset($selectedYears) ? $selectedYears : 0), 'months' => $months, 'sl_month' => (isset($selectedMonths) ? $selectedMonths : 0), 'days' => $days, 'sl_day' => (isset($selectedDays) ? $selectedDays : 0) )); self::$smarty->assign('newsletter', (int)Module::getInstanceByName('blocknewsletter')->active); } public function setMedia() { parent::setMedia(); Tools::addCSS(_THEME_CSS_DIR_.'authentication.css'); Tools::addJS(array(_THEME_JS_DIR_.'tools/statesManagement.js', _PS_JS_DIR_.'jquery/jquery-typewatch.pack.js')); } public function process() { parent::process(); $back = Tools::getValue('back'); $key = Tools::safeOutput(Tools::getValue('key')); if (!empty($key)) $back .= (strpos($back, '?') !== false ? '&' : '?').'key='.$key; if (!empty($back)) { self::$smarty->assign('back', Tools::safeOutput($back)); if (strpos($back, 'order.php') !== false) { if (Configuration::get('PS_RESTRICT_DELIVERED_COUNTRIES')) $countries = Carrier::getDeliveredCountries((int)self::$cookie->id_lang, true, true); else $countries = Country::getCountries((int)self::$cookie->id_lang, true); self::$smarty->assign(array( 'inOrderProcess' => true, 'PS_GUEST_CHECKOUT_ENABLED' => Configuration::get('PS_GUEST_CHECKOUT_ENABLED'), 'sl_country' => (int)Tools::getValue('id_country', Configuration::get('PS_COUNTRY_DEFAULT')), 'countries' => $countries )); } } } public function displayContent() { $this->processAddressFormat(); parent::displayContent(); self::$smarty->display(_PS_THEME_DIR_.'authentication.tpl'); } protected function processAddressFormat() { $addressItems = array(); $addressFormat = AddressFormat::getOrderedAddressFields(Configuration::get('PS_COUNTRY_DEFAULT'), false, true); $requireFormFieldsList = AddressFormat::$requireFormFieldsList; foreach ($addressFormat as $addressline) foreach (explode(' ', $addressline) as $addressItem) $addressItems[] = trim($addressItem); // Add missing require fields for a new user susbscription form foreach($requireFormFieldsList as $fieldName) if (!in_array($fieldName, $addressItems)) $addressItems[] = trim($fieldName); foreach (array('inv', 'dlv') as $addressType) self::$smarty->assign(array($addressType.'_adr_fields' => $addressFormat, $addressType.'_all_fields' => $addressItems)); } } Buen aporte, ponlo aquí: http://www.prestashop.com/forums/forum/168-modulos-gratis-sobrecargas-y-otras-astucias-que-cambian-la-vida/ (creando un tema nuevo), y asi queda todo mas organizado. Saludos Link to comment Share on other sites More sharing options...
fidelius-online Posted January 27, 2012 Share Posted January 27, 2012 Uhm.. acabo de sustituir los archivos AddressController.php y AuthController.php y parece que todo está OK. Aparece el campo del DNI aunque ahora no es obligatorio cumplimentarlo. El caso, es que todavía se muestra el asterisco rojo que indica que es obligatorio... ¿Donde se puede editar eso?....Estoy revisando en la carpeta del tema, el archivo authentication.tpl En principio, ahí puedo borrar el asterisco de todos los demás campos, pero no de ese del número de identificación ¿De donde se supone que sale?. ACTUALIZADO: No he dicho nada... efectivamente estaba ahÍ, en el authenticacion.tpl Link to comment Share on other sites More sharing options...
tafisa Posted February 10, 2012 Share Posted February 10, 2012 Vaya Vida PHP, que ha pasado con ese post??, se ha eliminado o el link es incorrecto? Link to comment Share on other sites More sharing options...
nadie Posted February 10, 2012 Share Posted February 10, 2012 Vaya Vida PHP, que ha pasado con ese post??, se ha eliminado o el link es incorrecto? ¿El que se ha borrado? Saludos Link to comment Share on other sites More sharing options...
tafisa Posted February 10, 2012 Share Posted February 10, 2012 Perdona, pensaba que enviaba a un post en concreto y no a una carpeta, Estás al loro, ehhhh !!!!! ;-) Link to comment Share on other sites More sharing options...
nadie Posted February 10, 2012 Share Posted February 10, 2012 Perdona, pensaba que enviaba a un post en concreto y no a una carpeta, Estás al loro, ehhhh !!!!! ;-) Al servicio de todos ! Un saludo Link to comment Share on other sites More sharing options...
bazaralandalus Posted February 19, 2012 Share Posted February 19, 2012 por favor, como veo si los trozos de codigo que se salen de la pantallan han sido modificados, porque estoy muy muy interesada muchas gracias, sois geniales! Link to comment Share on other sites More sharing options...
nadie Posted February 19, 2012 Share Posted February 19, 2012 por favor, como veo si los trozos de codigo que se salen de la pantallan han sido modificados, porque estoy muy muy interesada muchas gracias, sois geniales! En este mensaje: http://www.prestasho...post__p__728643 Te dice los ficheros a modificar, simplemente abre le ficheros en cuestión y cambias el contenido actual de dichos ficheros por el contenido que aparece en ese mensaje. Link to comment Share on other sites More sharing options...
bazaralandalus Posted February 19, 2012 Share Posted February 19, 2012 ya lo ví, pero el código se sale de la pantalla y no veo si cambia. Ahi forma de ver lo que se sale?? Madre mía que trabajazo tienes "nadie" estas es todos lados como Dios!!! Gracias!! Link to comment Share on other sites More sharing options...
nadie Posted February 19, 2012 Share Posted February 19, 2012 ya lo ví, pero el código se sale de la pantalla y no veo si cambia. Ahi forma de ver lo que se sale?? Madre mía que trabajazo tienes "nadie" estas es todos lados como Dios!!! Gracias!! En fin aqui tienes los dos ficheros que debes sustituir en la carpeta controllers. AddressController.php AuthController.php Link to comment Share on other sites More sharing options...
bazaralandalus Posted February 19, 2012 Share Posted February 19, 2012 Gracias!! genial super rápido, me alucina ver que gente que no conozco me dediquen más tiempo que mis amigos!! Sois marabillosos!!! Gracias Link to comment Share on other sites More sharing options...
nadie Posted February 19, 2012 Share Posted February 19, 2012 Gracias!! genial super rápido, me alucina ver que gente que no conozco me dediquen más tiempo que mis amigos!! Sois marabillosos!!! Gracias En este mundo lleno de tinieblas y oscuridad, siempre es bueno ayudar un poco. Un saludo, y recuerda que estaremos por el foro para guiarte por este mundo tenebroso. PD: Buen fin de semana. Link to comment Share on other sites More sharing options...
bazaralandalus Posted February 19, 2012 Share Posted February 19, 2012 Gracias, he modificado el formulario gracias a vosotros. Os lo agradezco infinito. Mil gracias Link to comment Share on other sites More sharing options...
lb20 Posted February 22, 2012 Share Posted February 22, 2012 ¿ esta solucion se puede aplicar a prestashop 1.4.7 ? Link to comment Share on other sites More sharing options...
nadie Posted February 22, 2012 Share Posted February 22, 2012 ¿ esta solucion se puede aplicar a prestashop 1.4.7 ? Si. Link to comment Share on other sites More sharing options...
lb20 Posted February 22, 2012 Share Posted February 22, 2012 Con esta solución hacemos no obligatorio dni y uno de los teléfonos, en mi caso solo quiero que ocurra con el dni, que es lo que se debería modificar entonces? Muchas gracias Link to comment Share on other sites More sharing options...
luiisz Posted February 28, 2012 Share Posted February 28, 2012 Buena solucion efectivamente funciona, pero no encuentro donde borrar el * donde puedo modificar eso? solo en DNI quitar el * Link to comment Share on other sites More sharing options...
nadie Posted February 28, 2012 Share Posted February 28, 2012 Buena solucion efectivamente funciona, pero no encuentro donde borrar el * donde puedo modificar eso? solo en DNI quitar el * En el authentication.tpl de tu plantilla. Un saludo, Link to comment Share on other sites More sharing options...
luiisz Posted February 28, 2012 Share Posted February 28, 2012 En el authentication.tpl de tu plantilla. Un saludo, PLOP! Graciaaaas! Link to comment Share on other sites More sharing options...
nadie Posted February 28, 2012 Share Posted February 28, 2012 PLOP! Graciaaaas! De nada Link to comment Share on other sites More sharing options...
luiisz Posted February 29, 2012 Share Posted February 29, 2012 (edited) De nada Vida PHP! MASTER! no me odies!!! necesito tu ayuda!! bueno esque encontre el authentication.tpl y dentro encuentro tambien el * en el area de DNI.. pero lo borro y sigue saliendo * sufro! si no es borrar el * en las aeras de DNI entonces que me ahce falta? agradezco mucho tu ayuda! nooo ya no! jaja ups puse el modo Forzar la compilación y asunto arreglado.. =D ok tu no has visto nada! jaja Edited February 29, 2012 by luiisz (see edit history) Link to comment Share on other sites More sharing options...
nadie Posted February 29, 2012 Share Posted February 29, 2012 Vida PHP! MASTER! no me odies!!! necesito tu ayuda!! bueno esque encontre el authentication.tpl y dentro encuentro tambien el * en el area de DNI.. pero lo borro y sigue saliendo * sufro! si no es borrar el * en las aeras de DNI entonces que me ahce falta? agradezco mucho tu ayuda! nooo ya no! jaja ups puse el modo Forzar la compilación y asunto arreglado.. =D ok tu no has visto nada! jaja Efectivamente debes poner forzar compilacion, en ese momento, por que sino, no se aplicaran los cambios. Un saludo, y recuerda que estaremos por el foro para guiarte por este mundo lleno de oscuridad y tinieblas. Link to comment Share on other sites More sharing options...
pexu Posted February 29, 2012 Share Posted February 29, 2012 Buenas!!! muchas gracias por este post, me ha venido de gran ayuda! Me queda quitar el asterísco! he modificado el authentication.tpl de esta forma: <fieldset class="account_creation dni"> <h3>{l s='Tax identification'}</h3> <p class="required text"> <label for="dni">{l s='Identification number'}</label> <input type="text" class="text" name="dni" id="dni" value="{if isset($smarty.post.dni)}{$smarty.post.dni}{/if}" /> <span class="form_info">{l s='DNI / NIF / NIE'}</span> </p> </fieldset> Cómo hago para subirlo? Muchas gracias y un saludo! Link to comment Share on other sites More sharing options...
mac_pica Posted March 1, 2012 Share Posted March 1, 2012 hola necesito saber como hacen todos esos cambios es decir como entrar en las carpetas y todo eso me lo pueden explicar paso por paso, por favor Link to comment Share on other sites More sharing options...
kris86 Posted March 11, 2012 Share Posted March 11, 2012 Hola! he seguido las indicaciones que dais en este post pero a mi me esta dando problemas. De primeras me funciona, al registrarse no sale el telefono, pero cuando relleno los datos y le doy a registrar sale esto: Hay 1 error : 01-An error occurred while creating your account. Y de hay ya no pasa :S ¿Alguna solución? Link to comment Share on other sites More sharing options...
Alberto69 Posted April 13, 2012 Share Posted April 13, 2012 Hola a todos, Yo utilizo la 1.4.7.0 y he visto que también hay que quitar el asterisco del fichero address.tpl situado al mismo nivel que authentication.tpl, ya que si se van a actualizar los datos de la cuenta, también sale el DNI. Un saludo. Link to comment Share on other sites More sharing options...
monxu Posted May 17, 2012 Share Posted May 17, 2012 Hay una solución mucho más fácil que editar los archivos. Desde admin: click en pestaña transporte > paises > seleccionar el pais> y abajo del todo ¿Necesita el número de identificación fiscal? -> NO Link to comment Share on other sites More sharing options...
nadie Posted May 17, 2012 Share Posted May 17, 2012 Hay una solución mucho más fácil que editar los archivos. Desde admin: click en pestaña transporte > paises > seleccionar el pais> y abajo del todo ¿Necesita el número de identificación fiscal? -> NO Ya pero hay desaparece el DNI directamente, el tema del foro se creo con la idea de dejarlo como opcional. (Esa era la idea del tema en un principio, lo que pasa es que luego se fue distorsionando el tema ) Link to comment Share on other sites More sharing options...
sak2 Posted July 13, 2012 Share Posted July 13, 2012 ¿Debería de funcionar modificando los controllers y ubicándolos en la carpeta 'override'? Lo he hecho y no me va, me da error de dni incorrecto. Gracias de antemano. Link to comment Share on other sites More sharing options...
el_gota Posted November 30, 2012 Share Posted November 30, 2012 Gracias, correcto!!! Link to comment Share on other sites More sharing options...
Recommended Posts