Post by rogery » Fri Oct 29, 2010 7:13 pm

Is there a way to make customer names always appear with the first letters of their name in uppercase and the rest in lowercase regardless of how they were entered?

Roger

New member

Posts

Joined
Wed May 26, 2010 5:55 pm

Post by mystifier » Fri Oct 29, 2010 7:37 pm

There are standard php string functions to capitalize the first letter of a string or the first letter of every word in a string so both of the following would have the desired effect (turning everything to lowercase first):

Code: Select all

$fullname = ucwords(strtolower($fullname)); 
$lastname = ucfirst(strtolower($lastname)); 
Ideally, it should be done at the point that data is inserted. I suggested this somewhere here ages ago but it fell on deaf ears.

I don't think that MySQL has such a string function, although it would be easy to write one; that aside, you could do it in SQL by, for example, replacing:

Code: Select all

lastname
in any query with:

Code: Select all

CONCAT(UCase(Left(`lastname`, 1)),LCase(Right(`lastname`,Length(`lastname`)-1)))
If you don't want to alter code, you could periodically run the clean-up query:

Code: Select all

UPDATE customer SET 
`firstname` = CONCAT(UCase(Left(`firstname`, 1)),LCase(Right(`firstname`,Length(`firstname`)-1))), 
`lastname` = CONCAT(UCase(Left(`lastname`, 1)),LCase(Right(`lastname`,Length(`lastname`)-1)));
which would convert "ROBIN HOOD", "guy fawkes", "RiChArD lIoNhEaRt" to "Robin Hood", "Guy Fawkes", "Richard Lionheart"
Last edited by mystifier on Fri Oct 29, 2010 7:43 pm, edited 1 time in total.

Free v1.4.9 Extensions: Default Specials | Improved Search | Customer Activity Report | Customer Groups | Royal Mail With Handling | Improved Product Page | Random Products | Stock Report | All Products


User avatar
Active Member

Posts

Joined
Tue May 18, 2010 5:15 pm

Post by billyggla » Fri Oct 29, 2010 7:41 pm

could you not just add style="text-transform: capitalize;" to the form field?

Active Member

Posts

Joined
Mon Sep 20, 2010 7:05 am

Post by mystifier » Fri Oct 29, 2010 7:54 pm

It would be possible to use css styling but that would require either in-line style or adding a class to individual elements.

I can't think of any situation where I would want to display 'eDwaRD lONGshaNKS' (which some customers seem to favour) so it might as well be corrected before it is databased.

I guess 'Simon de Montford' might raise small objection to being called 'Simon De Montford' but rather that than having all reports, emails, invoices, mailshots looking like they were produced by an eight year old.

Free v1.4.9 Extensions: Default Specials | Improved Search | Customer Activity Report | Customer Groups | Royal Mail With Handling | Improved Product Page | Random Products | Stock Report | All Products


User avatar
Active Member

Posts

Joined
Tue May 18, 2010 5:15 pm

Post by rogery » Fri Oct 29, 2010 8:30 pm

Thanks guys, spoiled for choice! I just tried the clean up query which works great so I will use this before any invoice run. It would be nice to apply the fix that makes them store properly on the customer registration form though.

I would really appreciate it if someone could show exactly how in which files because i am sure i would mess it up. :-[

Thanks,

Roger

New member

Posts

Joined
Wed May 26, 2010 5:55 pm

Post by billyggla » Sat Oct 30, 2010 7:18 am

This will change the first letter to uppercase before it goes to the database..
backup first...

in catalog/model/account/customer.php

add this

Code: Select all

$fname = ucwords(strtolower($data['firstname'])); 
$lname = ucwords(strtolower($data['lastname']));
 
directly below this

Code: Select all

public function addCustomer($data) {
 
then find every instance of this

Code: Select all

$this->db->escape($data['firstname'])
 
and replace with this

Code: Select all

$this->db->escape($fname)
 
then find every instance of this

Code: Select all

$this->db->escape($data['lasttname'])
 
and replace with this

Code: Select all

$this->db->escape($lname)
 
all done.. enjoy.

If you want the customer to see this as they type on the registration form

in catalog/view/theme/default/template/account/create.tpl

find this

Code: Select all

<input type="text" name="firstname" value="<?php echo $firstname; ?>" />
replace with this

Code: Select all

<input type="text" style="text-transform: capitalize;" name="firstname" value="<?php echo $firstname; ?>" />
then find this

Code: Select all

<input type="text" name="lastname" value="<?php echo $lastname; ?>" />
replace with this

Code: Select all

<input type="text" style="text-transform: capitalize;" name="lastname" value="<?php echo $lastname; ?>" />
hope that helps..

Active Member

Posts

Joined
Mon Sep 20, 2010 7:05 am

Post by Qphoria » Sat Oct 30, 2010 7:41 am

billyggla wrote:

Code: Select all

$fname = ucwords(strtolower($data['firstname'])); 
$lname = ucwords(strtolower($data['lastname']));
 
Save yourself a lot of work and additional variables by just changing the existing variable

Code: Select all

$data['firstname'] = ucwords(strtolower($data['firstname'])); 
$data['lastname'] = ucwords(strtolower($data['lastname'])); 
Then you don't have to change anything else

Image
Donate!|OpenCart Basics|GeoZones
Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by billyggla » Sat Oct 30, 2010 10:53 am

Spot on as usual Q..
I just get in to the habbit of changing variables, so that if I break it I know where I've been.. :crazy:

Active Member

Posts

Joined
Mon Sep 20, 2010 7:05 am

Post by mystifier » Sat Oct 30, 2010 3:52 pm

That's the code I was just going to paste which I suggested some time ago (v1.4.8 ).

I can't understand why such a simple change with such a benefitial effect wasn't included in the core to the point that I haven't bothered to make any similar suggestions.

Free v1.4.9 Extensions: Default Specials | Improved Search | Customer Activity Report | Customer Groups | Royal Mail With Handling | Improved Product Page | Random Products | Stock Report | All Products


User avatar
Active Member

Posts

Joined
Tue May 18, 2010 5:15 pm

Post by rogery » Mon Nov 01, 2010 8:40 pm

I didn't intend to stir up any politics but it has been a godsend getting rid of all of the ugly name formatting.

Where exactly do I need to add the code to stop new poorly formatted ones from getting added?

It would be great if this could be extended to include address fields.

Thanks as always,

Roger

New member

Posts

Joined
Wed May 26, 2010 5:55 pm

Post by mystifier » Mon Nov 01, 2010 10:57 pm

In catalog/model/account/customer.php

Change:

Code: Select all

public function addCustomer($data) {
to:

Code: Select all

public function addCustomer($data) {
    $data['firstname'] = ucwords(strtolower($data['firstname']));
    $data['lastname'] = ucwords(strtolower($data['lastname']));
    $data['company'] = ucwords(strtolower($data['company']));
    $data['address_1'] = ucwords(strtolower($data['address_1']));
    $data['address_2'] = ucwords(strtolower($data['address_2']));
    $data['city'] = ucwords(strtolower($data['city']));
    $data['postcode'] = strtoupper($data['postcode']);

Free v1.4.9 Extensions: Default Specials | Improved Search | Customer Activity Report | Customer Groups | Royal Mail With Handling | Improved Product Page | Random Products | Stock Report | All Products


User avatar
Active Member

Posts

Joined
Tue May 18, 2010 5:15 pm

Post by rogery » Tue Nov 02, 2010 3:47 am

Thanks mystifier.

Any chance of an extended clean up query to do addresses? Also, names are still showing unformatted in some places.

Roger

New member

Posts

Joined
Wed May 26, 2010 5:55 pm

Post by mystifier » Tue Nov 02, 2010 6:13 am

rogery wrote:names are still showing unformatted in some places.
Aside from the customer table, customer names are stored (de-normalised) in addresses. They are also stored in orders where they appear as name, shipping name and payment (invoice) name so to straighten out names everywhere would be:

Code: Select all

UPDATE customer SET 
`firstname` = CONCAT(UCase(Left(`firstname`, 1)),LCase(Right(`firstname`,Length(`firstname`)-1))), 
`lastname` = CONCAT(UCase(Left(`lastname`, 1)),LCase(Right(`lastname`,Length(`lastname`)-1)));
UPDATE `order` SET 
`firstname` = CONCAT(UCase(Left(`firstname`, 1)),LCase(Right(`firstname`,Length(`firstname`)-1))), 
`lastname` = CONCAT(UCase(Left(`lastname`, 1)),LCase(Right(`lastname`,Length(`lastname`)-1))),
`shipping_firstname` = CONCAT(UCase(Left(`shipping_firstname`, 1)),LCase(Right(`shipping_firstname`,Length(`shipping_firstname`)-1))), 
`shipping_lastname` = CONCAT(UCase(Left(`shipping_lastname`, 1)),LCase(Right(`shipping_lastname`,Length(`shipping_lastname`)-1))),
`payment_firstname` = CONCAT(UCase(Left(`payment_firstname`, 1)),LCase(Right(`payment_firstname`,Length(`payment_firstname`)-1))), 
`payment_lastname` = CONCAT(UCase(Left(`payment_lastname`, 1)),LCase(Right(`payment_lastname`,Length(`payment_lastname`)-1)));
UPDATE address SET
`firstname` = CONCAT(UCase(Left(`firstname`, 1)),LCase(Right(`firstname`,Length(`firstname`)-1))), 
`lastname` = CONCAT(UCase(Left(`lastname`, 1)),LCase(Right(`lastname`,Length(`lastname`)-1)));
You could apply a similar strategy to addresses with 'company', 'address_1', 'address_2', 'city', 'postcode' etc., with similar clean-up. But these too appear as shipping address and payment address in orders.

There is nothing difficult, it is just more of the same but, on the basis that my own requests for help rarely get response, I don't really feel very inclined to spend much of my free time on it. ;)

Free v1.4.9 Extensions: Default Specials | Improved Search | Customer Activity Report | Customer Groups | Royal Mail With Handling | Improved Product Page | Random Products | Stock Report | All Products


User avatar
Active Member

Posts

Joined
Tue May 18, 2010 5:15 pm

Post by billyggla » Tue Nov 02, 2010 6:23 am

mystifier wrote:on the basis that my own requests for help rarely get response, I don't really feel very inclined to spend much of my free time on it. ;)
A bit petty..
2 wrongs dont make a right....

Active Member

Posts

Joined
Mon Sep 20, 2010 7:05 am

Post by mystifier » Tue Nov 02, 2010 7:05 am

Not really petty billyggla; if you look through my posts, I have spent many hours on support and added numerous free extensions. It is a case of putting in what you get out.

Free v1.4.9 Extensions: Default Specials | Improved Search | Customer Activity Report | Customer Groups | Royal Mail With Handling | Improved Product Page | Random Products | Stock Report | All Products


User avatar
Active Member

Posts

Joined
Tue May 18, 2010 5:15 pm

Post by billyggla » Tue Nov 02, 2010 7:28 am

I agree its frustrating when you dont get an answer mystifier. It could just be that no one had an answer.

What I meant by petty was that Roger, who has been thankfull and appreciated your help, got the brunt of your frustration. Understandable, but misplaced..

By the way.. I like your extensions. ;)

Active Member

Posts

Joined
Mon Sep 20, 2010 7:05 am

Post by Qphoria » Tue Nov 02, 2010 9:18 am

mystifier wrote:Not really petty billyggla; if you look through my posts, I have spent many hours on support and added numerous free extensions. It is a case of putting in what you get out.
It's a case of tough love teaching :) Look how much better you are at it after being forced to learn it on your own :)

Image
Donate!|OpenCart Basics|GeoZones
Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by i2Paq » Tue Nov 02, 2010 3:00 pm

mystifier wrote:There is nothing difficult, it is just more of the same but, on the basis that my own requests for help rarely get response, I don't really feel very inclined to spend much of my free time on it. ;)
I for one appreciate your help and friendly comments!

I know how frustrated it can be to be on the helping end and get nothing but bad comments from people who themselves only drain the forum and their users but rarely give something back.

But isn't that like the real world? ;)

Norman in 't Veldt
Moderator OpenCart Forums

_________________ READ and Search BEFORE POSTING _________________

Our FREE search: Find your answer FAST!.

[How to] BTW + Verzend + betaal setup.


User avatar
Global Moderator

Posts

Joined
Mon Nov 09, 2009 7:00 pm
Location - Winkel - The Netherlands

Post by rogery » Tue Nov 02, 2010 4:28 pm

No offense from me. I use some of mystifiers extensions and he has been terrific help on numerous occasions both on the forum and in taking the trouble to answer PMs when I have been stuck.

I must admit, I do sometimes ask questions out of laziness that I could probably solve myself with some effort. That's probably because the support here is too good. ;D

New member

Posts

Joined
Wed May 26, 2010 5:55 pm

Post by Qphoria » Tue Nov 02, 2010 7:41 pm

rogery wrote:probably because the support here is too good. ;D
We'll work on that ;) 8)

Image
Donate!|OpenCart Basics|GeoZones
Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am
Who is online

Users browsing this forum: No registered users and 49 guests