PrestaShop Forum

The best place in the world to ask questions about PrestaShop and get advice from our passionate community!

PrestaShop Forum

Jump to content

 

Return the surname from the DB as capitalize text

15 replies to this topic
#1
Ash Bryant

    PrestaShop Newbie

  • Members
  • Pip
  • 14 posts
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
Eck!

    PrestaShop Apprentice

  • Members
  • PipPip
  • 40 posts
Where are you displaying the text? You can use the PHP function ucwords() to acheive this.

#3
TropischBruin

    PrestaShop Fanatic

  • Moderators
  • 2198 posts
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.
Norman in 't VeldtModeratorPrestaShopForums
Help PrestaShop, make a donation!

#4
Ash Bryant

    PrestaShop Newbie

  • Members
  • Pip
  • 14 posts
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
TropischBruin

    PrestaShop Fanatic

  • Moderators
  • 2198 posts
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!
Norman in 't VeldtModeratorPrestaShopForums
Help PrestaShop, make a donation!

#6
Eck!

    PrestaShop Apprentice

  • Members
  • PipPip
  • 40 posts

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
Splash

    PrestaShop Apprentice

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

#8
presta-dyr

    PrestaShop Fanatic

  • Moderators
  • 1045 posts
Here are the files I use for version 1.2.5.0. I have replaced strtoupper with ucfirst.

/Kjeld

Attached Files



#9
Splash

    PrestaShop Apprentice

  • Members
  • PipPip
  • 44 posts
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
presta-dyr

    PrestaShop Fanatic

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

/Kjeld

#11
Splash

    PrestaShop Apprentice

  • Members
  • PipPip
  • 44 posts
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
Eck!

    PrestaShop Apprentice

  • Members
  • PipPip
  • 40 posts

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
SteveP

    PrestaShop Apprentice

  • Members
  • PipPip
  • 29 posts
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
Stano Novák

    PrestaShop Newbie

  • Members
  • Pip
  • 6 posts
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
outlet.ee

    PrestaShop Apprentice

  • Members
  • PipPip
  • 175 posts
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
JohnsonZA

    PrestaShop Newbie

  • Members
  • Pip
  • 15 posts

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'); ?>