VirtueMart Forum

VirtueMart 2 + 3 + 4 => Virtuemart Development and bug reports => Coding Central => Topic started by: Genius WebDesign on April 15, 2014, 14:07:53 PM

Title: How to store VM User First Name + VM User Last Name as Joomla Full Name?
Post by: Genius WebDesign on April 15, 2014, 14:07:53 PM
Hi,

Im using VM v.2.0.26d
It seems that when a customer creates a new profile via the Virtuemart registration form, or when a new customer creates an order, then the user“s email is stored as Joomla user "Full Name" field (not username).
Instead I would like it to store VM first name + last name as Joomla "Full Name".

How do I accomplish this?
Title: Re: How to store VM User First Name + VM User Last Name as Joomla Full Name?
Post by: Genius WebDesign on April 22, 2014, 11:50:46 AM
Has anyone had the same problem?

And does anyone know which file I should look into in order to change the VM registration to save the Joomla user info as explained?
Title: Re: How to store VM User First Name + VM User Last Name as Joomla Full Name?
Post by: Milbo on April 24, 2014, 10:42:56 AM
This is not done by vm. You can accomplish that with a js.
If input for displayed name is empty, fill it with vm firstname + lastname
Title: Re: How to store VM User First Name + VM User Last Name as Joomla Full Name?
Post by: Genius WebDesign on April 24, 2014, 10:57:21 AM
Hi Milbo,

Thanks for the answer.
I found this script on the registration form page:

<script type="text/javascript">
document.getElementById("email_field").setAttribute("onchange", "mail_is_user()");

    function mail_is_user(){
var reg_email = document.getElementById("email_field").value
document.getElementById("name_field").value = (reg_email);
document.getElementById("username_field").value = (reg_email);
}
</script>


So I guess I could just modify this script to instead save the "name_field" as First Name + Last Name
Title: Re: How to store VM User First Name + VM User Last Name as Joomla Full Name?
Post by: Genius WebDesign on April 24, 2014, 11:15:05 AM
Furthermore, I found out that the code was located in one of the template“s override folders, so this problem is specific for my template only.
Title: Re: How to store VM User First Name + VM User Last Name as Joomla Full Name?
Post by: Genius WebDesign on April 24, 2014, 11:32:54 AM
Just to wrap it up, I finally got it working by changing the javascript to this:

<script type="text/javascript">
document.getElementById("email_field").setAttribute("onchange", "mail_is_user()");
    function mail_is_user(){
var reg_email = document.getElementById("email_field").value;
document.getElementById("username_field").value = (reg_email);
}

document.getElementById("first_name_field").setAttribute("onchange", "joomla_name_is_vmname()");
document.getElementById("last_name_field").setAttribute("onchange", "joomla_name_is_vmname()");
    function joomla_name_is_vmname(){
var first_name = document.getElementById("first_name_field").value;
var last_name = document.getElementById("last_name_field").value;
document.getElementById("name_field").value = (first_name + ' ' + last_name);
}
</script>
Title: Re: How to store VM User First Name + VM User Last Name as Joomla Full Name?
Post by: Milbo on April 24, 2014, 12:16:31 PM
Nice snippet. We could add it to the core layout. We could also do it in the model, but that would need an extra option. The js solution is easy to remove and to adjust.
Title: Re: How to store VM User First Name + VM User Last Name as Joomla Full Name?
Post by: Genius WebDesign on April 24, 2014, 12:23:18 PM
Yes, indeed.
It should be fairly easy to make some kind of VM admin implementation of this snippet.
Maybe the shopowner could then have some options to choose exactly how he want the registration form to save the VM user data in the core Joomla user tables.
Title: Re: How to store VM User First Name + VM User Last Name as Joomla Full Name?
Post by: Milbo on April 25, 2014, 11:24:49 AM
The problem is actually that the loginname is part of the password. It is a bit similar to the public key. So actually there should be at least a random alphanumeric in it.