Read Customer Email from ws_users

ChochkoBG

Yes, your method is better.

Thanks!!!

DarkViper

Quote from: ChochkoBG on June 01, 2014, 02:09:40 AM

// Insert Customer E-Mail Address in the Order Form
// Author: ChochkoBG
// Version: 1.0
// Get existing values from database
$sql = "SELECT email FROM ".TABLE_PREFIX."users WHERE user_id = '".$wb->get_user_id()."'";
$rowset = $database->query($sql);
if($database->is_error()) $error[] = $database->get_error();
$row = $rowset->fetchRow();
// insert values into form
$tpl->set_var('$cust_email', $row['email']);

if (!isset($cust_email) || $cust_email == '') {
$cust_email = $row['email'];
}
        if (!isset($cust_confirm_email) || $cust_confirm_email == '') {
$cust_confirm_email = $row['email'];
}

maybe that's a bit more easier. ;)
<?php
// insert values into form
$tpl->set_var('$cust_email'$wb->get_email());
if (!isset($cust_email) || $cust_email == '') {
$cust_email $wb->get_email();
}
        if (!isset(
$cust_confirm_email) || $cust_confirm_email == '') {
$cust_confirm_email $wb->get_email();
}

Note: you took the UID by get_user_id() from the object $wb.  If that UID exists, then also the users email exists in the object $wb and you can use the methods of $wb.
You can find user related methods in class.wb from line 235 to 283 (WB-2.8.3)

[url=http://www.youtube.com/watch?v=tmzDAz6ZvFQ]Der blaue Planet[/url] - er ist nicht unser Eigentum - wir haben ihn nur von unseren Nachkommen geliehen[br]
[i]"You have to take the men as they are... but you can not leave them like that !" :-P [/i]
[i]Das tägliche Stoßgebet: [b]Oh Herr, wirf Hirn vom Himmel ![/b][/i]

ChochkoBG

OK, I fixed it.

If anyone want to do the same, you have to add the following code into /$WSB/modules/bakery/view_form.php
on line 95

Here is the Code:


// Insert Customer E-Mail Address in the Order Form
// Author: ChochkoBG
// Version: 1.0
// Get existing values from database
$sql = "SELECT email FROM ".TABLE_PREFIX."users WHERE user_id = '".$wb->get_user_id()."'";
$rowset = $database->query($sql);
if($database->is_error()) $error[] = $database->get_error();
$row = $rowset->fetchRow();
// insert values into form
$tpl->set_var('$cust_email', $row['email']);

if (!isset($cust_email) || $cust_email == '') {
$cust_email = $row['email'];
}
        if (!isset($cust_confirm_email) || $cust_confirm_email == '') {
$cust_confirm_email = $row['email'];
}


This code will read the information from the User Account (The E-mail Address) and If the User is Logged In with his account, it will insert the E-Mail Address and Confirm E-Mail Address in the Customer Order Form.

Thanks!!!

ChochkoBG

Hello guys,

Is there a way, when a customer select product and continue with filling the form details to check if the User is Logged In, and if the User is Logged In to insert the E-mail Address and Confirm E-mail Address text in the fields and also if the User is not Logged In - the field to be empty ?

I think this script have to use ws_users from the database.

Thanks!!!