Rhapsody Posted July 30, 2011 Share Posted July 30, 2011 I started using the override feature when I upgraded to 1.4.3 thinking this would preclude having to modify core code for upgrades made in the future. I have two files (AddressController.php and AuthController.php) that worked to override the 1.4.3 core. These files eliminated the normalization of the US address (it forced all caps). I can go back in and modify the core code in the controller directory to verify that it works, but I'd rather do the override. Below is the code in my override/controller/AddressController.php that works in 1.4.3 but not in 1.4.4 There are only six code lines with the changes, but I think the entire public function preProcess() needs to be inserted in the override. Can anyone tell me what is needed to make the override work in 1.4.4? <?php /* * Rhapsody created from 1.4.3 of AddressController.php * * Rhapsody commented out US customer: normalize the address (all caps) * * @author PrestaShop SA <[email protected]> * @copyright 2007-2011 PrestaShop SA * @version Release: $Revision: 6594 $ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) * International Registered Trademark & Property of PrestaShop SA */ class AddressController extends AddressControllerCore { public function 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 (!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()); /* Rhapsody comment out 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); } End Rhapsody comment out US customer: normalize the address */ $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 (!Tools::getValue('dni') OR !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)); } parent::preProcess(); } } Link to comment Share on other sites More sharing options...
bellini13 Posted July 31, 2011 Share Posted July 31, 2011 its possible that the v1.4.4 has modified the core files that you have overriden, specifically the preProcess function. You might try taking the v1.4.4 preprocess function, add your 6 lines to it and place it in the override and see if that fixes the problem. also when you say it does not work, what do you mean? do you get an error? you might try putting in a debug statement in your code to ensure your custom code is actually getting executed as you expect. Link to comment Share on other sites More sharing options...
Rhapsody Posted August 1, 2011 Author Share Posted August 1, 2011 By not working, I mean it appears that the override is not being executed. I took the 1.4.4 core and copied it to the AddressController.php file and changed: class AddressControllerCore extends FrontController to class AddressController extends AddressControllerCore along with these mods to comment out the code I want deleted: /* Rhapsody comment out 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); } End Rhapsody comment out US customer: normalize the address */ It still does not work. The override/classes code appears to work fine Link to comment Share on other sites More sharing options...
Rhapsody Posted August 1, 2011 Author Share Posted August 1, 2011 I found my problem. The following code at the beginning of the core file, needed to me moved near the end of the override file. parent::preProcess(); 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now