diff options
author | Christopher Burger <burgerc@freeside.biz> | 2017-07-24 16:45:50 -0400 |
---|---|---|
committer | Christopher Burger <burgerc@freeside.biz> | 2017-07-24 16:45:50 -0400 |
commit | 2371880187dcd6a8dbc55be0ddc70a7436ffbf5f (patch) | |
tree | 4ab91d2b025d9a548b5477c61edbf84ff8fbc7ab /rt | |
parent | 994b2be1b9b039d309a9527ac598a16cbb7e80e9 (diff) |
RT# 38517 - Added Lingua::EN::NameParse to parse real name into first and last name.
Diffstat (limited to 'rt')
-rw-r--r-- | rt/lib/RT/Interface/Web_Vendor.pm | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/rt/lib/RT/Interface/Web_Vendor.pm b/rt/lib/RT/Interface/Web_Vendor.pm index da0b1892e..909127b22 100644 --- a/rt/lib/RT/Interface/Web_Vendor.pm +++ b/rt/lib/RT/Interface/Web_Vendor.pm @@ -170,16 +170,25 @@ sub ProcessTicketCustomers { 'table' => 'contact_email', 'hashref' => { 'emailaddress' => $Requestor->{'values'}->{'emailaddress'}, }, } ) ) { - use FS::contact; - my $lname = $Requestor->{'values'}->{'realname'} ? - (split (/ /, $Requestor->{'values'}->{'realname'}))[-1] : - 'Requestor'; + ## get first and last name for contact. + my ($fname, $lname) = ( + split (/\@/, substr($Requestor->{'values'}->{'emailaddress'}, 0, index($Requestor->{'values'}->{'emailaddress'}, "."))) + ); + + use Lingua::EN::NameParse; + my $name = Lingua::EN::NameParse->new(); + + my $error = $name->parse($Requestor->{'values'}->{'realname'}) + unless !$Requestor->{'values'}->{'realname'}; - my $fname = $Requestor->{'values'}->{'realname'} ? - (split (/ /, $Requestor->{'values'}->{'realname'}))[0] : - 'RT'; + my %name_comps = $name->components unless !$Requestor->{'values'}->{'realname'} || $error; + $fname = $name_comps{given_name_1} || $name_comps{initials_1} unless !$name_comps{given_name_1} && !$name_comps{initials_1}; + $lname = $name_comps{surname_1} unless !$name_comps{surname_1}; + + ## create the contact. + use FS::contact; my $contact = new FS::contact { 'custnum' => $custnum, 'first' => $fname, |