WebsiteBaker Support (2.8.x) > Bakery Shop

Read Customer Email from ws_users

(1/1)

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!!!

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:


--- 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'];
}

--- End code ---

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!!!

DarkViper:

--- Quote from: ChochkoBG on June 01, 2014, 02:09:40 AM ---
--- 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'];
}

--- End code ---

--- End quote ---

maybe that's a bit more easier. ;)

--- Code: ---<?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();
}

--- End code ---
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)

ChochkoBG:
Yes, your method is better.

Thanks!!!

Navigation

[0] Message Index

Go to full version