PrestaShop Forums: Return the surname from the DB as capitalize text - PrestaShop Forums

Jump to content


Welcome to the PrestaShop Forum! We hope you'll share your comments and suggestions with us. We ask that you please post in English to the main sections of the PrestaShop Forum. If you want to write in another language, please post in the corresponding PrestaShop Community section below.

Please note that PrestaShop Community sections are largely self-moderated. PrestaShop team members may or may not participate in non-English sections. To improve the chances of receiving feedback to your question or comment, please post it in English to the main sections of our Forum.

NYC

Vous parlez français ? par ici !


Return the surname from the DB as capitalize text


Return the surname from the DB as capitalize text

#1 Guest_Ash Bryant_*

  • --
  • Guests

Posted 08 October 2009 - 10:47 AM

Hi, does anyone know how I can return the users surname as capitalize text? or even lowercase, as then I can use css to change it?

At the moment it would look like this, John SMITH and I need it to look like John Smith.

Thanks Ash

#2 Guest__*

  • --
  • Guests

Posted 08 October 2009 - 03:07 PM

Where are you displaying the text? You can use the PHP function ucwords() to acheive this.

#3 Guest__*

  • --
  • Guests

Posted 08 October 2009 - 03:18 PM

There is some code "somewhere" on these forums that will make you enter the namse normal instead of the PS way.
I never understand why PS wants the last names in CAPITAL, but hee, you cant have it all.

#4 Guest__*

  • --
  • Guests

Posted 08 October 2009 - 03:20 PM

I need to display it in the user info areas in a "normal" way, not have it look like its being shouted at the user. It looks a lot better as Name Surname, than Name SURNAME!!!

How do you use that php function?
:)

#5 Guest__*

  • --
  • Guests

Posted 08 October 2009 - 03:57 PM

Found it:

To remove auto capital on lastname you have to edit this files:


admin/tabs/AdminAddresses.php
=> remove «style=“text-transform: uppercase;“» on:
<input type=“text” size=“33” name=“lastname” value=”’.htmlentities($this->getFieldValue($obj, ‘lastname’), ENT_COMPAT, ‘UTF-8’).’” style=“text-transform: uppercase;” > *

admin/tabs/AdminCustomers.php
=> remove «style=“text-transform: uppercase;“» on:
<input type=“text” size=“33” name=“lastname” value=”’.htmlentities($this->getFieldValue($obj, ‘lastname’), ENT_COMPAT, ‘UTF-8’).’” style=“text-transform: uppercase;” > *

admin/tabs/AdminEmployees.php
=> remove «style=“text-transform: uppercase;“» on:
<input type=“text” size=“33” name=“lastname” value=”’.htmlentities($this->getFieldValue($obj, ‘lastname’), ENT_COMPAT, ‘UTF-8’).’” style=“text-transform: uppercase;” > *

classes/Address.php
=> find this line and change to this: «$fields[‘lastname’] = pSQL($this->lastname);»

classes/Customer.php
=> find this line and change to this: «$fields[‘lastname’] = pSQL($this->lastname);»

classes/Employee.php
=> find this line and change to this: «$fields[‘lastname’] = pSQL($this->lastname);»



This will NOT change the names already in the database!

#6 Guest__*

  • --
  • Guests

Posted 09 October 2009 - 11:16 AM

From 1255013855:

Found it:

This will NOT change the names already in the database!


To change the data already in you will need to write an SQL update script or update it manually if there arent many entries.

An alternative method might be this (I havent tested this) - Open classes/Tools.php and round about line 726:


static function strtoupper($str)
{
if (function_exists('mb_strtoupper'))
return mb_strtoupper($str, 'utf-8');
return strtoupper($str);
}

Change to:

static function strtoupper($str)
{
return ucwords(strtolower($str));
}

This should now save surnames in the correct format.

#7 Guest__*

  • --
  • Guests

Posted 26 November 2009 - 06:09 PM

I think this should be a standard feature.... or at least an option in the Back Office to enable this.

#8 Guest__*

  • --
  • Guests

Posted 26 November 2009 - 07:31 PM

Here are the files I use for version 1.2.5.0. I have replaced strtoupper with ucfirst.

/Kjeld

Attached File(s)



#9 Guest__*

  • --
  • Guests

Posted 26 November 2009 - 07:34 PM

Great! I used ECK!'s idea and it seems to have worked like a charm.... all we need is for this to be a admin option in the next release!

#10 Guest__*

  • --
  • Guests

Posted 26 November 2009 - 07:39 PM

I don't think you should do it the way Eck! suggests. "Tools::strtoupper" is used for other things than lastname.

/Kjeld

#11 Guest__*

  • --
  • Guests

Posted 26 November 2009 - 07:40 PM

Ahhh ok! ... Ill backout and replace the files with yours! Thanks!...

just need to make a note when the next update comes out I update the new code.

#12 Guest__*

  • --
  • Guests

Posted 09 December 2009 - 12:58 PM

From 1259260749:

I don't think you should do it the way Eck! suggests. "Tools::strtoupper" is used for other things than lastname.

/Kjeld


Yes this is not best practice so can only be a quick temporary fix. A better solution would be to add my amended function as a different name into Tools.php eg: public static function lastname($str) and then perform a search (Dreamweaver CTRL-F) for "Tools::strtoupper", then change any calls that relate to "lastname" to "Tools::lastname" (theres only about 15 edits in the whole system)

#13 Guest__*

  • --
  • Guests

Posted 02 February 2010 - 04:57 AM

Any chance this actually will make it into the next release? This may be the only negative thing I've encountered in Prestashop yet. :) It's an amazing package.

#14 Guest__*

  • --
  • Guests

Posted 05 March 2010 - 04:38 PM

Correct code for UTF-8 (PrestaShop version 1.3 - file 'Tools.php')

    static function strtoupper($str)
{
if (is_array($str))
return false;
/* if (function_exists('mb_strtoupper'))
return mb_strtoupper($str, 'utf-8');
return strtoupper($str);
*/
if (function_exists('mb_convert_case'))
return mb_convert_case($str, MB_CASE_TITLE, "UTF-8");
return $str;
}


#15 Guest__*

  • --
  • Guests

Posted 19 March 2010 - 02:13 PM

How to change the name and address fields to display first letter in capital? I have lot of customers typing in their own name as firstname lastname, I don't mind that but when I print the invoice or label I'd like to have the address label correctly printed. Tried to change it in css but the data are written t the DB as the user has typed.

#16 Guest__*

  • --
  • Guests

Posted 22 May 2010 - 12:09 PM

From 1255013855:

Found it:

To remove auto capital on lastname you have to edit this files:


admin/tabs/AdminAddresses.php
=> remove «style=“text-transform: uppercase;“» on:
<input type=“text” size=“33” name=“lastname” value=”’.htmlentities($this->getFieldValue($obj, ‘lastname’), ENT_COMPAT, ‘UTF-8’).’” style=“text-transform: uppercase;” > *

admin/tabs/AdminCustomers.php
=> remove «style=“text-transform: uppercase;“» on:
<input type=“text” size=“33” name=“lastname” value=”’.htmlentities($this->getFieldValue($obj, ‘lastname’), ENT_COMPAT, ‘UTF-8’).’” style=“text-transform: uppercase;” > *

admin/tabs/AdminEmployees.php
=> remove «style=“text-transform: uppercase;“» on:
<input type=“text” size=“33” name=“lastname” value=”’.htmlentities($this->getFieldValue($obj, ‘lastname’), ENT_COMPAT, ‘UTF-8’).’” style=“text-transform: uppercase;” > *

classes/Address.php
=> find this line and change to this: «$fields[‘lastname’] = pSQL($this->lastname);»

classes/Customer.php
=> find this line and change to this: «$fields[‘lastname’] = pSQL($this->lastname);»

classes/Employee.php
=> find this line and change to this: «$fields[‘lastname’] = pSQL($this->lastname);»



This will NOT change the names already in the database!


Also one last occurance for the back office in admin/header.inc.php:

change:
<?php echo Tools::substr($cookie->firstname, 0, 1).'. '.htmlentities(Tools::strtoupper($cookie->lastname), ENT_COMPAT, 'UTF-8'); ?>

to:
<?php echo Tools::substr($cookie->firstname, 0, 1).'. '.htmlentities($cookie->lastname, ENT_COMPAT, 'UTF-8'); ?>






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users